Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vFco4-00Ev6d-Vn for pgsql-bugs@arkaria.postgresql.org; Sun, 02 Nov 2025 18:28:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vFco3-00D91M-6B for pgsql-bugs@arkaria.postgresql.org; Sun, 02 Nov 2025 18:27:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vFco2-00D91C-Tp for pgsql-bugs@lists.postgresql.org; Sun, 02 Nov 2025 18:27:57 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vFco0-0055Hs-0d for pgsql-bugs@lists.postgresql.org; Sun, 02 Nov 2025 18:27:56 +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 5A2IRsbc441301; Sun, 2 Nov 2025 13:27:55 -0500 From: Tom Lane To: Chris Hanks cc: pgsql-bugs@lists.postgresql.org Subject: Re: Inconsistencies around Composite Row nullness In-reply-to: References: Comments: In-reply-to Chris Hanks message dated "Sun, 02 Nov 2025 11:52:20 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <441299.1762108074.1@sss.pgh.pa.us> Date: Sun, 02 Nov 2025 13:27:54 -0500 Message-ID: <441300.1762108074@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Chris Hanks writes: > I've experienced some logically inconsistent query output on my local > Postgres instance, version string: PostgreSQL 18.0 (Homebrew) on > aarch64-apple-darwin25.0.0, compiled by Apple clang version 17.0.0 > (clang-1700.3.19.1), 64-bit Yeah, it's not terribly consistent, but neither is the SQL standard in this area. I believe what is happening in your first example is that the construct "ROW(a, b, ...) = ROW(x, y, ...)" is being broken down into "(a = x) AND (b = y) AND ...", from which you can get a NULL result as described. However, the insertion of coalesce() stops that decomposition from happening, and then what you get is the behavior of the native composite-type comparators (record_eq and friends). Those functions adhere to the btree requirement of producing a total order of the datatype, ie null results are not OK, so they report that ROW(NULL, 2) = ROW(NULL, 2) is true not null. We could get rid of some of the inconsistency by eliminating that special treatment of equality of two row-constructors, but I'm afraid there would be complaints from people who were relying on that behavior for optimization purposes. regards, tom lane