Re: going crazy with serial type

From: Fran Fabrizio <ffabrizio(at)mmrd(dot)com>
To: Cindy <ctmoore(at)uci(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: going crazy with serial type
Date: 2002-01-31 21:13:31
Message-ID: 3C59B37B.1050800@mmrd.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-01-31 21:17:44 Re: going crazy with serial type
Previous Message Tom Lane 2002-01-31 21:11:18 Re: going crazy with serial type