Re: 8.1 Unique Index Issue/Bug??? - Mailing list pgsql-admin

From Michael Fuhr
Subject Re: 8.1 Unique Index Issue/Bug???
Date
Msg-id 20060713161546.GA86489@winnie.fuhr.org
Whole thread Raw
In response to 8.1 Unique Index Issue/Bug???  ("Chris Hoover" <revoohc@gmail.com>)
List pgsql-admin
On Thu, Jul 13, 2006 at 10:40:43AM -0400, Chris Hoover wrote:
> Why is PostgreSQL not enforcing this index? This appears to be a pretty
> major a bug?  It would seem that you could have a unique index across
> columns that might have a null in them.

This comes up frequently due to a misunderstanding of how NULL
comparison works.

http://www.postgresql.org/docs/8.1/interactive/ddl-constraints.html#AEN2016

"In general, a unique constraint is violated when there are two or
more rows in the table where the values of all of the columns
included in the constraint are equal.  However, null values are not
considered equal in this comparison.  That means even in the presence
of a unique constraint it is possible to store duplicate rows that
contain a null value in at least one of the constrained columns.
This behavior conforms to the SQL standard, but we have heard that
other SQL databases may not follow this rule.  So be careful when
developing applications that are intended to be portable."

--
Michael Fuhr

pgsql-admin by date:

Previous
From: Chris Browne
Date:
Subject: Re: Where are the temporary work / sort files please
Next
From: "Aaron Bono"
Date:
Subject: Re: 8.1 Unique Index Issue/Bug???