From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(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:06:27 |
Message-ID: | 20020131125551.D16906-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 31 Jan 2002, 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
> is the sequence created by declaring id SERIAL in the table
> state_vectors, and I've done one INSERT INTO state_vectors VALUES
> (nextval('state_vectors_id_seq'), ... ); which worked fine and is
> where the 1 comes from. (I'm interested in finding out the value used
> for the most recent insert, and currval seemed like a pretty painless
> way of doing so.)
>
> (I'm basing this on 4.15.2 of the postgresql faq kindly supplied
> earlier.)
Well, as you've run into, it doesn't quite work like that. currval gives
you the most recently assigned number to your session, not the database as
a whole. What are you trying to do with the id once you get it?
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-01-31 21:11:18 | Re: going crazy with serial type |
Previous Message | Andrew Sullivan | 2002-01-31 21:05:24 | Re: Function to Pivot data |