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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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