Re: Bug?

From: Doug McNaught <doug(at)wireboard(dot)com>
To: Rasmus Resen Amossen <NOSPAM(at)hey(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Bug?
Date: 2001-11-15 15:24:04
Message-ID: m33d3gcb1n.fsf@belphigor.mcnaught.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rasmus Resen Amossen <NOSPAM(at)hey(dot)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

In response to

  • Bug? at 2001-11-15 02:02:41 from Rasmus Resen Amossen

Responses

  • Re: Bug? at 2001-11-15 19:29:58 from Andrew G. Hammond

Browse pgsql-general by date

  From Date Subject
Next Message Vince Vielhaber 2001-11-15 15:35:04 Re: Postgres+Delphi
Previous Message Vivek Khera 2001-11-15 15:05:22 Re: Modifying check constraints