Postgres returns [null] instead of [] for array_agg of join table
Another option might be array_remove(…, NULL) (introduced in 9.3) if tags.tag is NOT NULL (otherwise you might want to keep NULL values in the array, but in that case, you can’t distinguish between a single existing NULL tag and a NULL tag due to the LEFT JOIN): SELECT objects.*, array_remove(array_agg(tags.tag), NULL) AS tags, FROM objects … Read more