Re: UNIQUE, btree index allows duplicate records, if some fields are null - Mailing list pgsql-sql

From Tom Lane
Subject Re: UNIQUE, btree index allows duplicate records, if some fields are null
Date
Msg-id 4118.1139515154@sss.pgh.pa.us
Whole thread Raw
In response to UNIQUE, btree index allows duplicate records, if some fields are null  (Bryce Nesbitt <bryce1@obviously.com>)
List pgsql-sql
Bryce Nesbitt <bryce1@obviously.com> writes:
> I have a table with the following:
>     "eg_vehicle_event_pkey" PRIMARY KEY, btree (event_id)
>     "no_duplicate_events" UNIQUE, btree (thing, other_thing,
> "timestamp", number, other_number)

> The "no_duplicate_events" constraint works fine, but if I insert records
> where
> "other_thing" is null, they all go in without complaint. I can insert as
> many duplicates as I want.

This is per SQL spec.  You're imagining that two nulls are considered
equal, which they are not.
        regards, tom lane


pgsql-sql by date:

Previous
From: Bryce Nesbitt
Date:
Subject: UNIQUE, btree index allows duplicate records, if some fields are null
Next
From: george young
Date:
Subject: Re: unique constraint instead of primary key? what