Re: null != null ??? - Mailing list pgsql-general

From Thomas Lockhart
Subject Re: null != null ???
Date
Msg-id 3BD986BE.81A735A4@fourpalms.org
Whole thread Raw
In response to null != null ???  (Fran Fabrizio <ffabrizio@mmrd.com>)
Responses Re: null != null ???  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
...
> This is an odd result.  Both sides of that where clause evaluate to
> null, so it is null=null, yet this is not evaluating to true
> because I'm getting no rows back.

This is expected behavior. NULL means "unknown", so you can not know
that they are equivalent. But it is *not* the same as "NULL=NULL",
because...

>  Just to confirm that null=null
> evaluates to true (double-checking my sanity):
> monitoring=# select null=null;
> ----------
>  t
> (1 row)
> Ok, quite bizarre.

Yes, this is an explicit feature in our parser to help out poor MSAccess
souls who have a product which generates illegal SQL queries. We put in
a specific rule to convert "anything=NULL" to "anything IS NULL", which
*is* legal syntax.

Check the archives to discover that no one is very happy with this
feature, except folks trying to use ODBC via Access and some goofy forms
interface. Sorry that it has bit you, but basically you should not rely
on this hack at any time, and the behavior "expr=expr" returning false
when each expression evaluates to NULL conforms to SQL standards.

> Can someone smarter than me tell me what I am missing?

I may not be smarter, just "been there, done that"; hopefully you will
find the information useful anyway ;)

                  - Thomas

pgsql-general by date:

Previous
From: Fran Fabrizio
Date:
Subject: null != null ???
Next
From: Vivek Khera
Date:
Subject: Re: DBD::Pg