gpt4 book ai didi

mysql - 如何在 kettle pentaho 中将数据插入到具有枚举数据类型的 postgres 表中?

转载 作者:可可西里 更新时间:2023-11-01 08:26:32 25 4
gpt4 key购买 nike

我正在尝试将数据从 mysql 移动到 postgres 表。所以我使用表输入步骤从 mysql 表中获取数据,并使用插入/更新步骤将数据插入到 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'
);

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

最佳答案

例子

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 语句”来执行它的版本。

关于mysql - 如何在 kettle pentaho 中将数据插入到具有枚举数据类型的 postgres 表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34849620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com