On Fri, 2 Mar 2001, Tom Lane wrote:
> Quite a few people don't seem to understand how currval() and nextval()
> work.
>
> 1. nextval() advances the sequence object, generating a new value that
> will not be the same as any other nextval() call returns, in either
> this backend or any other one.
>
> 2. currval() gives the last value generated by a nextval() *IN THIS
> BACKEND*. It is undefined until the current backend has done at
> least one nextval() on the sequence object.
>
> There is no "multiuser risk" from either one: in particular, currval()
> will give you the value you last generated, regardless of what other
> backends may be doing.
How ironic... I got into an argument not too long ago with someone on the
Perl-DBI list who insisted that currval could not be reliably used in a
multi-user environment and I argued what you say above. I eventually
conceded the argument, but am glad to know that I was right all along.
But now I feel bad for passing on wrong information...
-- Brett
http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
"The chain which can be yanked is not the eternal chain."
-- G. Fitch