PG官方文档:http://www.postgres.cn/docs/10/
1.行列转换函数
行转列:string_agg
select id,string_agg(name,',') from user group by id;
1 张三
1 李四
1 张三,李四
列转行:regexp_split_to_table
select id,regexp_split_to_table(name,',') from user;
1 张三,李四
1 张三
1 李四
regexp_split_to_table(replace(replace(replace(a.phones,'[',''),']',''),'},{','}_{'),'_')::jsonb->>'value' phone
2.JSON解析函数
用纯函数解决:
--数组内套json
SELECT json_extract_path(json_array_elements(cast(data as json)),'body') t FROM table;
--纯json
select json_extract_path(cast(data as json),'approveType') t from table;
3.替换函数