Re: [GENERAL] Issue with json_agg() and ordering - Mailing list pgsql-general

From Bob Jones
Subject Re: [GENERAL] Issue with json_agg() and ordering
Date
Msg-id CA+HuS5FZoqYvBLG7eX2W65fX5fJD8q9eerWzz0N_KOrZy_RuFA@mail.gmail.com
Whole thread Raw
In response to Re: [GENERAL] Issue with json_agg() and ordering  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-general
>>
>> I guess that the order by should be in the aggregation.
>>
>> SELECT json_agg(a.* ORDER BY a.last_name, a.last_year DESC)
>> FROM my_table a;
>
> yes.  however, you would say, json_agg(a... not 'a.*').  The .*
> notation only works in certain contexts, and is transformed at parse
> time to, a.col1, a.col2, a.col3...  which would not work inside an
> aggregation function which can only handle a single column or record.
>
> merlin


Awesome ! Thanks Charles for the answer, and Merlin for the
tweaking/additional insight.


pgsql-general by date:

Previous
From: "Peter J. Holzer"
Date:
Subject: Re: [GENERAL] pglogical bidirectional replication of sequences
Next
From: Ken Tanzer
Date:
Subject: [GENERAL] Fields re-ordered on JOIN with * and USING