Re: unique (a,b)?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: unique (a,b)?
Дата
Msg-id 1810.989015985@sss.pgh.pa.us
обсуждение исходный текст
Ответ на unique (a,b)?  (Knut Suebert <knut.suebert@web.de>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Converting a proceedure from SOLID to Postgres
Следующее
От: Andrew McMillan
Дата:
Сообщение: Re: Re: psql with PHP question