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

Re: unique (a,b)?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Knut Suebert <knut(dot)suebert(at)web(dot)de>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: unique (a,b)?
Date: 2001-05-04 22:39:45
Message-ID: 1810.989015985@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-novice
Knut Suebert <knut(dot)suebert(at)web(dot)de> writes:
> I thought that a table-constraint unique (a,b) in a table like

> a | b
> --+--
> 1 | 1
> 2 | 2
> 3 | 3

> would allow an insert of (1,2) as it is an unique combination. That seems to be wrong.

It works fine for me:

regression=# create table ff (a int, b int, unique(a,b));
NOTICE:  CREATE TABLE/UNIQUE will create implicit index 'ff_a_key' for table 'ff'
CREATE
regression=# insert into ff values(1,1);
INSERT 1401043 1
regression=# insert into ff values(2,2);
INSERT 1401044 1
regression=# insert into ff values(3,3);
INSERT 1401045 1
regression=# insert into ff values(1,2);
INSERT 1401046 1
regression=# select * from ff;
 a | b
---+---
 1 | 1
 2 | 2
 3 | 3
 1 | 2
(4 rows)
regression=# insert into ff values(1,2);
ERROR:  Cannot insert a duplicate key into unique index ff_a_key

If you're having a problem you'll need to be more specific.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Tom LaneDate: 2001-05-04 23:20:26
Subject: Re: Converting a proceedure from SOLID to Postgres
Previous:From: jason.servetarDate: 2001-05-04 22:05:58
Subject: default value not working?

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