Re: UNIQUE, btree index allows duplicate records, if some fields are null

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bryce Nesbitt <bryce1(at)obviously(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: UNIQUE, btree index allows duplicate records, if some fields are null
Date: 2006-02-09 19:59:14
Message-ID: 4118.1139515154@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Bryce Nesbitt <bryce1(at)obviously(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message george young 2006-02-09 20:10:18 Re: unique constraint instead of primary key? what
Previous Message Bryce Nesbitt 2006-02-09 19:38:35 UNIQUE, btree index allows duplicate records, if some fields are null