Re: ISOLATION LEVEL SERIALIZABLE

Поиск
Список
Период
Сортировка
От Doug McNaught
Тема Re: ISOLATION LEVEL SERIALIZABLE
Дата
Msg-id m3sn6nhzig.fsf@varsoon.wireboard.com
обсуждение исходный текст
Ответ на Re: ISOLATION LEVEL SERIALIZABLE  (Darren Ferguson <darren@crystalballinc.com>)
Список pgsql-general
power2themacs <power2themacs@yahoo.com> writes:

> >BEGIN;
> >INSERT INTO TABLE1 VALUES (Whatever values);
> >var = SELECT CURRVAL('sequence_name');
> >INSERT INTO TABLE2 VALUES (var,whatever else);
> >COMMIT;
> >
>
> But this is the race condition I am trying to avoid. Someone can
> insert before I get the currval and it will beincremented and this
> will result in invalid data.

Not true.  Sequences are handled specially to avoid this problem--you
don't even have to SET TRANSACTION ISOLATION.  'currval' will always
return the last value YOU saw, regardless of what other backends might
be doing.  See the docs for more details.

-Doug
--
Doug McNaught       Wireboard Industries      http://www.wireboard.com/

      Custom software development, systems and network consulting.
      Java PostgreSQL Enhydra Python Zope Perl Apache Linux BSD...

В списке pgsql-general по дате отправления:

Предыдущее
От: power2themacs
Дата:
Сообщение: Re: ISOLATION LEVEL SERIALIZABLE
Следующее
От: Jan Wieck
Дата:
Сообщение: Re: Altering a CHAR(4) column CHAR(5) changing pg_attribute