Re: [GENERAL] json aggregation question

Поиск
Список
Период
Сортировка
От Paul Jungwirth
Тема Re: [GENERAL] json aggregation question
Дата
Msg-id c9dbbd48-736c-1703-878d-5b1325fef3b8@illuminatedcomputing.com
обсуждение исходный текст
Ответ на [GENERAL] json aggregation question  (Chris Withers <chris@simplistix.co.uk>)
Список pgsql-general
On 02/28/2017 08:21 AM, Chris Withers wrote:
> How can I aggregate the results of a query that equates to "show me the
> number of matching rows and the set of |tag1| value that have
> a |tag2| value of |t2val1|?
>
> ...but I really want:
>
> |count |tag1 -------+-------------------------2|["val1","val2","val3"](1row)|

Seems like this does the trick?:

     SELECT  COUNT(DISTINCT id),
             json_agg(DISTINCT elem)
     FROM    (
       SELECT  id,
               jsonb_array_elements_text(tags->'tag1') AS elem
       FROM    thing
       WHERE   tags->'tag2'?'t2val1'
     ) x;

You are looking to get always one result, right?

Yours,
Paul



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

Предыдущее
От: Sasa Vilic
Дата:
Сообщение: Re: [GENERAL] Shared WAL archive between master and standby: WALs notalways identical
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: [GENERAL] Shared WAL archive between master and standby: WALs notalways identical