I have this table and all I want to do is a simple concatenation of the name grouping by the id.
id manager
1 tim
1 anna
2 clara
My desired table:
id manager
1 tim, anna
2 clara
I have tried with GROUP_CONCAT()
and LISTAGG ()
but I received the following error for both methods
ERROR: function group_concat(character varying, unknown) does not exist
I also tried with this but it does not work either because it said manager has to appear in the aggregate function.
SELECT id, CONCAT( manager, ', ') AS manager
FROM table
GROUP BY 1
I'm using DBeaver 7.3.5. Any lead on which function I can use here would be really appreciate I researched but did not find anything I can use.
Your error message suggests that you are using Postgres or a Postgres-derived database. That suggests STRING_AGG()
:
SELECT id, STRING_AGG( manager, ', ') AS manager
FROM table
GROUP BY 1