I can't see why the query below should need any group by? I can't get this to work whereas other uses of string_agg elsewhere work
Any suggestions appreciated
select dv.DocumentVersionID, dv.DocumentID, dv.AuthorUserID1, dv.AuthorUserID2, dv.AuthorUserID3,
(select string_agg(
((COALESCE ((', ' || author1.FirstName || ' ' || author1.LastName), ' ')) ||
(COALESCE ((', ' || author2.FirstName || ' ' || author2.LastName), ' ')) ||
(COALESCE ((', ' || author3.FirstName || ' ' || author3.LastName), ' '))) , ' ' )) as Authors
FROM DocumentVersion AS dv INNER JOIN
"User" AS author1 ON author1.UserID = dv.AuthorUserID1 LEFT OUTER JOIN
"User" AS author2 ON author2.UserID = dv.AuthorUserID2 LEFT OUTER JOIN
"User" AS author3 ON author3.UserID = dv.AuthorUserID3 ;
results in:-
ERROR: column "dv.documentversionid" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: select dv.DocumentVersionID, dv.DocumentID, dv.AuthorUserID1...