如何在PostgreSQL中将单行值转换为另一个表行

时间:2019-10-25 14:47:18

标签: sql postgresql

需要将Table1 Col1值插入到Table2 Col1中:

输入:

Table1
Col1
1,2,3,4

输出:

Table2
Col1
1
2
3
4

1 个答案:

答案 0 :(得分:1)

使用regexp_split_to_table()

select val
from table1 t1 cross join lateral
     regexp_split_to_table(t1.col1, ',') val;