Re: Extracting data from jsonb array?

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Extracting data from jsonb array?
Date: 2020-12-08 01:19:53
Message-ID: f2651149-c274-3cea-651d-891f71843960@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On 12/7/20 6:17 PM, David G. Johnston wrote:
> On Mon, Dec 7, 2020 at 6:13 PM Rob Sargent <robjsargent(at)gmail(dot)com
> <mailto:robjsargent(at)gmail(dot)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.
With that correction OP might have an answer?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ken Tanzer 2020-12-08 01:39:59 Re: Extracting data from jsonb array?
Previous Message David G. Johnston 2020-12-08 01:17:33 Re: Extracting data from jsonb array?