Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 7BC93B5D80A for ; Sun, 19 Jun 2011 21:35:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 88437-02 for ; Mon, 20 Jun 2011 00:35:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [173.230.139.50]) by mail.postgresql.org (Postfix) with ESMTP id A606DB5D801 for ; Sun, 19 Jun 2011 21:35:22 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by www.postnewspapers.com.au (Postfix) with ESMTP id DEFD710D; Sun, 19 Jun 2011 20:35:21 -0400 (EDT) X-Virus-Scanned: amavisd-new at postnewspapers.com.au.com Received: from www.postnewspapers.com.au ([127.0.0.1]) by localhost (www.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id D+yrcYs4WIRj; Sun, 19 Jun 2011 20:35:21 -0400 (EDT) Received: from mail.postnewspapers.com.au (ppp171-128.static.internode.on.net [150.101.171.128]) by www.postnewspapers.com.au (Postfix) with ESMTP id CC19437; Sun, 19 Jun 2011 20:35:20 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id CC9F1AE975; Mon, 20 Jun 2011 08:35:19 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id GivgCbOK+kB1; Mon, 20 Jun 2011 08:35:14 +0800 (WST) Received: from [10.1.1.3] (124-169-169-221.dyn.iinet.net.au [124.169.169.221]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id ADA2BAE974; Mon, 20 Jun 2011 08:35:13 +0800 (WST) Message-ID: <4DFE95BE.5090308@postnewspapers.com.au> Date: Mon, 20 Jun 2011 08:35:10 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: "Pilling, Michael" CC: Kevin Grittner , pgsql-bugs@postgresql.org Subject: Re: BUG #6064: != NULL, <> NULL do not work [sec=UNCLASSIFIED] References: <201106170739.p5H7dLOe043882@wwwmaster.postgresql.org> <4DFB1C6F020000250003E7D4@gw.wicourts.gov> <4DFDBAB0.1000708@postnewspapers.com.au> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/175 X-Sequence-Number: 30554 On 20/06/2011 7:43 AM, Pilling, Michael wrote: > Thanks Craig, > > The real problem here then is that the documentation showing > the boolean comparison operators does not mention this quirk, which I > accept may be a standard quirk but it's still a quirk. What URL are you looking at? http://www.postgresql.org/docs/current/interactive/functions-comparison.html certainly does. Are you looking at documentation for a really ancient version like 6.x ? > You just > wouldn't go looking for that flag unless you had any inkling that > it might exist. You shouldn't use it, either. As documented, it's an ugly hack to work around a deficiency in MS Access, which doesn't use SQL correctly. You may not like how NULL comparisons work, but I *strongly* recommend that you get used to it because trying to ignore it *will* cause you problems down the track, and there won't be any other flags to flip to change the behaviour to how you want it. SQL's 3-value logic isn't always popular and isn't as logically consistent as I'd like when you get into messy things like arrays. Unfortunately, it's not practical to just rip it out of the system because it's so fundamentally linked into the relational calculus, how outer joins work, how aggregates work, etc. See: http://en.wikipedia.org/wiki/Null_(SQL) See: http://en.wikipedia.org/wiki/Three-valued_logic > And indeed the parser does not generate warnings either. Why would it? You might argue that performing an equality comparison to a literal NULL is probably a mistake. Unfortunately, many queries are written by query generators that will quite happily substitute null into placeholders. This is often correct and will return the expected result so long as you know what it means, eg: WHERE a = NULL OR b = 1; will return 't' if b is 1, and false (or null, which evaluates to false for WHERE clauses) when b is not 1, irrespective of the value of 'a'. This may well be the application author's intent, and it's certainly valid. Maybe Pg should have a warning when " = NULL " is seen that can be emitted at INFO log level, the same log level as the notices about implicit index creation etc. I doubt you'll find anyone enthusiastic about implementing it, though, and the added parser time cost hardly seems worth it. -- Craig Ringer Tech-related writing at http://soapyfrogs.blogspot.com/