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