Re: Is NULL equal to NULL or not?

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: jco(at)cornelius-olsen(dot)dk
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is NULL equal to NULL or not?
Date: 2002-12-09 22:08:40
Message-ID: 3DF51468.6060106@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

jco(at)cornelius-olsen(dot)dk wrote:
>
> Hi,
>
> My first message on this list:
>
> Using PostgreSQL 7.1.3.
>
> I've noticed that
> select NULL=NULL;
> yields TRUE. It is also possible to select rows in this manner.

Not generally since 7.2:

http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/release-7-2.html

"In this release, comparisons using = NULL will always return
false (or NULL, more precisely). Previous releases automatically
transformed this syntax to IS NULL. The old behavior can be
re-enabled using a postgresql.conf parameter."

> At the same time in PL/pgSQL:
>
> drop function demo1();
> create function demo1() returns boolean as '
> declare
> a boolean:=NULL;
> b boolean:=NULL;
> begin
> return a=b;
> end;
> ' language 'plpgsql';

Not sure why that is. Different sub-parsing paths, perhaps?
However, the default has changed since the old days (7.1). The
hack was in place because ancient versions of Access (re: Access
95) used to call into the ODBC driver with parameters which
resulted in PostgreSQL getting queried with:

SELECT
...
WHERE field = NULL;

That behavior changed in Microsoft products a long time ago, so
the PostgreSQL behavior now mirrors the SQL standard. So from
this point forward, I'd code using IS NULL for NULL comparisons.
And I'd upgrade... ;-)

Hope that helps,

Mike Mascari

P.S.: NULLs are evil.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marc G. Fournier 2002-12-09 22:12:28 Re: publicly available PostGreSQL server?
Previous Message scott.marlowe 2002-12-09 22:08:08 Re: Is NULL equal to NULL or not?