I have a table in postgresql. The following table \"animals\" will do to explain my problem:
name
------
tiger
cat
dog
Now I am using the follo
Still, for version 8.4, using the solution suggested by Matthew Wood, if you need to do a grouping in the outer query, the inner query should be sorted, too, for the sorting to be consistent.
SELECT family, array_agg(animal_name)
FROM (
SELECT family, "name" AS animal_name
FROM animals
ORDER BY family, "name"
) AS sorted_animals
group by family;