Re: Last ID

Поиск
Список
Период
Сортировка
От Brett W. McCoy
Тема Re: Last ID
Дата
Msg-id Pine.LNX.4.30.0103021315290.22539-100000@chapelperilous.net
обсуждение исходный текст
Ответ на Re: Last ID  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-novice
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


В списке pgsql-novice по дате отправления:

Предыдущее
От: Catalin CIOCOIU
Дата:
Сообщение: Re: Last ID
Следующее
От: "Chuck Kimber"
Дата:
Сообщение: RE: Last ID