我有一个像这个问题的表:How to split row into many rows in postgresql
我希望在拆分行后插入新行。我怎么能在postgresql中做到这一点?我可以使用
选择它们SELECT "ID",
regexp_split_to_table("Cars", '(([,;] (?!damaged))|[,;]? and )') "Cars"
FROM mytable;
但我不知道修改表格。
答案 0 :(得分:0)
\2|\1
检查begin;
create temporary table mytable_temp after commit drop as
-- Here is SQL you povided so no any questions about it to me :)
SELECT "ID",
regexp_split_to_table("Cars", '(([,;] (?!damaged))|[,;]? and )') "Cars"
FROM mytable;
-- Here we will deal with fake table instead of your original table
-- to prevent data lost
create mytable_new as
select * from mytable_temp;
commit;
包含正确的数据,然后
mytable_new