Re: going crazy with serial type - Mailing list pgsql-general

From Doug McNaught
Subject Re: going crazy with serial type
Date
Msg-id m3bsfatfa3.fsf@varsoon.denali.to
Whole thread Raw
In response to Re: going crazy with serial type  (Cindy <ctmoore@uci.edu>)
List pgsql-general
Cindy <ctmoore@uci.edu> writes:

> OK, next question.  I'm trying to use nextval/currval and I'm getting
> this:
>
> search_info=# select currval('state_vectors_id_seq');
> ERROR:  state_vectors_id_seq.currval is not yet defined in this session

You need to do an explicit or implicit 'nextval' in a transaction
before 'currval' will work in that transaction.  So you can do:

BEGIN WORK;
INSERT INTO mytable (a, b) VALUES (1,2);
SELECT nextval('mytable_id_seq');
<do something with it>
COMMIT WORK;

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
   --T. J. Jackson, 1863

pgsql-general by date:

Previous
From: "Gregory Wood"
Date:
Subject: Re: going crazy with serial type
Next
From: Ellen Cyran
Date:
Subject: Re: Function to Pivot data