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

Re: duplicate key violates unique constraint

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Spiegelberg, Greg" <gspiegelberg(at)isodxsolutions(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: duplicate key violates unique constraint
Date: 2007-05-10 15:28:41
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-admin
"Spiegelberg, Greg" <gspiegelberg(at)isodxsolutions(dot)com> writes:
> As you can see, it's only providing the key1 column and the sequence is
> providing the value for the column with the constraint.  How can this be
> happening?

Perhaps at some point you manually inserted an id value past the
then-current sequence value?

> Now, I don't know if this just hasn't been tested or is a documented
> feature (a.k.a. bug) but something does not seem right here.  In this
> test case I'm able to get the same sequence ID's via two psql
> connections to the same database on the same sequence.

No, you've misunderstood currval().  That gives the value most recently
obtained by nextval() within your own session; it is not affected by any
subsequent manipulation of the sequence.

			regards, tom lane

In response to


pgsql-admin by date

Next:From: Mikko PartioDate: 2007-05-10 15:30:27
Subject: Re: duplicate key violates unique constraint
Previous:From: Peter KoczanDate: 2007-05-10 15:26:56
Subject: Re: upgrade 8.0.3 -> 8.2.4

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