Search Postgresql Archives

Re: serial increments on failed insert

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux