Re: How to enforce uniqueness when NULL values are present?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Christian Schröder <cs(at)deriva(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to enforce uniqueness when NULL values are present?
Date: 2007-03-11 10:23:29
Message-ID: 20070311102329.GB26281@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Mar 11, 2007 at 11:09:56AM +0100, Christian Schröder wrote:
> Of course, if a NULL always means "unknown", then this approach doesn't
> make sense. Where can I find an authorative definition of what NULL
> means? As I have quoted before, according to the Wikipedia (far from
> being authorative!) a NULL can also mean "not applicable".

Nowhere. SQL's definition of NULL isn't even consistant, which is why
some people prefer to avoid it altogether.

Your particular case may be solvable with:

CREATE UNIQUE INDEX foo ON bar(key1, (coalesce(key2,'1900-01-01')));

Though I agree that -infinity would be a better fit.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Berend Tober 2007-03-11 11:07:16 Re: How to enforce uniqueness when NULL values are present?
Previous Message Christian Schröder 2007-03-11 10:09:56 Re: How to enforce uniqueness when NULL values are present?