如何在Kettle Pentaho中向具有枚举数据类型的Postgres表插入数据?

5

我正在尝试将数据从mysql转移到postgres表格。因此,我使用“Table input”步骤从mysql表中获取数据,并使用“insert/update”步骤将数据插入到postgres表中。

postgres表中有一个枚举数据类型。因此,当我尝试将数据插入到该字段时,会抛出以下错误:

2016/01/18 12:36:56 - Insert / Update.0 - ERROR: column "subject_classification" is of type subject_classification_type but expression is of type character varying
2016/01/18 12:36:56 - Insert / Update.0 -   Hint: You will need to rewrite or cast the expression.
2016/01/18 12:36:56 - Insert / Update.0 -   Position: 166

我知道这是一个类型转换问题,但我不知道该如何将其转换为枚举数据类型。

这是表格的表结构:

    CREATE TABLE subject (
    subject_id bigint NOT NULL,
    created_at timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    updated_at timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    code character varying(2000) NOT NULL,
    display_code character varying(2000) NOT NULL,
    subject_classification subject_classification_type NOT NULL,
    );


    CREATE TYPE subject_classification_type AS ENUM (
    'Math',
    'Social Science',
    'Language Arts'
);

请有人帮助我解决这个问题。谢谢!

1个回答

3

例子

create type suser as enum ('admin', 'user' , 'staff');
drop table if exists user_login;
create table user_login(
    id serial primary key, 
  who_logged suser, 
    when_logged timestamp default CURRENT_TIMESTAMP
);

示例解决方案

enter image description here

请注意,此解决方案不使用PreparedStatement的优势,因此速度较慢。如果有百万条记录需要插入,则可能不是一个好的解决方案,必须进行测量。

但它实际上是生成插入、更新语句的简化版本,并使用相同的步骤“执行SQL语句”来执行它。


您可以将数据下载到数据库中,然后运行一个函数来处理所有的数据。 - simar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接