Re: problem fetching currval of sequence

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Josh Berkus" <josh(at)agliodbs(dot)com>
Cc: Charles Hauser <chauser(at)duke(dot)edu>, pgsql-sql(at)postgresql(dot)org
Subject: Re: problem fetching currval of sequence
Date: 2002-08-06 16:25:44
Message-ID: 20611.1028651144@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Josh Berkus" <josh(at)agliodbs(dot)com> writes:
> Sometime in the upgrade process for 7.1.0 --> 7.2.1, the CURRVAL
> function changed so that it was rigorously session-specific.

Huh? AFAIR it's always worked the way it does now (and a quick review
of the CVS logs for sequence.c backs up my recollection).

> ... it has the unfortunate
> side effect that CURRVAL is virtually useless for querying the current
> value of the row you just inserted using a front-end that creates a new
> session for each command.

Such a front end would be too broken to consider using anyway: if you
cannot wrap several related commands into a transaction, you cannot use
a database the way it's intended to be used. The connection-pooling
front ends that I know about all give you dedicated use of a connection
for at least the length of a transaction block, so the secret to using
currval is "do it in the same transaction block as you call nextval in".

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Charles Hauser 2002-08-06 16:43:32 Re: problem fetching currval of sequence
Previous Message Jean-Luc Lachance 2002-08-06 16:20:03 Re: copy files to postgresql