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

From Tom Lane
Subject Re: going crazy with serial type
Date
Msg-id 5327.1012511478@sss.pgh.pa.us
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

currval is defined to return the value most recently returned by nextval
in the current session.  Thus, without a prior nextval, you get an error.
The reason for this is to make it useful in a situation where multiple
clients are concurrently obtaining values from the same sequence.

The 7.2 documentation set has been improved (or at least I'd like to
think so) over 7.1's description of sequence stuff.  You may find that
reading

http://developer.postgresql.org/docs/postgres/datatype.html#DATATYPE-SERIAL
http://developer.postgresql.org/docs/postgres/functions-sequence.html
http://developer.postgresql.org/docs/postgres/sql-createsequence.html

reduces your level of confusion.  (Or not, but at least we tried...)
Note that 7.1 does not have the int8-based sequences described there,
but other than that I believe all the info carries back to 7.1.

            regards, tom lane

pgsql-general by date:

Previous
From: Fran Fabrizio
Date:
Subject: Re: going crazy with serial type
Next
From: Andrew Sullivan
Date:
Subject: Re: Function to Pivot data