Re: Cannot insert a duplicate key into unique index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: kynn(at)panix(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Cannot insert a duplicate key into unique index
Date: 2004-02-19 05:10:39
Message-ID: 28971.1077167439@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

<kynn(at)panix(dot)com> writes:
> The insert statement that is producing this error does not
> include a value for the pkey field in question (this field is of type
> SERIAL). I imagine that somehow the counter associated with this
> field got messed up, so that it is mistakenly generating a value that
> has been used already. How can I straighten it out?

You need to do something like

select setval('seq-name', (select max(col) + 1 from table));

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message daq 2004-02-19 07:01:04 Re: Cannot insert a duplicate key into unique index
Previous Message Noel 2004-02-19 04:18:45 Re: Cannot insert a duplicate key into unique index