| From: | Michael Fuhr <mike(at)fuhr(dot)org> |
|---|---|
| To: | Bluebottle <luckychap(at)bluebottle(dot)com> |
| Cc: | pgsql-novice(at)postgresql(dot)org |
| Subject: | Re: Currval function won't work |
| Date: | 2005-10-07 07:56:39 |
| Message-ID: | 20051007075639.GA59072@winnie.fuhr.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tjibbe | 2005-10-07 11:11:02 | TEMPORARY TABLE in a PL/pgSQL function |
| Previous Message | Tom Lane | 2005-10-07 03:23:12 | Re: Order by and index |