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 1q01mv-00022x-3a for pgsql-bugs@arkaria.postgresql.org; Fri, 19 May 2023 15:13:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q01mt-0001Xz-R1 for pgsql-bugs@arkaria.postgresql.org; Fri, 19 May 2023 15:12:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q01mt-0001Xq-If for pgsql-bugs@lists.postgresql.org; Fri, 19 May 2023 15:12:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q01mq-000k9h-Gg for pgsql-bugs@lists.postgresql.org; Fri, 19 May 2023 15:12:58 +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 34JFCskx099861; Fri, 19 May 2023 11:12:55 -0400 From: Tom Lane To: "David G. Johnston" cc: sulfinu@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: Aggregation results with json(b)_agg and array_agg in a SELECT with OUTER JOIN In-reply-to: References: <35907.1684505642@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Fri, 19 May 2023 07:36:49 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <99859.1684509174.1@sss.pgh.pa.us> Date: Fri, 19 May 2023 11:12:54 -0400 Message-ID: <99860.1684509174@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > I agree that, in at least the json_agg case, the json array that is > produced should be an json object with keys matching the names of the > fields of the composite. Well, it *is*, if the input is a composite value. A bare NULL isn't a composite value. Observe the difference: regression=# select to_json(null::b); to_json --------- (1 row) regression=# select to_json(null::b) is null; ?column? ---------- t (1 row) regression=# select to_json(row(null,null)::b); to_json ------------------------ {"name":null,"a":null} (1 row) As I said, we do not treat null::b and row(null,null)::b exactly alike. We could spend a long time arguing about the merits of that and whether or not it exactly satisfies the SQL spec, but at the end of the day, the odds of it changing in Postgres are epsilon. I do not agree that it's wrong, and even if I did I doubt we'd take the compatibility hit of changing it. regards, tom lane