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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-general by date

  From Date Subject
Next Message Jason Earl 2002-03-26 20:13:01 Re: ISOLATION LEVEL SERIALIZABLE
Previous Message Fernando Schapachnik 2002-03-26 20:06:26 Re: ISOLATION LEVEL SERIALIZABLE