What's the equivalent for LISTAGG in postgres?

天大地大妈咪最大 提交于 2019-12-23 06:53:09

问题


I have to replace the Oracle driver with the newest postgres.

Postgres doesn't know the function LISTAGG. I have to concat values by comma separated.

What's the equivalent for the Oracle function LISTAGG in Postgres?

Thanks.


回答1:


The equivalent function in Postgres is string_agg()

select string_agg(col,',') from my_table

string_agg : input values concatenated into a string, separated by delimiter




回答2:


From Postgres 9.0 or later, I believe you could do something like this:

SELECT c_id, STRING_AGG(c_grp_id, ',' ORDER BY c_grp_id) AS group_ids 
FROM c_grp_at 
GROUP BY c_id


来源:https://stackoverflow.com/questions/29557563/whats-the-equivalent-for-listagg-in-postgres

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!