Re: FW: "=" operator vs. "IS"

From: Jeff Boes <jboes(at)qtm(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: FW: "=" operator vs. "IS"
Date: 2004-07-01 15:02:25
Message-ID: 41955aeb655d4b2976f0ae6878b95fa6@news.teranews.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?

As noted elsewhere, joining two tables on "a.foo = b.foo" where both foo
values are NULL is not usually what you want.

But if you really, truly do want that, then you always have this:

coalesce(a.foo,0) = coalesce(b.foo,0)

or a similar construct, using something in place of zero that has the
same base type as a.foo and b.foo, and which doesn't occur in either table.

(Why? Because you really don't want

a.foo = coalesce(b.foo,0)

or

b.foo = coalesce(a.foo,0)

to give you false positives.)

--
(Posted from an account used as a SPAM dump. If you really want to get
in touch with me, dump the 'jboes' and substitute 'mur'.)
________
Jeffery Boes <>< jboes(at)qtm(dot)net

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bob Hobart 2004-07-01 18:11:13 How to make a portable application?
Previous Message Phil Endecott 2004-07-01 09:57:23 Re: finding if a foreign key is in use