Re: Table column vales to JSON object keys?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"David G. Johnston" <david.g.johnston@xxxxxxxxx> writes:
> On Thursday, February 11, 2021, Wells Oliver <wells.oliver@xxxxxxxxx> 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





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux