From: Michael Fuhr <mike@fuhr.org>
To: Hortschitz, Stefan <Stefan.Hortschitz@lfrz.at>
Cc: pgsql-admin@postgresql.org
Subject: Re: failed insert into serial-type row
Date: Sat, 18 Jun 2005 07:52:55 -0600
Message-ID: <20050618135255.GA91505@winnie.fuhr.org> (raw)
In-Reply-To: <D12153701D57FF45A1AD64DFB6571D7C79DCCF@svie0107.vie01.local>
References: <D12153701D57FF45A1AD64DFB6571D7C79DCCF@svie0107.vie01.local>
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/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: mike@fuhr.org, Stefan.Hortschitz@lfrz.at
Subject: Re: failed insert into serial-type row
In-Reply-To: <20050618135255.GA91505@winnie.fuhr.org>
References: <D12153701D57FF45A1AD64DFB6571D7C79DCCF@svie0107.vie01.local> <20050618135255.GA91505@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox