From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Wells Oliver <wells.oliver@gmail.com>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: Table column vales to JSON object keys?
Date: Thu, 11 Feb 2021 15:15:35 -0500
Message-ID: <1484156.1613074535@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwYTvbo4AqgY62xLdU=g8FaLFA5Ggr9ZAmtHTCPZTvp=rQ@mail.gmail.com>
References: <CAOC+FBU_ChUfOhVC9LJFOFwzQYH2=ZEBpY_cbNTL8zhexJvQow@mail.gmail.com>
<CAKFQuwYTvbo4AqgY62xLdU=g8FaLFA5Ggr9ZAmtHTCPZTvp=rQ@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Thursday, February 11, 2021, Wells Oliver <wells.oliver@gmail.com> wrote:
>> Trying to go from a table like:
>>
>> g | e | angle | path
>> ----+---+--------+----------------------
>> g1 | e1 | a1 | http://foo.com/a.mp4
>> g1 | e1 | a2 | http://foo.com/b.mp4
>> g1 | e1 | a3 | http://foo.com/c.mp4
>>
>> To a table like this, with a column value per angle as a key.
>>
>> g | e | obj
>> ----+---+---------------------------------------------------
>> ------------------------------------------
>> g1 | e1 | {"a1": "http://foo.com/a.mp4";, "a2": "http://foo.com/b.mp4";,
>> "a3": "http://foo.com/c.mp4";}
>>
>> Can't quite get there.
> How far can you get?
I'm guessing something like
SELECT g, e, json_object_agg(angle, path) FROM ... GROUP BY g, e
would work, but haven't experimented.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, wells.oliver@gmail.com
Subject: Re: Table column vales to JSON object keys?
In-Reply-To: <1484156.1613074535@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox