Re: Bug?

Поиск
Список
Период
Сортировка
От Doug McNaught
Тема Re: Bug?
Дата
Msg-id m33d3gcb1n.fsf@belphigor.mcnaught.org
обсуждение исходный текст
Ответ на Bug?  (Rasmus Resen Amossen <NOSPAM@hey.com>)
Ответы Re: Bug?  ("Andrew G. Hammond" <drew@xyzzy.dhs.org>)
Список pgsql-general
Rasmus Resen Amossen <NOSPAM@hey.com> writes:

> CREATE TABLE test (
>   id SERIAL NOT NULL,
>   val INT
> );
>
> The the following insertions creates an error:
> INSERT INTO test(id,val) VALUES (1,1);
> INSERT INTO test(val) VALUES (1);
>
> Error:
> Cannot insert a duplicate key into unique index test_id_key
>
> After that I can just reåeat the second line and insert without errors.
> Is this bug fixed in newer versions?

Not a bug.  The second insert of the two above increments the SERIAL
sequence for 'id', and the incremented value is the same as the one
you explicitly inserted earlier.  Since SERIAL columns have a unique
index on them, the insert fails.

When you repeat the second insert, the sequence is incremented again,
and this time it doesn't collide.

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
   --T. J. Jackson, 1863

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

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: Bug?
Следующее
От: Vivek Khera
Дата:
Сообщение: Re: Modifying check constraints