Re: unique (a,b)? - Mailing list pgsql-novice

From Tom Lane
Subject Re: unique (a,b)?
Date
Msg-id 1810.989015985@sss.pgh.pa.us
Whole thread Raw
In response to unique (a,b)?  (Knut Suebert <knut.suebert@web.de>)
List pgsql-novice
Knut Suebert <knut.suebert@web.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

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Converting a proceedure from SOLID to Postgres
Next
From: Andrew McMillan
Date:
Subject: Re: Re: psql with PHP question