> The query would become
> SELECT a.id, a.name, array_acc(b.name) as b_names
> FROM a LEFT JOIN b USING(id)
> GROUP BY a.id, a.name;
>
All variants are possible. Variant with array_to_string is faster and
doesn't need own aggregate function. And you can easy remove
duplicities.
SELECT a.id, a.name,
ARRAY_TO_STRING(ARRAY(
SELECT DISTINCT b.name
FROM b
WHERE b.id = a.id
ORDER BY b.name ASC
), ',') AS b_names
FROM a
ORDER BY a.id ASC;
regards
Pavel