Re: Returning values from an array of JSONB objects. - Mailing list pgsql-general

From Christoph Moench-Tegeder
Subject Re: Returning values from an array of JSONB objects.
Date
Msg-id 20160413111631.GA1620@elch.exwg.net
Whole thread Raw
In response to Returning values from an array of JSONB objects.  (sighup <rts@sighup.eu>)
List pgsql-general
## sighup (rts@sighup.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


pgsql-general by date:

Previous
From: Alex Ignatov
Date:
Subject: Re: Freezing localtimestamp and other time function on some value
Next
From: Thomas Kellerer
Date:
Subject: Why is the comparison between timestamp and date so much slower then between two dates