列转行
1 查询测试表数据
- cqdb=> select * from test ;
- name
- ------
- AA
- BB
- CC
- (3 rows)
- cqdb=> select string_agg(name,',') from test;
- string_agg
- ------------
- AA,BB,CC
- (1 row)
行转列
1 查询测试表数据
- cqdb=> select * from test ;
- name
- -----------
- A,B,C,D,E
- (1 row)
2 行转列(regexp_split_to_table)
- cqdb=> select regexp_split_to_table(name,',') from test;
- regexp_split_to_table
- -----------------------
- A
- B
- C
- D
- E
- (5 rows)