Since PostgreSQL 9.0 (released September 2010), there is the aggregate function
string_agg()
to do what you seem to want:
SELECT string_agg(field1, ';') FROM tbl GROUP BY id;
Note, that the second parameter is the separator (similar to other aggregate functions) .
There is also the string function concat_ws()
since PostgreSQL 9.1, that's otherwise doing the same as MySQL's concat_ws()
(when not abused as aggregate function). It's particularly useful to deal with NULL
values.
SELECT concat_ws(';', field1, field2, field3) FROM tbl
You could even combine both to aggreagate multiple columns any way you want.
SELECT id, string_agg(concat_ws(',', field1, field2, field3), ';') AS fields
FROM tbl
GROUP BY id;