Re: Unique index with Null value in one field - Mailing list pgsql-general

From Tom Lane
Subject Re: Unique index with Null value in one field
Date
Msg-id 25944.1129085512@sss.pgh.pa.us
Whole thread Raw
In response to Unique index with Null value in one field  (Hrishi Joshi <hjoshi@abcsinc.com>)
List pgsql-general
Hrishi Joshi <hjoshi@abcsinc.com> writes:
> I need to define a Unique index on 3 non-PK fields (composite key) on my
> table in PostgreSQL 8.0.3.

> The problem is, if any of those 3 fields is Null, PostgreSQL allows
> duplicate rows to be inserted.

That is the behavior defined by the SQL standard.

> But I need to know how can I make PostgreSQL throw error on attempt to
> insert second record having same 3 field values, one of them being Null.

You can't.  Rethink your data representation, instead.  You are misusing
NULL if you think that it represents something unique.

            regards, tom lane

pgsql-general by date:

Previous
From: Aileen
Date:
Subject: Xampp, PostgreSQL & phpPgAdmin
Next
From: Tom Lane
Date:
Subject: Re: [pgsql-advocacy] Oracle buys Innobase