将以逗号分隔的列数据拆分为具有50个以上字段的其他列

时间:2018-10-12 11:00:21

标签: sql postgresql split delimiter

所以我试图将逗号分隔的列数据拆分为其他列。

select max(array_length(regexp_split_to_array(tags, ','), 1)) from employee 

    The value is 61. 

如何更改不需要键入a [xx] 61次的以下内容?

select a[1], a[2], a[3], a[4], a[5], a[6]
from (
    select regexp_split_to_array(tags, ',')
    from employee
) as dt(a)

1 个答案:

答案 0 :(得分:0)

@ gordon-linoff指出,您可以使用SAXParser

代码示例:

regexp_split_to_table

结果:

create table employee (tags varchar(50));

insert into employee values ('one,two,three'),('cow,chicken,rooster');`

select * 
from (
    select regexp_split_to_table(tags, ',')
    from employee
) as t