pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
UNIQUE, btree index allows duplicate records, if some fields are null
2+ messages / 2 participants
[nested] [flat]

* UNIQUE, btree index allows duplicate records, if some fields are null
@ 2006-02-09 19:38  Bryce Nesbitt <bryce1@obviously.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Bryce Nesbitt @ 2006-02-09 19:38 UTC (permalink / raw)
  To: pgsql-sql

This threw me for a loop.  Is this my fault, or a
problem in postgres?

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.

I had expected two records, identical in all respects including the
null value, to be rejected by the constraint.

This is with:
PostgreSQL 7.4.1 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.3
20030502 (Red Hat Linux 3.2.3-20)




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: UNIQUE, btree index allows duplicate records, if some fields are null
@ 2006-02-09 19:59  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Bryce Nesbitt <bryce1@obviously.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2006-02-09 19:59 UTC (permalink / raw)
  To: Bryce Nesbitt <bryce1@obviously.com>; +Cc: 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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2006-02-09 19:59 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-02-09 19:38 UNIQUE, btree index allows duplicate records, if some fields are null Bryce Nesbitt <bryce1@obviously.com>
2006-02-09 19:59 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox