From: | Marcin Inkielman <marn(at)wsisiz(dot)edu(dot)pl> |
---|---|
To: | Chairudin Sentosa Harjo <chai(at)prima(dot)net(dot)id> |
Cc: | Vadim Mikheev <vadim(at)krs(dot)ru>, V Krishnaraj <kimi(at)intercept(dot)co(dot)in>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: [GENERAL] Postgres concurrency : urgent |
Date: | 1999-11-12 12:05:58 |
Message-ID: | Pine.LNX.4.04.9911121255350.26022-100000@mi.marnnet |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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?
************************************
From | Date | Subject | |
---|---|---|---|
Next Message | jose soares | 1999-11-12 14:17:09 | Re: [GENERAL] About Date field |
Previous Message | Andrzej Mazurkiewicz | 1999-11-12 10:06:33 | RE: [GENERAL] Types available |