Re: Transactions + sequences

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Neil Conway <nconway(at)klamath(dot)dyndns(dot)org>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Transactions + sequences
Date: 2000-09-22 18:52:44
Message-ID: Pine.BSF.4.10.10009221125490.67353-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Fri, 22 Sep 2000, Neil Conway wrote:

> Consider the following (PgSQL 7.0.2):
>
> CREATE SEQUENCE foo;
> SELECT nextval('foo');
> -- returns 1
> BEGIN WORK;
> SELECT nextval('foo');
> -- returns 2
> ABORT WORK;
> SELECT nextval('foo');
> -- returns 3
>
> As you can see, even though the transaction has been aborted, the
> sequence is still incremented. Is there any way to work around this?
> Are there any plans to change this behavior in the future?

Not really. There's a locking issue involved in rolling back a sequence.
In the current implementation if two backends want to call nextval, they
each get a value and don't have to worry about whether the other one will
rollback. If you wanted the one that called nextval second to not skip a
number if the other aborts, you'd have to wait until it has aborted or
committed to know what number to return.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John McKown 2000-09-22 19:36:34 Re: one more word about rules (fwd)
Previous Message Adam Haberlach 2000-09-22 17:51:57 Re: one more word about rules