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.替換函數