Skip site navigation (1) Skip section navigation (2)

Re: Issues with generate_series using integer boundaries

From: Thom Brown <thom(at)linux(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Issues with generate_series using integer boundaries
Date: 2011-02-01 20:26:34
Message-ID: AANLkTinwULWX_cChuFA-XkSBqL7zQJ1EpT132QQ-x6NL@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-hackers
On 1 February 2011 01:05, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Thom Brown <thom(at)linux(dot)com> writes:
>> I've noticed that if I try to use generate_series to include the upper
>> boundary of int4, it never returns:
>
> I'll bet it's testing "currval > bound" without considering the
> possibility that incrementing currval caused an overflow wraparound.
> We fixed a similar problem years ago in plpgsql FOR-loops...

Yes, you're right.  Internally, the current value is checked against
the finish.  If it hasn't yet passed it, the current value is
increased by the step.  When it reaches the upper bound, since it
hasn't yet exceeded the finish, it proceeds to increment it again,
resulting in the iterator wrapping past the upper bound to become the
lower bound.  This then keeps it looping from the lower bound upward,
so the current value stays well below the end.

-- 
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935

In response to

Responses

pgsql-hackers by date

Next:From: Christopher HotchkissDate: 2011-02-01 20:51:47
Subject: Re: Authentication Enhancement Proposal
Previous:From: Simon RiggsDate: 2011-02-01 20:25:35
Subject: Re: Error code for "terminating connection due to conflict with recovery"

pgsql-general by date

Next:From: Adrian KlaverDate: 2011-02-01 21:05:29
Subject: Re: Some Problems - Shall I reinstall the DB?
Previous:From: John R PierceDate: 2011-02-01 20:25:26
Subject: Re: yum repo problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group