将属性从 table 迁移到另一个 table
Migrate attributes from a table to another table
我有两个 tables :
TEST1 :
attribut1, attribut2, attribut3
TEST2 :
attribut4
attribut4 模式类似于 "xxxxx yyyyy zzzzz"
我的问题是,是否可以在 TEST1 属性 1 中放入所有 "xxxxx",在属性 2 中放入所有 "yyyyy" 并在属性 3 "zzzzz" 中放入 table 测试 2?
我试过类似的东西:
insert into TEST1(attribut1) SELECT SUBSTRING(attribut4,1,5)::integer FROM TEST2;
但它说:
ERROR: null value in column "attribut2" violates not-null constraint
DETAIL: Failing row contains (xxxxx, null, null).
(attribut1,attribut2) 是主键。
感谢您的回答和抽出时间。
您可以使用 split_part()
:
insert into TEST1 (attribut1, attribut2, attribut3)
SELECT split_part(attribut4, ' ', 1)::int,
split_part(attribut4, ' ', 2)::int,
split_part(attribut4, ' ', 3)::int
FROM TEST2;
我有两个 tables :
TEST1 :
attribut1, attribut2, attribut3
TEST2 :
attribut4
attribut4 模式类似于 "xxxxx yyyyy zzzzz"
我的问题是,是否可以在 TEST1 属性 1 中放入所有 "xxxxx",在属性 2 中放入所有 "yyyyy" 并在属性 3 "zzzzz" 中放入 table 测试 2?
我试过类似的东西:
insert into TEST1(attribut1) SELECT SUBSTRING(attribut4,1,5)::integer FROM TEST2;
但它说:
ERROR: null value in column "attribut2" violates not-null constraint DETAIL: Failing row contains (xxxxx, null, null).
(attribut1,attribut2) 是主键。
感谢您的回答和抽出时间。
您可以使用 split_part()
:
insert into TEST1 (attribut1, attribut2, attribut3)
SELECT split_part(attribut4, ' ', 1)::int,
split_part(attribut4, ' ', 2)::int,
split_part(attribut4, ' ', 3)::int
FROM TEST2;