Re: failed insert into serial-type row - Mailing list pgsql-admin

From Michael Fuhr
Subject Re: failed insert into serial-type row
Date
Msg-id 20050618135255.GA91505@winnie.fuhr.org
Whole thread Raw
In response to failed insert into serial-type row  ("Hortschitz, Stefan" <Stefan.Hortschitz@lfrz.at>)
List pgsql-admin
On Tue, Jun 14, 2005 at 07:28:22AM +0200, Hortschitz, Stefan wrote:
>
> sometimes if i'm adding new rows to the table with statements like
> this:
>
>       insert into (name,value) ('xy','xy');
>
> the database only returns an 'duplicate key on primary key', which
> should be prevented by the serial-datatype, or? how could it be, that
> two rows become the same id??

One possibility is that the table contains IDs that are higher than
the sequence value, so you occasionally get duplicates when you use
the sequence.  What are the results of the following queries?

SELECT max(id) FROM session.preferences;
SELECT * FROM session.preferences_id_seq;

If max(id) is higher than the sequence's last_value, then you can
adjust the sequence with setval() or ALTER SEQUENCE.  Then you
should to figure out how that happened so you can prevent it from
happening again.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-admin by date:

Previous
From: "Tomas Kratochvil"
Date:
Subject: pgAdmin II download
Next
From: "Greg Sabino Mullane"
Date:
Subject: Re: getting a sequence to update properly