Sort a text aggregate created with array_agg in postgresql

前端 未结 6 2094
傲寒
傲寒 2021-02-05 04:42

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

6条回答
  •  被撕碎了的回忆
    2021-02-05 05:08

    This will be available in PostgreSQL 9.0:

    http://www.postgresql.org/docs/9.0/static/release-9-0.html, Section E.1.3.6.1. Aggregates

    In the meantime, you could do something like this which may solve the problem (albeit clunky):

    SELECT array_agg(animal_name)
    FROM (
        SELECT "name" AS animal_name
        FROM animals
        ORDER BY "name"
    ) AS sorted_animals;
    

提交回复
热议问题