如何将存储在'text'字段中的csv数据检索到postgresql中的另一个表中?

时间:2017-08-09 10:16:52

标签: java postgresql postgresql-9.4

例如

enter image description here

请建议解决方案

1 个答案:

答案 0 :(得分:1)

你可以使用string_to_array通过回车分割行,然后用| char分隔,例如:

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)