PostGresql 函数

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.替换函数

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章