Re: Fw: select null + 0 question

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Vincent Hikida <vhikida(at)inreach(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Fw: select null + 0 question
Date: 2003-07-14 06:45:23
Message-ID: 20030714064523.GB24361@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Jul 13, 2003 at 11:14:15PM -0700, Vincent Hikida wrote:
> Oops forgot to cc the list.
> > I just happened to notice another difference recently between Oracle and
> > Postgresql for the clause
> >
> > WHERE 1 IN (1,2,NULL)
> >
> > In Oracle, this clause is false because 1 compared to a NULL is false.
> > However, Postgresql will return a true. I actually don't know what the
> ANSI
> > standard is for this case. Perhaps someone else on this list will know.
> > Perhaps the standard body never even thought of this. Yes, I was actually
> > stung by this particular while using it in Oracle.

I can;t comment on what the correct answer is, but I beleive the reason it
works in Postgres is because the expression is expanded to:

WHERE (1=1) OR (1=0) OR (1=NULL)

which becomes:

WHERE TRUE OR FALSE OR NULL

which is TRUE. (standard tri-value logic)
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> "the West won the world not by the superiority of its ideas or values or
> religion but rather by its superiority in applying organized violence.
> Westerners often forget this fact, non-Westerners never do."
> - Samuel P. Huntington

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2003-07-14 07:39:51 Re: Fw: select null + 0 question
Previous Message Vincent Hikida 2003-07-14 06:43:09 Re: FYI: geometric means in one step without custom functions