Skip site navigation (1) Skip section navigation (2)

Re: uniqueness not always correct

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Frank Cusack <fcusack(at)iconnet(dot)net>
Cc: pgsql-bugs(at)postgreSQL(dot)org
Subject: Re: uniqueness not always correct
Date: 2000-09-30 02:16:44
Message-ID: 200009300216.WAA01739@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-hackers
I can confirm this is fixed in the current source tree, to be released
as 7.1 in a few months:


test=> create table test (zone int4, net cidr, unique(zone, net));
NOTICE:  CREATE TABLE/UNIQUE will create implicit index 'test_zone_key'
for table 'test'
CREATE
test=> insert into test (zone, net) values (1, '1.2.3/24');
INSERT 19822 1
test=> insert into test (zone, net) values (1, '2.3.4/24');
INSERT 19823 1
test=> insert into test (zone, net) values (1, '1.2.3/24');
ERROR:  Cannot insert a duplicate key into unique index test_zone_key
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test=> insert into test (zone, net) values (1, '2.3.4/24');
ERROR:  Cannot insert a duplicate key into unique index test_zone_key
test=> 


> Solaris 2.6/sparc; postgres 6.5.1
> 
> dns=> create table test (zone int4, net cidr, unique(zone, net));
> NOTICE:  CREATE TABLE/UNIQUE will create implicit index 'test_zone_key' for table 'test'
> CREATE
> dns=> insert into test (zone, net) values (1, '1.2.3/24');
> INSERT 21750 1
> dns=> insert into test (zone, net) values (1, '2.3.4/24');
> INSERT 21751 1
> dns=> insert into test (zone, net) values (1, '1.2.3/24');
> INSERT 21752 1
> dns=> insert into test (zone, net) values (1, '2.3.4/24');
> ERROR:  Cannot insert a duplicate key into a unique index
> dns=> select * from test;
> zone|net     
> - ----+--------
>    1|1.2.3/24
>    1|2.3.4/24
>    1|1.2.3/24
> (3 rows)
> 
> 
> Once a unique error is reported, uniqueness seems to be maintained.
> Also, if you enter 4 values, then try a duplicate, it all works.
> 
> The threshold seems to be 3.
> 
> A select before the duplicate add also seems to fix it.
> 
> ~f
> 
> 
> 
> ************
> 
> 


-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

In response to

pgsql-hackers by date

Next:From: Bruce MomjianDate: 2000-09-30 02:18:01
Subject: I am back
Previous:From: Philip WarnerDate: 2000-09-30 01:24:42
Subject: Bug in constraings (from GENERAL)

pgsql-bugs by date

Next:From: Bruce MomjianDate: 2000-09-30 02:18:18
Subject: Re: uniqueness not always correct
Previous:From: Christof PetigDate: 2000-09-29 17:21:55
Subject: Re: how to copy data from excel spreadsheet to postgresql database

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group