Re: How to don't update sequence on rollback of a transaction - Mailing list pgsql-general

From Frank Lanitz
Subject Re: How to don't update sequence on rollback of a transaction
Date
Msg-id 501B843A.7080509@frank.uvena.de
Whole thread Raw
In response to Re: How to don't update sequence on rollback of a transaction  (Andrew Hastie <andrew@ahastie.net>)
Responses Re: How to don't update sequence on rollback of a transaction
List pgsql-general
Am 02.08.2012 17:15, schrieb Andrew Hastie:
> Hi Frank,
>
> I believe this is by design. See the bottom of the documentation on
> sequences where it states ;-
>
> "*Important:* To avoid blocking 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 might leave unused "holes" in the sequence of
> assigned values. |setval| operations are never rolled back, either."
>
> http://www.postgresql.org/docs/9.1/static/functions-sequence.html
>
> If you really want to reset the sequence, I think you would have to call
> SELECT SETVAL(.....) at the point you request the roll-back.

Yepp. Somehow I missed that part of documentation. I don't think setval
will do the trick I want to perform, but Craig's idea looks very well.

Thanks for feedback!

Cheers,
Frank


pgsql-general by date:

Previous
From: Frank Lanitz
Date:
Subject: Re: How to don't update sequence on rollback of a transaction
Next
From: Edson Richter
Date:
Subject: Re: Async replication: how to get an alert on failure