Re: serial increments on failed insert - Mailing list pgsql-general

From Michael Fuhr
Subject Re: serial increments on failed insert
Date
Msg-id 20050115015343.GA54856@winnie.fuhr.org
Whole thread Raw
In response to serial increments on failed insert  (David Kammer <djkammer@u.washington.edu>)
List pgsql-general
On Fri, Jan 14, 2005 at 04:57:19PM -0800, David Kammer wrote:

> Notice that even though the second insert failed, it still incremented
> the serial value.  This seems counter intuative to the way that serial
> should work.  Is this truly a bug, or is there a good work around?

See the "Sequence Manipulation Functions" section in the "Functions
and Operators" chapter of the documentation.  The page contains
the following note:

    Important:  To avoid blocking of concurrent transactions that obtain
    numbers from the same sequence, a nextval operation is never rolled
    back; that is, once a value has been fetched it is considered used,
    even if the transaction that did the nextval later aborts.  This
    means that aborted transactions may leave unused "holes" in the
    sequence of assigned values.  setval operations are never rolled
    back, either.

Sequences are for obtaining numbers guaranteed to be unique; other
assumptions about their behavior are probably unwarranted.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: Steve Atkins
Date:
Subject: Re: serial increments on failed insert
Next
From: Tatsuo Ishii
Date:
Subject: Re: pgpool