From: | Wells Oliver <wells(dot)oliver(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-admin <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: Table column vales to JSON object keys? |
Date: | 2021-02-11 21:04:11 |
Message-ID: | CAOC+FBUNdTzMHYp9y04VgKBt3YXiHTEVPPBwE0mNm0jrd1EX7A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
Thanks! jsonb_object_agg() is indeed the solution.
On Thu, Feb 11, 2021 at 12:15 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> > On Thursday, February 11, 2021, Wells Oliver <wells(dot)oliver(at)gmail(dot)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
>
--
Wells Oliver
wells(dot)oliver(at)gmail(dot)com <wellsoliver(at)gmail(dot)com>
From | Date | Subject | |
---|---|---|---|
Next Message | Don Seiler | 2021-02-11 22:01:29 | Re: Managing autovacuum freezing |
Previous Message | Tom Lane | 2021-02-11 20:15:35 | Re: Table column vales to JSON object keys? |