dbTalk Databases Forums  

Cannot insert a duplicate key into unique index

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Cannot insert a duplicate key into unique index in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
joseph speigle
 
Posts: n/a

Default Re: Cannot insert a duplicate key into unique index - 06-03-2004 , 10:40 PM






hi kj,

select nextval('shipments_ship_id_seq');
then add one to that, say it's now equal 1010 ...
SELECT setval('shipments_ship_id_seq', 1010);

source =

http://www.commandprompt.com/ppbook/...EQUENCEVAL UE

but, sometimes there are deeper problems, as you alluded to.


On Thu, Feb 19, 2004 at 03:18:45PM +1100, Noel wrote:
Quote:
Hi KJ,

For each SERIAL primary key, there is a sequence table for that table,
which is where the primary key is generated. You need to check to see
that the current counter in the sequence table is passed the MAX primary
key in your table.
eg:
TABLE A
id (pkey)

Will have a sequence table
A_id_seq

Hope that helps
Cheers
Noel

kynn (AT) panix (DOT) com wrote:

I'm trying to debug some problem in my database that is resulting in
an error of the form "Cannot insert a duplicate key into unique
index". 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?

Thanks!

kj
--
joe speigle
www.sirfsup.com

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.