pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@postnewspapers.com.au>
To: Pilling, Michael <Michael.Pilling@dsto.defence.gov.au>
Cc: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6064: != NULL, <> NULL do not work [sec=UNCLASSIFIED]
Date: Mon, 20 Jun 2011 08:35:10 +0800
Message-ID: <4DFE95BE.5090308@postnewspapers.com.au> (raw)
In-Reply-To: <DB2FF420856DB942829BF029A7E3C196029E3CB6@ednex514.dsto.defence.gov.au>
References: <201106170739.p5H7dLOe043882@wwwmaster.postgresql.org>
	<4DFB1C6F020000250003E7D4@gw.wicourts.gov>
	<4DFDBAB0.1000708@postnewspapers.com.au>
	<DB2FF420856DB942829BF029A7E3C196029E3CB6@ednex514.dsto.defence.gov.au>

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/



view thread (10+ messages)  latest in thread

Message-ID: <4DFE95BE.5090308@postnewspapers.com.au>
Permalink:  ../4DFE95BE.5090308@postnewspapers.com.au/
Also on:    postgresql.org/message-id/4DFE95BE.5090308@postnewspapers.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: craig@postnewspapers.com.au, Michael.Pilling@dsto.defence.gov.au, Kevin.Grittner@wicourts.gov
  Subject: Re: BUG #6064: != NULL, <> NULL do not work [sec=UNCLASSIFIED]
  In-Reply-To: <4DFE95BE.5090308@postnewspapers.com.au>
  References: <201106170739.p5H7dLOe043882@wwwmaster.postgresql.org> <4DFB1C6F020000250003E7D4@gw.wicourts.gov> <4DFDBAB0.1000708@postnewspapers.com.au> <DB2FF420856DB942829BF029A7E3C196029E3CB6@ednex514.dsto.defence.gov.au> <4DFE95BE.5090308@postnewspapers.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox