Re: [GENERAL] Postgres concurrency : urgent
От | Marcin Inkielman |
---|---|
Тема | Re: [GENERAL] Postgres concurrency : urgent |
Дата | |
Msg-id | Pine.LNX.4.04.9911121255350.26022-100000@mi.marnnet обсуждение исходный текст |
Ответ на | Re: [GENERAL] Postgres concurrency : urgent (Chairudin Sentosa Harjo <chai@prima.net.id>) |
Список | 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 по дате отправления: