Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQgxq-0001fB-Gt for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Jul 2016 20:22:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bQgxo-00031M-NZ for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Jul 2016 20:22:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bQgxA-0002Jq-0Y for pgsql-bugs@postgresql.org; Fri, 22 Jul 2016 20:21:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bQgx6-0000Or-TR for pgsql-bugs@postgresql.org; Fri, 22 Jul 2016 20:21:46 +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 u6MKLi0h010228; Fri, 22 Jul 2016 16:21:44 -0400 From: Tom Lane To: Andrew Gierth cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14235: inconsistencies with IS NULL / IS NOT NULL In-reply-to: <8760sg96u2.fsf@news-spur.riddles.org.uk> References: <20160708024746.1410.57282@wrigleys.postgresql.org> <8760sg96u2.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Fri, 08 Jul 2016 04:10:10 +0100" Date: Fri, 22 Jul 2016 16:21:44 -0400 Message-ID: <10227.1469218904@sss.pgh.pa.us> X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Andrew Gierth writes: > And here's my analysis of what seems to be going on: > The executor, when doing IS [NOT] NULL on a composite value, looks at > each column to see if it is the null value. It does NOT recurse into > nested composite values, and my reading of the spec suggests that this > is correct. Hmm. Of course the $64 question is whether that really is correct, or sensible. I went to look at the spec, and discovered that SQL:2011 actually has wording that is different from SQL99, which I think is what we relied on last time we considered this issue. Specifically, in 2011, section 8.8 quoth: ::= ::= IS [ NOT ] NULL (Oddly, SQL does not seem to allow IS [NOT] NULL on non-composite values, which is just silly.) 1) Let R be the and let V be the value of R. 2) Case: a) If V is the null value, then “R IS NULL” is True and the value of “R IS NOT NULL” is False. b) Otherwise: i) The value of “R IS NULL” is Case: 1) If the value of every field of V is the null value, then True. 2) Otherwise, False. ii) The value of “R IS NOT NULL” is Case: 1) If the value of no field of V is the null value, then True. 2) Otherwise, False. NOTE 267 — For all R, “R IS NOT NULL” has the same result as “NOT R IS NULL” if and only if R is of degree 1. Rule (2a) was not there in SQL99. But look at what this is doing: it is admitting straight out that a null composite value is not the same as a composite value all of whose fields are null. It is only asserting that a will not distinguish them. The implication is that it's just fine if, say, COALESCE() doesn't act that way. Previously, we thought this part of the spec was supposed to define what "V is null" means everywhere else in the spec if V is composite; but now it seems clear that "V is null" is a primitive test that is not the same as the construct. > It seems possible that this could be fixed by simply setting > argisrow=false for all the null tests generated in such cases. I concur that this is an appropriate fix if we believe that ExecEvalNullTest's behavior is correct. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs