Re: Returning values from an array of JSONB objects.

From: Christoph Moench-Tegeder <cmt(at)burggraben(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Returning values from an array of JSONB objects.
Date: 2016-04-13 11:16:32
Message-ID: 20160413111631.GA1620@elch.exwg.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

## sighup (rts(at)sighup(dot)eu):

> How can I extract the value of the 'items' key either as two rows and or
> a sum of both.

select id, jsonb_array_elements(markers)->>'items' from data;
And as jsonb_array_elements() returns a setof jsonb:
with tab(id, items) as (
select id, (jsonb_array_elements(markers)->>'items')::integer from d
) select id, sum(items) from tab group by id;

Regards,
Christoph

--
Spare Space

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alex Ignatov 2016-04-13 11:17:03 Re: Freezing localtimestamp and other time function on some value
Previous Message Alex Ignatov 2016-04-13 11:16:05 Re: Freezing localtimestamp and other time function on some value