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:44:59 -0500
Message-ID: <3211450.1607402699@sss.pgh.pa.us> (raw)
In-Reply-To: <CAD3a31WBtf0WzypuW6-Q-WOtTqa-dkit1TEC-PkJzHOr1nd_xA@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>
	<3210187.1607400978@sss.pgh.pa.us>
	<CAD3a31WBtf0Wzy! puW6-Q-WOtTqa-dkit1TEC-PkJzHOr1nd_xA@mail.gmail.com>

Ken Tanzer <ken.tanzer@gmail.com> writes:
> On Mon, Dec 7, 2020 at 8:16 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> 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 I do that without the Primary Key, it does indeed complain about f1 & f2
> not being grouped.  But what is the "It" in "it lets you get away with
> that" referring to?

Sorry I was vague there, it's the parse analysis phase that understands
that "GROUP BY a primary key" should be treated as allowing any column of
that pkey's table to be referenced without also explicitly grouping by
that other column.  If you then join to some other table, the free pass
doesn't extend to the other table.

> Or more specifically, is this some specialized case
> because of something related to use of the jsonb_recordset function?

Nope, unrelated to that.

> I've
> gotten so used to having to group on every non-aggregate field that I
> didn't realize there could be any exception to that.

We did not use to have this bit of logic, so maybe your habits were
formed a few years ago.  But as I said, I think the SQL spec says
this should be OK.  Definitely, there are other DBMSes that also
allow it.

			regards, tom lane





view thread (25+ messages)  latest in thread

Message-ID: <3211450.1607402699@sss.pgh.pa.us>
Permalink:  ../3211450.1607402699@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3211450.1607402699@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: <3211450.1607402699@sss.pgh.pa.us>
  References: <CAD3a31UQuYmXLuHLFtF1NTZyFSjdHfAKeSkie8GT5K_2ahAh=Q@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> <3211450.1607402699@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