From: | Doug McNaught <doug(at)wireboard(dot)com> |
---|---|
To: | power2themacs <power2themacs(at)yahoo(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: ISOLATION LEVEL SERIALIZABLE |
Date: | 2002-03-26 19:58:47 |
Message-ID: | m3sn6nhzig.fsf@varsoon.wireboard.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
power2themacs <power2themacs(at)yahoo(dot)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...
From | Date | Subject | |
---|---|---|---|
Next Message | Fernando Schapachnik | 2002-03-26 20:06:26 | Re: ISOLATION LEVEL SERIALIZABLE |
Previous Message | power2themacs | 2002-03-26 19:42:39 | Re: ISOLATION LEVEL SERIALIZABLE |