| From: | Bob Jones <r(dot)a(dot)n(dot)d(dot)o(dot)m(dot)d(dot)e(dot)v(dot)4+postgres(at)gmail(dot)com> |
|---|---|
| To: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
| Cc: | Charles Clavadetscher <clavadetscher(at)swisspug(dot)org>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Issue with json_agg() and ordering |
| Date: | 2017-09-01 21:17:07 |
| Message-ID: | CA+HuS5FZoqYvBLG7eX2W65fX5fJD8q9eerWzz0N_KOrZy_RuFA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ken Tanzer | 2017-09-01 21:25:35 | Fields re-ordered on JOIN with * and USING |
| Previous Message | Peter J. Holzer | 2017-09-01 18:17:34 | Re: pglogical bidirectional replication of sequences |