Re: DISTINCT *and* ORDER BY in aggregate functions on expressions(!)y - Mailing list pgsql-general

From Thorsten Glaser
Subject Re: DISTINCT *and* ORDER BY in aggregate functions on expressions(!)y
Date
Msg-id 9e86b053-a29a-a82-78f0-1228a391edc3@evolvis.org
Whole thread Raw
In response to Re: DISTINCT *and* ORDER BY in aggregate functions on expressions(!)y  (Alban Hertroys <haramrae@gmail.com>)
Responses Re: DISTINCT *and* ORDER BY in aggregate functions on expressions(!)y  (Alban Hertroys <haramrae@gmail.com>)
List 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 :-)



pgsql-general by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: PG16devel - vacuum_freeze_table_age seems not being taken into account
Next
From: Merlin Moncure
Date:
Subject: Re: Converting row elements into a arrays?