Search Postgresql Archives

Re: Returning values from an array of JSONB objects.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



## sighup (rts@xxxxxxxxx):

> 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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux