Re: A problem with sequences...

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Dmitry Tkach <dmitry(at)openratings(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: A problem with sequences...
Date: 2003-02-21 18:35:43
Message-ID: 20030221103441.H59965-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Doug McNaught 2003-02-21 18:37:29 Re: A problem with sequences...
Previous Message Stephan Szabo 2003-02-21 18:33:57 Re: Mutating table (urgent)