Cindy wrote:
>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
>search_info=# select id from state_vectors;
> id
>----
> 1
>(1 row)
>
>
>shouldn't the first select have returned 1? The state_vectors_id_seq
>
Nope. currval() is per session, so if you haven't called nextval()
during the current connection, you'll see exactly what you saw.
test=# create sequence testseq;
CREATE
test=# select currval('testseq');
ERROR: testseq.currval is not yet defined in this session
test=# select nextval('testseq');
nextval
---------
1
(1 row)
test=# select currval('testseq');
currval
---------
1
(1 row)
test=# \q
$ psql test
Welcome to psql, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
test=# select currval('testseq');
ERROR: testseq.currval is not yet defined in this session
test=#
-Fran