pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ken Tanzer <ken.tanzer@gmail.com>
Cc: Steve Baldwin <steve.baldwin@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: Rob Sargent <robjsargent@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Extracting data from jsonb array?
Date: Mon, 07 Dec 2020 23:16:18 -0500
Message-ID: <3210187.1607400978@sss.pgh.pa.us> (raw)
In-Reply-To: <CAD3a31Vr_xZXnayJTu_iRvEUHRy4_P3jDqptDimFgp_xWQQMyA@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>
	<f2651149-c274-3cea-651d-891f71843960@gmail.com>
	<CAD3a31XxwRS8cXT+wBQCdr=Urug0rRe_RCTQ9ATS=RXNLr4zDA@mail.gmail.com>
	<CAKFQuwYQcgnEczC8j37U3UuXDmCR7+7_s=M=gs97YM=mesrd_A@mail.gmail.com>
	<CAKE1Aibh8ekYEVpCZyCQyt0L9-75G7D=PV_b8Wht02DsQHZR5Q@mail.gmail.com>
	<CAD3a31V_1fGMGUx=v7CqrHE0kho+GpfhYtxfyEOV+Q4J-MuP2g@mail.gmail.com>
	<CAD3a31Vr_xZXnayJTu_iRvEUHRy4_P3jDqptDimFgp_xWQQMyA@mail.gmail.com>

Ken Tanzer <ken.tanzer@gmail.com> writes:
>> => select f.id, f.f1,f.f2,array_agg(t.key2) from foo as f,
>> jsonb_to_recordset(js) as t(key2 text) group by f.id;

> After a little more thought and experimenting, I'm not so sure about this
> part.  In particular, I'm not clear why Postgres isn't complaining about
> the f1 and f2 fields.  (It's not giving the "must appear in the GROUP BY
> clause or be used in an aggregate function" error that I would expect, and
> that I am getting when I try to apply this to my real query.)

> Can anyone explain to me why those fields don't need to be grouped?  Thanks.

If foo.id is a primary key, it knows that the "group by" doesn't really
merge any rows of foo, so it lets you get away with that.  I think this
is actually required by spec, but am too lazy to go check right now.

If foo.id isn't a primary key, then I'm confused too.  Can we see the
full declaration of the table?

			regards, tom lane





view thread (25+ messages)  latest in thread

Message-ID: <3210187.1607400978@sss.pgh.pa.us>
Permalink:  ../3210187.1607400978@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3210187.1607400978@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, ken.tanzer@gmail.com, steve.baldwin@gmail.com, david.g.johnston@gmail.com, robjsargent@gmail.com
  Subject: Re: Extracting data from jsonb array?
  In-Reply-To: <3210187.1607400978@sss.pgh.pa.us>
  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> <CAD3a31XxwRS8cXT+wBQCdr=Urug0rRe_RCTQ9ATS=RXNLr4zDA@mail.gmail.com> <CAKFQuwYQcgnEczC8j37U3UuXDmCR7+7_s=M=gs97YM=mesrd_A@mail.gmail.com> <CAKE1Aibh8ekYEVpCZyCQyt0L9-75G7D=PV_b8Wht02DsQHZR5Q@mail.gmail.com> <CAD3a31V_1fGMGUx=v7CqrHE0kho+GpfhYtxfyEOV+Q4J-MuP2g@mail.gmail.com> <CAD3a31Vr_xZXnayJTu_iRvEUHRy4_P3jDqptDimFgp_xWQQMyA@mail.gmail.com> <3210187.1607400978@sss.pgh.pa.us>

* 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