pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Extracting data from jsonb array?
Date: Mon, 7 Dec 2020 18:19:53 -0700
Message-ID: <f2651149-c274-3cea-651d-891f71843960@gmail.com> (raw)
In-Reply-To: <CAKFQuwaXHneeDSiR8hdZNnr4AFtU5BwVsCWY9YuCEP0DqJB+ag@mail.gmail.com>
References: <CAD3a31UQuYmXLuHLFtF1NTZyFSjdHfAKeSkie8GT5K_2ahAh=Q@mail.gmail.com>
	<CAKE1AiaA7f_KJL0Qre=2Cnev4geGsrGmdbFPQYLpfCZnMS=DkQ@mail.gmail.com>
	<CAKFQuwaxB6bK_CSJaWM=OXjXya7BaV+3Pwpp9e4dPPSfB0CSrQ@mail.gmail.com>
	<CAD3a31VDRAV8_snO9SbxwJa77=aUJJTcsSvCRnc1v5mG8NqDkA@mail.gmail.com>
	<CAKFQuwY710pBKLXDhaGD-Sg27FOZro5uZ7GvBO8=aHbUYYWyWg@mail.gmail.com>
	<CAD3a31WNrMJq5bxQZ2+z5pEQU=wAn7Gtx2ahSmt6w5LiLqs57A@mail.gmail.com>
	<72f54672-ad66-0370-9128-206e49389b60@gmail.com>
	<CAKFQuwaXHneeDSiR8hdZNnr4AFtU5BwVsCWY9YuCEP0DqJB+ag@mail.gmail.com>


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

view thread (25+ messages)  latest in thread

Message-ID: <f2651149-c274-3cea-651d-891f71843960@gmail.com>
Permalink:  ../f2651149-c274-3cea-651d-891f71843960@gmail.com/
Also on:    postgresql.org/message-id/f2651149-c274-3cea-651d-891f71843960@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: robjsargent@gmail.com, david.g.johnston@gmail.com
  Subject: Re: Extracting data from jsonb array?
  In-Reply-To: <f2651149-c274-3cea-651d-891f71843960@gmail.com>
  References: <CAD3a31UQuYmXLuHLFtF1NTZyFSjdHfAKeSkie8GT5K_2ahAh=Q@mail.gmail.com> <CAKE1AiaA7f_KJL0Qre=2Cnev4geGsrGmdbFPQYLpfCZnMS=DkQ@mail.gmail.com> <CAKFQuwaxB6bK_CSJaWM=OXjXya7BaV+3Pwpp9e4dPPSfB0CSrQ@mail.gmail.com> <CAD3a31VDRAV8_snO9SbxwJa77=aUJJTcsSvCRnc1v5mG8NqDkA@mail.gmail.com> <CAKFQuwY710pBKLXDhaGD-Sg27FOZro5uZ7GvBO8=aHbUYYWyWg@mail.gmail.com> <CAD3a31WNrMJq5bxQZ2+z5pEQU=wAn7Gtx2ahSmt6w5LiLqs57A@mail.gmail.com> <72f54672-ad66-0370-9128-206e49389b60@gmail.com> <CAKFQuwaXHneeDSiR8hdZNnr4AFtU5BwVsCWY9YuCEP0DqJB+ag@mail.gmail.com> <f2651149-c274-3cea-651d-891f71843960@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox