Re: Extracting data from jsonb array? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Extracting data from jsonb array?
Date
Msg-id CAKFQuwaXHneeDSiR8hdZNnr4AFtU5BwVsCWY9YuCEP0DqJB+ag@mail.gmail.com
Whole thread Raw
In response to Re: Extracting data from jsonb array?  (Rob Sargent <robjsargent@gmail.com>)
Responses Re: Extracting data from jsonb array?  (Rob Sargent <robjsargent@gmail.com>)
List pgsql-general
On Mon, Dec 7, 2020 at 6:13 PM Rob Sargent <robjsargent@gmail.com> wrote:


postgres=# select id, array_agg(fa) from (select id, (jsonb_array_elements(js)->'key') as fa from foo) g group by id order by id;
 id |          array_agg          
----+------------------------------
  1 | {"\"r1kval\"","\"r1kval2\""}
  2 | {"\"r2kval\"","\"r2kval2\""}
(2 rows)

I think the quotes are a fault of example data?  

The quotes are the fault of the query author choosing the "->" operator instead of "->>".

David J.

pgsql-general by date:

Previous
From: Rob Sargent
Date:
Subject: Re: Extracting data from jsonb array?
Next
From: Rob Sargent
Date:
Subject: Re: Extracting data from jsonb array?