Re: Unique indexes not unique?

From: dev(at)archonet(dot)com
To: "Tomasz Myrta" <jasiek(at)klaster(dot)net>
Cc: jimmy(dot)makela(at)agent25(dot)se, "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Unique indexes not unique?
Date: 2003-01-13 12:32:05
Message-ID: 1477.192.168.1.16.1042461125.squirrel@mainbox.archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> Jimmy Mäkelä wrote:
>
>> I found that Postgres isn't behaving like I thought when using a
>> unique index in
>> combination with NULL-values...
>> Is this a bug or specified in the SQL-standard? If its a bug, is it
>> fixed in a
>> recent version? We are using 7.2.3

>> intranet=# insert into "foo" (a, b) values ('apa', null);
>> INSERT 26229706 1
>> intranet=# insert into "foo" (a, b) values ('apa', null);
>> INSERT 26229707 1
>
> I'm not sure unique index works properly for null values. I can't
> explain, why. Maybe it comes from SQL standard - null i a special value
> and can't be compared using default operators to other non null values:
> 1>null =null
> 1<null =null
> 1=null =null

Null is not a value or even a "special" value, it is supposed to represent
the absence of a value. It means either "not applicable" or "not known".

It doesn't make sense to say whether one null is the same as another, a
null is an absence, a hole. As a result, you can't really talk about
comparing two nulls, only testing whether a value is null.

If you are using a null in a situation where it should be unique, you
probably want a value instead. Can't say more without an actual example.

- Richard Huxton

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message dev 2003-01-13 12:47:01 Crosstab-style query in pure SQL
Previous Message Stephan Szabo 2003-01-13 12:08:04 Re: Unique indexes not unique?