Re: DISTINCT *and* ORDER BY in aggregate functions on expressions(!)y
Thorsten Glaser <tg@evolvis.org>
From: Thorsten Glaser <tg@evolvis.org>
To: Alban Hertroys <haramrae@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Date: 2023-03-03T19:32:14Z
Lists: pgsql-general
On Fri, 3 Mar 2023, Alban Hertroys wrote:
>You can rewrite that into something like this:
>
>select jsonb_build_object('opening_times’,
> obj
> ORDER BY
> obj->>'weekday’,
> obj->>'from_hour’,
> obj->>'to_hour')
>)
>from cot
>cross join lateral jsonb_agg(jsonb_build_object(
> 'weekday', cot.weekday,
> 'from_hour', cot.from_hour,
> 'to_hour', cot.to_hour) obj
But isn’t that the same as with a regular LEFT JOIN?
>> cgwaj AS (
>> SELECT cgwa.id AS id, jsonb_build_object(
>> 'weekday', cgwa.weekday,
>> 'forenoon', cgwa.forenoon,
>> 'afternoon', cgwa.afternoon,
>> 'evening', cgwa.evening) AS obj
>> FROM core_generalworkavailability cgwa
plus
>> LEFT JOIN cgwaj ON cgwaj.id=cppwt.generalworkavailability_id
With the addition that I can aggregate…
bye,
//mirabilos
--
15:41⎜<Lo-lan-do:#fusionforge> Somebody write a testsuite for helloworld :-)