Re: selecting all records where a column is null

From: Andrew Sullivan <andrew(at)libertyrms(dot)info>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: selecting all records where a column is null
Date: 2002-06-20 20:11:57
Message-ID: 20020620161157.I1635@mail.libertyrms.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jun 20, 2002 at 11:46:43AM -0700, Elmshauser, Erik wrote:
> Hi, I am trying to select every record from a table where a specific
> column does not have a value in it yet.

What you are looking for is NULL, as you note. Your problem is this:

> select * from table where field = NULL;

To make an oversimplification, SQL uses a three-value logic: T,F, and
NULL. NULL is for unknown cases. So

NULL = NULL

is false, because the left side is unknown, and the right side
is unknown also. (It might be that if you knew the two values, they
would not be equivalent.) What you want is

SELECT * FROM table WHERE field IS NULL;

In 7.2.1, there is a switch that allows you to turn on "= NULL"
conversion, in order to support some old behaviour (I think to
support Access, but I forget). But unless you need it to support
some external program, don't use it. Use the IS NULL locution
instead, because it'll prevent you from getting snagged by this on
other systems.

A

--
----
Andrew Sullivan 87 Mowat Avenue
Liberty RMS Toronto, Ontario Canada
<andrew(at)libertyrms(dot)info> M6K 3E3
+1 416 646 3304 x110

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Seidman 2002-06-20 20:14:39 Re: circular REFERENCES
Previous Message Robert Treat 2002-06-20 19:57:38 Re: db grows and grows