Re: Currval function won't work

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Currval function won't work
Дата
Msg-id 20051007075639.GA59072@winnie.fuhr.org
обсуждение исходный текст
Ответ на Currval function won't work  ("Bluebottle" <luckychap@bluebottle.com>)
Список pgsql-novice
On Fri, Oct 07, 2005 at 04:54:13PM -0700, Bluebottle wrote:
> select currval('library.items_itemid_seq') as NextItemID;
> ERROR:  currval of sequence "items_itemid_seq" is not yet defined in
> this session

currval() returns the value most recently obtained from nextval()
in the current session.  If you haven't called nextval() yet then
you get the error above.  Example:

test=> CREATE SEQUENCE foo_seq;
CREATE SEQUENCE
test=> SELECT currval('foo_seq');
ERROR:  currval of sequence "foo_seq" is not yet defined in this session
test=> SELECT nextval('foo_seq');
 nextval
---------
       1
(1 row)

test=> SELECT currval('foo_seq');
 currval
---------
       1
(1 row)

> Note that the nextval function works as expected
>
> select nextval('library.items_itemid_seq') as NextItemID;
> 2313

You should be able to call currval() after calling nextval().  If
not then please tell us a little more about your environment, such
as whether you're using a connection pool.

--
Michael Fuhr

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

Предыдущее
От: "Bluebottle"
Дата:
Сообщение: Currval function won't work
Следующее
От: "Tjibbe"
Дата:
Сообщение: TEMPORARY TABLE in a PL/pgSQL function