Re: A problem with sequences... - Mailing list pgsql-general

From Stephan Szabo
Subject Re: A problem with sequences...
Date
Msg-id 20030221103441.H59965-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Re: A problem with sequences...  (Dmitry Tkach <dmitry@openratings.com>)
Responses Re: A problem with sequences...
List pgsql-general
On Fri, 21 Feb 2003, Dmitry Tkach wrote:

> rapidb=# select last_value from answer_id_seq;
>   last_value
> ------------
>        22124
> (1 row)
>
> rapidb=# select setval ('answer_id_seq', id) from answer order by id desc limit 1;
>   setval
> --------
>    25000
> (1 row)
>
> rapidb=# select currval('answer_id_seq');
>   currval
> ---------
>     21452
> (1 row)
>
> So, the question I have now is - what's going on?
> How come setval() reports 25000, but the currval changes to 21452
> If my query is wrong (and I can't really see what's wrong with it), then why does it report the correct value?

IIRC, currval returns the last value given by the sequence (in nextval) to
this session.  What does a select nextval('answer_id_seq') give you?
21453 or 25001?


pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Mutating table (urgent)
Next
From: Doug McNaught
Date:
Subject: Re: A problem with sequences...