Re: serial increments on failed insert

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: David Kammer <djkammer(at)u(dot)washington(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: serial increments on failed insert
Date: 2005-01-15 01:53:43
Message-ID: 20050115015343.GA54856@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tatsuo Ishii 2005-01-15 02:12:04 Re: pgpool
Previous Message Steve Atkins 2005-01-15 01:49:42 Re: serial increments on failed insert