Re: "=" operator vs. "IS"

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Stefan Weiss <spaceman(at)foo(dot)at>, pgsql-sql(at)postgresql(dot)org
Subject: Re: "=" operator vs. "IS"
Date: 2004-06-28 22:27:14
Message-ID: 200406281527.14116.scrawford@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> I'm just curious - why is it not possible to use the "=" operator
> to compare values with NULL? I suspect that the SQL standard
> specified it that way, but I can't see any ambiguity in an
> expression like "AND foo.bar = NULL". Is it because NULL does not
> "equal" any value, and the expression should be read as "foo.bar is
> unknown"? Or is there something else I'm missing?

You've got it. NULL is the _absence_ of a known value so any
comparison or operation on it yields an unknown result.

So why can't you use = NULL?

Consider the a list of names and ages where Jack's and Jill's ages are
null. Now we run a query to list people who are of the same age.
Should Jack and Jill be listed as being the same age? Of course not.
You can't compare whether the two unknown values are equal any more
than you could determine whether or not they are over 18.

The SQL spec and PostgreSQL properly use and enforce this
interpretation of NULL.

The correct way to ask your questions is ...where foo.bar is null...

Cheers,
Steve

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael A Nachbaur 2004-06-28 22:28:08 Re: "=" operator vs. "IS"
Previous Message Dmitri Bichko 2004-06-28 22:17:17 FW: "=" operator vs. "IS"