Re: Can I prevent a sequence from being updated when a transaction fail?

From: Haroldo Stenger <hstenger(at)adinet(dot)com(dot)uy>
To: Thomas Holmgren <thm(at)cs(dot)auc(dot)dk>, pgsql-general(at)hub(dot)org
Subject: Re: Can I prevent a sequence from being updated when a transaction fail?
Date: 2000-06-05 00:09:09
Message-ID: 393AEFA5.9CA8EDD6@adinet.com.uy
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lincoln Yeoh 2000-06-05 07:15:42 Re: index problem
Previous Message Thomas Holmgren 2000-06-04 22:02:47 Can I prevent a sequence from being updated when a transaction fail?