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 1jduzd-0003sL-Ev for pgsql-bugs@arkaria.postgresql.org; Wed, 27 May 2020 12:17:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jduzc-0006AE-AS for pgsql-bugs@arkaria.postgresql.org; Wed, 27 May 2020 12:17:08 +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 1jduzc-0006A6-3v for pgsql-bugs@lists.postgresql.org; Wed, 27 May 2020 12:17:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jduzR-0007W6-Rg for pgsql-bugs@lists.postgresql.org; Wed, 27 May 2020 12:17:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 04RCGt6H005356; Wed, 27 May 2020 08:16:55 -0400 From: Tom Lane To: lukas.eder@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16465: Inconsistent results from comparison of row value expressions In-reply-to: <16465-0ec89f0382fd00db@postgresql.org> References: <16465-0ec89f0382fd00db@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 27 May 2020 08:00:46 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5354.1590581815.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 27 May 2020 08:16:55 -0400 Message-ID: <5355.1590581815@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > It seems the comparison of row value expressions with respect to NULLs i= s > inconsistent depending on whether the expressions are compared directly > (first column), or indirectly from derived tables (second column). My > reading of the SQL standard is that the second one is incorrect. This is per the documentation [1], which says The SQL specification requires row-wise comparison to return NULL if the result depends on comparing two NULL values or a NULL and a non-NULL. PostgreSQL does this only when comparing the results of two row constructors (as in Section 9.23.5) or comparing a row constructor to the output of a subquery (as in Section 9.22). In other contexts where two composite-type values are compared, two NULL field values are considered equal, and a NULL is considered larger than a non-NULL. This is necessary in order to have consistent sorting and indexing behavior for composite types. The short answer here is that comparison of two non-null composite type values cannot be allowed to yield null, or we could not sort or index them. That'd be a high price to pay for conforming to a dubious-to- begin-with spec detail. regards, tom lane [1] https://www.postgresql.org/docs/current/functions-comparisons.html#COM= POSITE-TYPE-COMPARISON