Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 85E5219BA3A5 for ; Thu, 31 May 2012 02:25:43 -0300 (ADT) Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SZxtD-0002iq-5R for pgsql-bugs@postgresql.org; Thu, 31 May 2012 05:25:42 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SZxsz-0002oR-1r for pgsql-bugs@postgresql.org; Thu, 31 May 2012 05:25:26 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1SZxsy-0001GO-JW for pgsql-bugs@postgresql.org; Thu, 31 May 2012 05:25:24 +0000 Date: Thu, 31 May 2012 05:25:24 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6669: unique index w/ multiple columns and NULLs To: pgsql-bugs@postgresql.org From: jose.soares@sferacarta.com X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/242 X-Sequence-Number: 33213 The following bug has been logged on the website: Bug reference: 6669 Logged by: jose soares Email address: jose.soares@sferacarta.com PostgreSQL version: 8.4.8 Operating system: x86_64-pc-linux-gnu, debian Description: = Hi, I think I have found an error in pg or at least inconsistency, take a look at this. I created an unique index on two columns and pg let me enter repeated values as NULLs (unknown value), When I ask pg to tell me if there are repetitions n this index (with group by), the inconsistency becomes apparent. # create table test(id int, data date, code int); CREATE TABLE # create UNIQUE index unica on test(data,code); CREATE INDEX # \d test Table "public.test" Column | Type | Modifiers --------+---------+----------- id | integer | data | date | code | integer | Indexes: "unica" UNIQUE, btree (data, code) # insert into test values(1,current_date); INSERT 0 1 # insert into test values(2,current_date); INSERT 0 1 # insert into test values(3,current_date); INSERT 0 1 sicer_forli=3D# select current_date,code, count(*) from test group by 1,2; date | code | count ------------+------+------- 31-05-2012 | | 3 (1 row) ps: Oracle don't allows to insert two NULLs in such column. I don't know which of them is SQL Standard, but in this case oracle is not inconsistent.