Re: [GENERAL] Postgres concurrency : urgent - Mailing list pgsql-general

From Marcin Inkielman
Subject Re: [GENERAL] Postgres concurrency : urgent
Date
Msg-id Pine.LNX.4.04.9911121255350.26022-100000@mi.marnnet
Whole thread Raw
In response to Re: [GENERAL] Postgres concurrency : urgent  (Chairudin Sentosa Harjo <chai@prima.net.id>)
List pgsql-general
On Fri, 12 Nov 1999, Chairudin Sentosa Harjo wrote:

> How do I lock a sequence?
> I must be able to rollback to previous sequence curr.value, if the
> transaction fails to work.
> I have been looking this for ages, it seems I haven't found the answer
> yet.
>

I use it like this:

BEGIN;
LOCK any_seq IN ACCESS EXCLUSIVE MODE;

SELECT any_seq.last_value+1...
INSERT into ... values(any_seq.last_value+1,....)
UPDATE ... set ...=any_seq.last_value+1...
...
SELECT nextval(any_seq);
END;

now I am sure that all SELECT, INSERT , ...
use exactly the same value of any_seq.last_value+1 and when any operation
fails my any_seq remains unchanged. I am also sure that only one
transaction that modify any_seq is running.


***********************************

    Marcin Inkielman

************************************
               .~.
               /V\
              // \\
             /(   )\
              ^`~'^

         powered by Linux
               ----

    sibi omino similis?
************************************


pgsql-general by date:

Previous
From: Bob Kline
Date:
Subject: Re: [GENERAL] troubles with datestyle
Next
From: Bruce Elrick
Date:
Subject: Composite Keys