Re: Is NULL equal to NULL or not?

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(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:08
Message-ID: Pine.LNX.4.33.0212091454230.1276-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 9 Dec 2002 jco(at)cornelius-olsen(dot)dk wrote:

> Hi,
>
> My first message on this list:
>
> Using PostgreSQL 7.1.3.

Stop. Upgrade right now. You're asking questions about a version of
postgresql that is quite old now. I'm not sure I remember using 7.1.3,
but since I started out with 6.5.2, I'm sure I must have. But it's been a
long long long time since I've used either, and I certainly don't have a
test box laying around running it. So I can't test anything on my end to
see how it works.

However, on 7.3, select 1 where null=null; gets me a 0 output. Same goes
for 7.2.3.

> I've noticed that
> select NULL=NULL;
> yields TRUE. It is also possible to select rows in this manner.

That's NOT because null EQUALS null, but because it allowed you to assign
one null value to another. which technically can be done, so it came out
true.

> 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';
>
> > select demo1();
> yields NULL. Yet if I'd written "return NULL=NULL" I would have gotten the
> same result as in the simple query;

Try a line like this:

return a is null;

and see what you get. Use the verb is, not the = sign to compared nulls.
NOT is to decide it not null.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mike Mascari 2002-12-09 22:08:40 Re: Is NULL equal to NULL or not?
Previous Message James F 2002-12-09 21:50:44 Referencing columns of the fly in triggers