Use string_agg
.
SELECT string_agg("name", ' | ') FROM thetable;
For older PostgreSQL, you must use array_agg
and array_to_string
:
SELECT array_to_string( array_agg("name"), ' | ') FROM thetable;
If you want a particular order, put it in the aggregate, e.g for alphabetical:
SELECT string_agg("name", ' | ' ORDER BY "name") FROM thetable;