Re: problem fetching currval of sequence - Mailing list pgsql-sql

From Tom Lane
Subject Re: problem fetching currval of sequence
Date
Msg-id 20611.1028651144@sss.pgh.pa.us
Whole thread Raw
In response to Re: problem fetching currval of sequence  ("Josh Berkus" <josh@agliodbs.com>)
Responses Re: problem fetching currval of sequence  (Josh Berkus <josh@agliodbs.com>)
List pgsql-sql
"Josh Berkus" <josh@agliodbs.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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: problem fetching currval of sequence
Next
From: Cédric Dufour
Date:
Subject: Re: Random resultset retrieving -> performance bottleneck