I\'\'ll explain what I need to do on example. First of all, we have a simple table like this one, named table:
id | name ===+===== 1 | foo 1 | bar
For Postgres use string_agg()
select id, string_agg(name, ',' order by name) as name_list from the_table group by id order by id;