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?
************************************