Re: Current value of a sequence?

Поиск
Список
Период
Сортировка
От missive@frontiernet.net (Lee Harr)
Тема Re: Current value of a sequence?
Дата
Msg-id 9femth$t8i$1@node21.cwnet.roc.gblx.net
обсуждение исходный текст
Ответ на Current value of a sequence?  (Adam Haberlach <adam@newsnipple.com>)
Список pgsql-general
On Sun, 3 Jun 2001 19:48:42 +0000 (UTC), Adam Haberlach <adam@newsnipple.com>:

> zipcode=# select currval('messages_pkey_seq');
> ERROR:  messages_pkey_seq.currval is not yet defined in this session
>
> ...however, if I select nextval() first, it works.  Is this
> lazy caching?  Is there a good way to find the current value of
> sequence without querying directly (and possibly breaking in
> future implementations?)


This is the way sequences are supposed to work.
currval is the current value of the sequence as seen
by the current session. That's why it is not defined
until you select nextval first.

Remember that a sequence is not guaranteed to not
have spaces...

If you want to find the last number from the sequence
which was inserted in to a table, you should select max()
on that column.


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

Предыдущее
От: "Sergey E. Volkov"
Дата:
Сообщение: Re: Pgsql vs Interbase: Transaction benchmark
Следующее
От: "Frank"
Дата:
Сообщение: about PostgreSQL...(important)