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

From Stephan Szabo
Subject Re: problem fetching currval of sequence
Date
Msg-id 20020806084817.M83826-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Re: problem fetching currval of sequence  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-sql
On Tue, 6 Aug 2002, Josh Berkus wrote:

> Charles,
>
> > I have a script to load values into a table (gb) which contains a
> > SEQUENCE ('gb_id').  For each entry into TABLE gb I need the value of
> > 'gb_gb_id_seq' to update a relational table.   I am getting the
> > following error msg:
> >   ERROR: gb_gb_id_seq.currval is not yet defined in this session.
>
> Sometime in the upgrade process for 7.1.0 --> 7.2.1, the CURRVAL
> function changed so that it was rigorously session-specific.  I can see
> a number of good reasons for doing this, but 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.
>
> I'd love to hear Tom, Bruce, or Stephan's comments on the issue.  It is
> an annoyance, and it would be nice to know the reason for the decrease
> in functionality of CURRVAL.

Presumably because it was fairly useless the other way?  I must be missing
how it worked. I can't see what you could do with the value apart from
getting a value that was at one point the most recent value of the
sequence, but a random number up to its current value in its range would
do the same thing. ;)  It doesn't guarantee you that you can see a row
with that value (in the case of the default) - or even if such a row will
ever exist, it doesn't guarantee you that it's really the last row (since
nextval could be called after the value is gotten but before your query
results are returned.  If you're doing an insert in one session, closing
the session, and starting a new one wanting to know the insert value from
the previous one, I don't see how currval helps, it'll give you *a* most
recent value, but not necessarily yours (unless you only have one updating
session, in which case you don't really need a sequence since you don't
need the concurrency guarantees).



pgsql-sql by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: problem fetching currval of sequence
Next
From: Jean-Luc Lachance
Date:
Subject: Re: copy files to postgresql