how to tell the difference between empty field and null field

From: Alex Howansky <alex(at)wankwood(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: how to tell the difference between empty field and null field
Date: 1999-12-13 04:17:01
Message-ID: Pine.LNX.4.20.9912122157220.18303-100000@net-srv-0001.bvrd.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Assuming a table such as this:

create table users (
user text,
password text,
name text,
domain text
);

...and data such as this:

insert into users values
('frank','zCeZ6f2f.NUKU','Frank Farley','domain.com');

insert into users values
('joe','QJixz/XLXvio2','Joe Blogg','');

insert into users values
('sam','kAdhVr3URa4Y.','Sam Stooge');

Note that joe has a blank domain field, while sam has none.

I want to know what users don't have a domain specified in their domain field.
But the query:

select * from users where domain = '';

only shows me joe, and the query:

select * from users where domain = null;

only shows me sam.

So, I use:

select * from users where domain = '' or domain = null;

Here's my question: if I have a zillion records in this table, and it's indexed
by user+domain, how can I run this query without losing the benefit of the
index?

--
Alex Howansky
alex(at)wankwood(dot)com
http://www.wankwood.com/

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 1999-12-13 05:14:20 Re: [SQL] how to tell the difference between empty field and null field
Previous Message Bruno Mendonca 1999-12-12 20:13:53