pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Chris Hoover <revoohc@gmail.com>
Cc: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: 8.1 Unique Index Issue/Bug???
Date: Thu, 13 Jul 2006 08:57:53 -0700 (PDT)
Message-ID: <20060713085157.H49004@megazone.bigpanda.com> (raw)
In-Reply-To: <1d219a6f0607130740g7fe13967t48c77a64fde977aa@mail.gmail.com>
References: <1d219a6f0607130740g7fe13967t48c77a64fde977aa@mail.gmail.com>

On Thu, 13 Jul 2006, Chris Hoover wrote:

> I am having what appears to be a bug with unique indexes on 8.1.3.
>
> I have created a new table.
>
> create table payer_835 (
>     payer_id         int8 not null default
> nextval('payer_835_payer_id_seq'::regclass) primary key,
>     payer_name        varchar(50) not null,
>     payer_trn03        varchar(10) not null,
>     payer_trn04        varchar(30),
>     sku_id            int8 references skucode(sku_id) on delete cascade on
> update cascade,
>     payer_billable        boolean not null default true,
>     create_timestamp    timestamp not null default now(),
>     last_mod_timestamp    timestamp,
>     expire_timestamp    timestamp
> );
>
> On this table, I have created a unique index on payer_trn03, payer_trn04,
> and expire_timestamp.  However, since the expire_timestamp is normally null,
> the unique index does not appear to be working.  I have been able to enter
> two identical rows into this table.

Two nulls are considered distinct for purposes of unique indexes and
constraints.

The unique constraint is defined effective as a search condition of
                 UNIQUE ( SELECT UCL FROM TN )
(with UCL being the column list in the constraint).

The definition from the UNIQUE predicate says (from sql92):
"If there are no two rows in T such that the value of each column in one
row is non-null as is equal to the value of the corresponding column in
the other row according to Subclause 8.2, "<comparison predicate>", then
the result of the <unique predicate> is true; otherwise, the result of the
<unique predicate> is false."

So, given something like
 1, 2, NULL
 1, 2, NULL
the unique predicate is true and the data is allowed by the constraint.



view thread (10+ messages)  latest in thread

Message-ID: <20060713085157.H49004@megazone.bigpanda.com>
Permalink:  ../20060713085157.H49004@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20060713085157.H49004@megazone.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: sszabo@megazone.bigpanda.com, revoohc@gmail.com
  Subject: Re: 8.1 Unique Index Issue/Bug???
  In-Reply-To: <20060713085157.H49004@megazone.bigpanda.com>
  References: <1d219a6f0607130740g7fe13967t48c77a64fde977aa@mail.gmail.com> <20060713085157.H49004@megazone.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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