Skip site navigation (1) Skip section navigation (2)

Re: Insert failure on serial

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Warren Seltzer <warrens(at)actcom(dot)net(dot)il>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Insert failure on serial
Date: 2006-05-05 15:07:47
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugs
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                      
The PostgreSQL Company - Command Prompt, Inc.

In response to

pgsql-bugs by date

Next:From: Robert LorDate: 2006-05-05 15:50:55
Subject: Re: [BUGS] BUG #2401: spinlocks not available on amd64
Previous:From: Bruce MomjianDate: 2006-05-05 12:22:59
Subject: Re: [BUGS] BUG #2401: spinlocks not available on amd64

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group