Re: Extracting data from jsonb array?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Rob Sargent <robjsargent(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:17:33
Message-ID: CAKFQuwaXHneeDSiR8hdZNnr4AFtU5BwVsCWY9YuCEP0DqJB+ag@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Dec 7, 2020 at 6:13 PM Rob Sargent <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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2020-12-08 01:19:53 Re: Extracting data from jsonb array?
Previous Message Rob Sargent 2020-12-08 01:13:06 Re: Extracting data from jsonb array?