postgresql string_agg(expression, delimiter)


Example

You can concatenate strings separated by delimiter using the string_agg() function.

If your individuals table is:

NameAgeCountry
Allie15USA
Amanda14USA
Alana20Russia

You could write SELECT ... GROUP BY statement to get names from each country:

SELECT string_agg(name, ', ') AS names, country 
FROM individuals 
GROUP BY country;

Note that you need to use a GROUP BY clause because string_agg() is an aggregate function.

Result:

namescountry
Allie, AmandaUSA
AlanaRussia

More PostgreSQL aggregate function described here