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