Re: Can I prevent a sequence from being updated when a transaction fail? - Mailing list pgsql-general

From Haroldo Stenger
Subject Re: Can I prevent a sequence from being updated when a transaction fail?
Date
Msg-id 393AEFA5.9CA8EDD6@adinet.com.uy
Whole thread Raw
In response to Can I prevent a sequence from being updated when a transaction fail?  (Thomas Holmgren <thm@cs.auc.dk>)
List pgsql-general
Thomas Holmgren wrote:
> How come sequences are not rolled back when a transaction is aborted, and
> can I do anything to prevent a failing statement from updating the
> involved sequence?

No. You can't. To achieve what you want, the sequence counter should be
locked. That would mean that parallel insertions in the same table from
other transactions, should wait for the first to end. And that is not
acceptable.

If you don care about it, i.e., either your aplication never inserts
parallelly in a table, or a second insert can wait for the first to end,
then use your own counter in an auxiliary table. This will do what you
asked.

Haroldo.

pgsql-general by date:

Previous
From: Thomas Holmgren
Date:
Subject: Can I prevent a sequence from being updated when a transaction fail?
Next
From: Lincoln Yeoh
Date:
Subject: Re: index problem