RE: array_to_json/array_agg question

2024-02-20 Thread Patrick FICHE
On 2024-02-20 10:48 +0100, Laura Smith wrote: > Before I go down the road of taking care of this in the front-end > through iterations, I thought I would ask the pgsql if there was a > clever query I could do on postgres that would take care of it for me > instead. > > In essence, I would like

Re: array_to_json/array_agg question

2024-02-20 Thread Laura Smith
> You almost got the subrecord ("value_1" and "value_2") right. You need > to use json_build_object() (or even the new json_object() function added > in pg16) instead of row_to_json() to just include "value_1" and > "value_2". Then GROUP BY "key" and aggregate the subrecords with > json_agg().

Re: array_to_json/array_agg question

2024-02-20 Thread Erik Wienhold
On 2024-02-20 10:48 +0100, Laura Smith wrote: > Before I go down the road of taking care of this in the front-end > through iterations, I thought I would ask the pgsql if there was a > clever query I could do on postgres that would take care of it for me > instead. > > In essence, I would like to

array_to_json/array_agg question

2024-02-20 Thread Laura Smith
Hi Before I go down the road of taking care of this in the front-end through iterations, I thought I would ask the pgsql if there was a clever query I could do on postgres that would take care of it for me instead. In essence, I would like to consolidate values from the same key as a json