Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmUs7-0005H1-PN for pgsql-general@arkaria.postgresql.org; Tue, 08 Dec 2020 04:45:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kmUs3-0004bK-VB for pgsql-general@arkaria.postgresql.org; Tue, 08 Dec 2020 04:45:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmUs3-0004bC-NC for pgsql-general@lists.postgresql.org; Tue, 08 Dec 2020 04:45:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmUs1-0002ot-7c for pgsql-general@lists.postgresql.org; Tue, 08 Dec 2020 04:45:02 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0B84ixpr3211451; Mon, 7 Dec 2020 23:44:59 -0500 From: Tom Lane To: Ken Tanzer cc: Steve Baldwin , "David G. Johnston" , Rob Sargent , "pgsql-generallists.postgresql.org" Subject: Re: Extracting data from jsonb array? In-reply-to: References: <72f54672-ad66-0370-9128-206e49389b60@gmail.com> <3210187.1607400978@sss.pgh.pa.us> Comments: In-reply-to Ken Tanzer message dated "Mon, 07 Dec 2020 20:32:06 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3211449.1607402699.1@sss.pgh.pa.us> Date: Mon, 07 Dec 2020 23:44:59 -0500 Message-ID: <3211450.1607402699@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ken Tanzer writes: > On Mon, Dec 7, 2020 at 8:16 PM Tom Lane 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