Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fihbO-0005M8-38 for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Jul 2018 14:50:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fihbM-0000co-2j for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Jul 2018 14:50:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fihbL-0000cf-Sx for pgsql-bugs@lists.postgresql.org; Thu, 26 Jul 2018 14:50:47 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fihbI-0004CW-SI for pgsql-bugs@lists.postgresql.org; Thu, 26 Jul 2018 14:50:47 +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 w6QEogLR029665; Thu, 26 Jul 2018 10:50:42 -0400 From: Tom Lane To: "Raphael 'kena' Poss" cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15297: Irregular comparison rules for NULLs in tuples In-reply-to: <94ffed23-67eb-3eac-e08e-5d4bf5287d8d@thaumogen.net> References: <153261212701.1395.18260320763646237974@wrigleys.postgresql.org> <27390.1532613836@sss.pgh.pa.us> <94ffed23-67eb-3eac-e08e-5d4bf5287d8d@thaumogen.net> Comments: In-reply-to "Raphael 'kena' Poss" message dated "Thu, 26 Jul 2018 10:08:54 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29663.1532616642.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 26 Jul 2018 10:50:42 -0400 Message-ID: <29664.1532616642@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "Raphael 'kena' Poss" writes: > Op 26-07-18 om 10:03 schreef Tom Lane: >> We insist on non-null record values being totally ordered, because with= out >> that you can't build a working btree opclass for them. So the general >> principle for comparing corresponding fields in two records is that nul= ls >> sort after non-nulls and two nulls are treated as equal. > I'd really like this to be true (I like it, it's simple) but then how do > you explain that row(1, null) > row(1, 2) is NULL, and not true? both > sides are record values and they are not null, after all. Yeah, well, if we have a comparison operator comparing two syntactic row constructors, it works differently: that case breaks down the two field lists and applies the named operator to each pair of values. The behavior for nulls is just one of the discrepancies; that case is also more forgiving about field type differences. For instance this is allowed: regression=3D# select (1, 1, NULL::int) > (1, 1, 2.0); ?column? = ---------- = (1 row) but this not so much: regression=3D# create type int3 as (f1 int,f2 int,f3 int); CREATE TYPE regression=3D# create table i3 (c1 int3); CREATE TABLE regression=3D# insert into i3 values ((1,1,1)); INSERT 0 1 regression=3D# select c1 > (1, 1, 2.0) from i3; ERROR: cannot compare dissimilar column types integer and numeric at reco= rd column 3 Personally I'd be happy to lose all that special-case behavior for row constructors, but we'd get push-back on backwards compatibility. regards, tom lane