Insert failure on serial

Started by Warren Seltzerabout 20 years ago2 messagesbugs
Jump to latest
#1Warren Seltzer
warrens@actcom.net.il

PostgreSQL 8.1.3 on i686-pc-mingw32
Windows XP SP2

Summary of Insert failure (There IS NO DUPLICATE KEY):
depot_development=# INSERT INTO line_items ("order_id", "product_id", "quantity",
"unit_price") VALUES(1, 2, 2, 989.99);
ERROR: duplicate key violates unique constraint "line_items_pkey"

See attached file for more info. Bugreport.txt is psql narrative. Dumpdd.sql is the dump
of entire (tiny) database, without the offending insert.

Thanks in Advance

Warren Seltzer

Attachments:

bugreport.txttext/plain; name=bugreport.txtDownload
dumpdd.sqltext/plain; name=dumpdd.sqlDownload
#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Warren Seltzer (#1)
Re: Insert failure on serial

Warren Seltzer wrote:

PostgreSQL 8.1.3 on i686-pc-mingw32
Windows XP SP2

Summary of Insert failure (There IS NO DUPLICATE KEY):
depot_development=# INSERT INTO line_items ("order_id", "product_id", "quantity",
"unit_price") VALUES(1, 2, 2, 989.99);
ERROR: duplicate key violates unique constraint "line_items_pkey"

The problem is that the sequence attached to the "id" column is lower
than the values actually present in the column. Try doing
SELECT setval(pg_get_serial_sequence('line_items', 'id'), 16);

and see if it fixes your problem.

Now, how did the sequence got out of sync? Did you insert values to the
id column by hand?

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.