Skip site navigation (1) Skip section navigation (2)

Re: ISOLATION LEVEL SERIALIZABLE

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(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 20:09:41
Message-ID: 20020326120824.Y13230-100000@megazone23.bigpanda.com (view raw or flat)
Thread:
Lists: pgsql-general
On Tue, 26 Mar 2002, power2themacs wrote:

> >In table two you would not create a serial instead you would create an
> >INTEGER because serial is a counter and the values in table 2 may not be
> >in table 1.
> >
> >Use a transaction like as follows
> >
> >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. Right now, I'm doing exactly that but I

That will only happen if another insert occurs *in your session*.

Currval is defined to give the last value from your session, so whatever
happens in other sessions will not affect the value returned from currval.



In response to

pgsql-general by date

Next:From: Jason EarlDate: 2002-03-26 20:13:01
Subject: Re: ISOLATION LEVEL SERIALIZABLE
Previous:From: Fernando SchapachnikDate: 2002-03-26 20:06:26
Subject: Re: ISOLATION LEVEL SERIALIZABLE

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group