greenplum多行变成一行

[复制链接]
查看11 | 回复2 | 2011-11-1 16:27:27 | 显示全部楼层 |阅读模式
在greenplum一个表中的字段要根据分隔符(;)来分出多行,如:字段是 "fdfd;fdfd;fdfe;",拆分成:"fdfd

fdfd

fdfe",一行就转换成三行了。









回复

使用道具 举报

千问 | 2011-11-1 16:27:27 | 显示全部楼层
找到了regexp_split_to_table
回复

使用道具 举报

千问 | 2011-11-1 16:27:27 | 显示全部楼层
--创建测试表,插入测试数据
create table test_split(id int,name varchar);
insert into test_split select 1,'a;b;c;d';
insert into test_split select 2,'e;f;h;g';
select * from test_split;
id |name
----+---------
1 | a;b;c;d
2 | e;f;h;g
--查询
select id,unnest(string_to_array(name,';')) as name from test_split;
--结果
id | name
----+------
1 | a
1 | b
1 | c
1 | d
2 | e
2 | f
2 | h
2 | g
(8 rows)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行