Skip to content
Advertisement

Output array type column

I have a table like so –

id_sale name
20029   Robert
10029   Christine
10029   Deborah

How do I output this result –

id_sale name
20029   Robert
10029   Christine, Deborah

Advertisement

Answer

For an array, you would use array_agg():

select id_sale, array_agg(name)
from t
group by id_sale;

If you want the value as a comma-sseparated string:

string_agg(name, ', ')
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement