[ADMIN] unique constraints

Поиск
Список
Период
Сортировка
От Campbell, Lance
Тема [ADMIN] unique constraints
Дата
Msg-id B75CD08C73BD3543B97E4EF3964B7D70479DACB2@CITESMBX1.ad.uillinois.edu
обсуждение исходный текст
Ответы Re: [ADMIN] unique constraints  ("Ron Watkins" <rwatki@gmail.com>)
Re: [ADMIN] unique constraints  (Achilleas Mantzios <achill@matrix.gatewaynet.com>)
Список pgsql-admin

PostgreSQL 9.5

 

I have a table:

 

CREATE TABLE test

(

  id integer NOT NULL,

  tag_id integer,

  CONSTRAINT test_id_tag_id_key UNIQUE (id, tag_id)

)

WITH (

  OIDS=FALSE

);

 

I noticed I can insert this into the database:

 

Insert into test (id, tag_id) values(1,null);

Insert into test (id, tag_id) values(1,null);

 

But this does not work:

 

Insert into test (id, tag_id) values(2,1);

Insert into test (id, tag_id) values(2,1); (error occurs)

 

Select * from test;

 

1, null

1, null

2, 1

 

I understand why in the second set of inserts I get an error when trying to insert the same set of values.  But why does the first example work?  I would have thought that it would have only allowed the first insert to work.

 

Thanks,

 

Lance

 

В списке pgsql-admin по дате отправления:

Предыдущее
От: xu jian
Дата:
Сообщение: [ADMIN] 答复: [ADMIN] blocking issue when create index concurrently
Следующее
От: "Ron Watkins"
Дата:
Сообщение: Re: [ADMIN] unique constraints