Re: ISOLATION LEVEL SERIALIZABLE - Mailing list pgsql-general

From Doug McNaught
Subject Re: ISOLATION LEVEL SERIALIZABLE
Date
Msg-id m3sn6nhzig.fsf@varsoon.wireboard.com
Whole thread Raw
In response to Re: ISOLATION LEVEL SERIALIZABLE  (Darren Ferguson <darren@crystalballinc.com>)
List 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 by date:

Previous
From: power2themacs
Date:
Subject: Re: ISOLATION LEVEL SERIALIZABLE
Next
From: Jan Wieck
Date:
Subject: Re: Altering a CHAR(4) column CHAR(5) changing pg_attribute