Re: Unique Index

From: Greg Stark <gsstark(at)mit(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Unique Index
Date: 2005-01-20 06:32:14
Message-ID: 87fz0wpq4x.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alex <alex(at)meerkatsoft(dot)com> writes:

> I actually just wanted to know if there is a way around this problem. Obviously
> it is implemented that way for whatever reason.

The way around is to make all the columns NOT NULL. For most applications
unique indexes don't make much sense on nullable columns.

> (If I want to differentiate the state, I would use a code instead of NULL as
> a NULL does not give any indication of its meaning, thus we could safely
> assume they are treated as equal).

I think you have that backwards. You use NULL in the case where you want all
cases to compare as unknown values. If you want them to compare as known
values then you should use a special value.

In other words, NULL has special properties. You should use it if those
special properties are what you want. If you want the system to enforce a
unique constraint on the special value then you probably don't want to be
using NULL for that special state.

Specifically if you find yourself saying "we could safely assume they are
treated equal" then NULL is almost certainly not what you want to represent
that. NULL never compares equal to anything.

--
greg

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Matthew Smith 2005-01-20 06:55:43 SELECT * variant idea, is there something like this...
Previous Message Troyston Campano 2005-01-20 05:03:28 Oracle and Postgresql Play Nice Together on Same Computer?