pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tod McQuillin <devin@spamcop.net>
To: Kovacs Baldvin <kb136@hszk.bme.hu>
Cc: pgsql-sql@postgresql.org
Subject: Re: Intentional, or bug?
Date: Mon, 17 Sep 2001 00:04:02 +0900 (JST)
Message-ID: <20010916235732.G46039-100000@glass.pun-pun.prv> (raw)
In-Reply-To: <Pine.GSO.4.33.0109161601050.10242-100000@ural2>

On Sun, 16 Sep 2001, Kovacs Baldvin wrote:

> select NULL = NULL;
>
> The answer is: true!!!

This has got to be a bug.  NULL is not equal to anything (nor is it
unequal to anything).

SQL uses tri-valued logic, where answers are either true, false, or
unknown.

When selecting where a = b, if either is null the row will not be
selected.  Likewise for a <> b.  This is standard correct behaviour for
SQL.  One rationale is, if null represents an unknown value then how can
you know if it's equal or not?  It might in fact be equal but we don't
know.

> However, I have a real life problem, when not all data is given in
> a column, so I need a query to include the NULL=NULL rows. I can
> workaround it as defining a new operator, ~=, with the
> meaning "both null, or =". I did it, it works, but very slow.

If you want the rows where a = b and where a and b are both NULL, you must
specify it precisely:

where a = b or (a is null and b is null)

> So, is it an intentinal way of functioning, or it is bug somewhere?

This is how it is supposed to work.
-- 
Tod McQuillin





view thread (4+ messages)  latest in thread

Message-ID: <20010916235732.G46039-100000@glass.pun-pun.prv>
Permalink:  ../20010916235732.G46039-100000@glass.pun-pun.prv/
Also on:    postgresql.org/message-id/20010916235732.G46039-100000@glass.pun-pun.prv

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: devin@spamcop.net, kb136@hszk.bme.hu
  Subject: Re: Intentional, or bug?
  In-Reply-To: <20010916235732.G46039-100000@glass.pun-pun.prv>
  References: <Pine.GSO.4.33.0109161601050.10242-100000@ural2> <20010916235732.G46039-100000@glass.pun-pun.prv>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox