Re: Table column vales to JSON object keys?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Table column vales to JSON object keys?
Дата
Msg-id 1484156.1613074535@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Table column vales to JSON object keys?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: Table column vales to JSON object keys?  (Wells Oliver <wells.oliver@gmail.com>)
Список pgsql-admin
"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



В списке pgsql-admin по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Table column vales to JSON object keys?
Следующее
От: Wells Oliver
Дата:
Сообщение: Re: Table column vales to JSON object keys?