X-Original-To: pgsql-admin-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 808B09FA603 for ; Thu, 13 Jul 2006 13:09:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 14745-09 for ; Thu, 13 Jul 2006 13:09:39 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.169]) by postgresql.org (Postfix) with ESMTP id 94A619FA5FC for ; Thu, 13 Jul 2006 13:09:38 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id c2so349503ugf for ; Thu, 13 Jul 2006 09:09:37 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=uTGT6rj0wSa8aOH69cCOmOFmbIEbPmxLA/DrdgTTKSu3Qzz1T1tWkVAIRXxSifrQPYDQfohXZwQ1U0BF/aXXNyh2JrL1Zx8MJoqemwepEpD9IJciXfQvtGqtzZyORRRhBkapANw8ChsBgT1gZSTVhYNFV+E/YgBGVAud+iAnWoQ= Received: by 10.78.165.16 with SMTP id n16mr819012hue; Thu, 13 Jul 2006 09:09:37 -0700 (PDT) Received: by 10.78.29.15 with HTTP; Thu, 13 Jul 2006 09:09:37 -0700 (PDT) Message-ID: Date: Thu, 13 Jul 2006 11:09:37 -0500 From: "Aaron Bono" To: "Chris Hoover" Subject: Re: 8.1 Unique Index Issue/Bug??? Cc: "pgsql-admin@postgresql.org" In-Reply-To: <1d219a6f0607130740g7fe13967t48c77a64fde977aa@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_12070_25101327.1152806977398" References: <1d219a6f0607130740g7fe13967t48c77a64fde977aa@mail.gmail.com> X-Google-Sender-Auth: 5f86c982e7e5a016 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/91 X-Sequence-Number: 22337 ------=_Part_12070_25101327.1152806977398 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/13/06, 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. > > Why is PostgreSQL not enforcing this index? This appears to be a pretty > major a bug? It would seem that you could have a unique index across > columns that might have a null in them. > > Here is the data from the table: > > COPY payer_835 (payer_id, payer_name, payer_trn03, payer_trn04, sku_id, > payer_billable, create_timestamp, last_mod_timestamp, expire_timestamp) FROM > stdin; > 1 CAHABA GBA-AL PART B 1630103830 \N 1 t > 2006-07-13 09:57: 52.834631 \N \N > 2 FEP 123456789 00402 1 t 2006-07-10 > 10:56:23 \N \N > 3 NC Medicaid 123123123 \N 1 t 2006-07-10 > 10:56:41 \N \N > 4 CAHABA GBA-AL PART B 1630103830 \N 1 t > 2006-07-11 16:13:43.808181 2006-07-12 10:09:46.066204 \N > \. > > > Notice records 1 and 4 have identical data (as far as my unique index is > concerned), and the index it not complaining. > A null means no data so nulls are not considered on the unique constraints. That is the way it is supposed to work. There was discussion about this fact here: http://www.thescripts.com/forum/thread400192.html http://archives.postgresql.org/pgsql-bugs/2004-07/msg00099.php You are probably going to need to write a trigger if you want to enforce that NULL is unique for that field. ================================================================== Aaron Bono Aranya Software Technologies, Inc. http://www.aranya.com ================================================================== ------=_Part_12070_25101327.1152806977398 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/13/06, Chris Hoover <revoohc@gmail.com> 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.

Why is PostgreSQL not enforcing this index? This appears to be a pretty major a bug?  It would seem that you could have a unique index across columns that might have a null in them.

Here is the data from the table:

COPY payer_835 (payer_id, payer_name, payer_trn03, payer_trn04, sku_id, payer_billable, create_timestamp, last_mod_timestamp, expire_timestamp) FROM stdin;
1       CAHABA GBA-AL PART B    1630103830      \N      1       t       2006-07-13 09:57: 52.834631      \N      \N
2       FEP     123456789       00402   1       t       2006-07-10 10:56:23     \N      \N
3       NC Medicaid     123123123       \N      1       t       2006-07-10 10:56:41     \N      \N
4       CAHABA GBA-AL PART B    1630103830      \N      1       t       2006-07-11 16:13:43.808181      2006-07-12 10:09:46.066204      \N
\.


Notice records 1 and 4 have identical data (as far as my unique index is concerned), and the index it not complaining.

A null means no data so nulls are not considered on the unique constraints.  That is the way it is supposed to work.

There was discussion about this fact here:

http://www.thescripts.com/forum/thread400192.html
http://archives.postgresql.org/pgsql-bugs/2004-07/msg00099.php

You are probably going to need to write a trigger if you want to enforce that NULL is unique for that field.

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
================================================================== ------=_Part_12070_25101327.1152806977398--