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

 

 

 

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