如何将存储在 'text' 字段中的 csv 数据检索到 postgresql 中的另一个 table 中?
How to retrieve csv data stored in a 'text' field into another table in postgresql?
例如
请提出解决方案
可以用string_to_array
按回车符return分行,再按|
字符分行,eg:
t=# with a("Data") as (values('a|b|c'||chr(10)||'d|e|f'))
, mid as (select unnest(string_to_array("Data",chr(10))) u from a)
select split_part(u,'|',1) x, split_part(u,'|',2) y, split_part(u,'|',3) z from mid;
x | y | z
---+---+---
a | b | c
d | e | f
(2 rows)
例如
请提出解决方案
可以用string_to_array
按回车符return分行,再按|
字符分行,eg:
t=# with a("Data") as (values('a|b|c'||chr(10)||'d|e|f'))
, mid as (select unnest(string_to_array("Data",chr(10))) u from a)
select split_part(u,'|',1) x, split_part(u,'|',2) y, split_part(u,'|',3) z from mid;
x | y | z
---+---+---
a | b | c
d | e | f
(2 rows)