Re: A problem with sequences...

From: Dmitry Tkach <dmitry(at)openratings(dot)com>
To: Doug McNaught <doug(at)mcnaught(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: A problem with sequences...
Date: 2003-02-21 20:47:19
Message-ID: 3E569057.6070907@openratings.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Doug McNaught wrote:

>Dmitry Tkach <dmitry(at)openratings(dot)com> writes:
>
>
>
>>select setval('answer_id_seq', id) from answer order by id desc limit 1;
>>
>>Now, for some reason this reports a correct value, but what actually
>>gets set is wrong!
>>
>>
>
>I'm guessing that 'setval' is getting called more than once here.
>Your 'LIMIT 1' controls how many rows are returned to the client, but
>the server is probably generating more rows internally. So this is
>just wrong, and
>
>
You are right ! That's it! It does get called twice.
There is even a nice comment in ExecLimit():

* NOTE: when scanning forwards, we must fetch one tuple beyond the
* COUNT limit before we can return NULL, else the subplan won't
* be properly positioned to start going backwards. Hence test
* here is for position > netlimit not position >= netlimit.

Whatever that means, that's what was causing my problems...

Thanks!

Dima

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andy Kriger 2003-02-21 20:48:45 regexp question
Previous Message Stephan Szabo 2003-02-21 20:46:39 Re: Mutating table (urgent)