问题
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