Re: Issues with generate_series using integer boundaries

From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
To: Thom Brown <thom(at)linux(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Issues with generate_series using integer boundaries
Date: 2011-02-01 21:32:52
Message-ID: CB0F669D-83CB-4ADA-90D4-9D89B9AADF6D@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On 1 Feb 2011, at 21:26, Thom Brown wrote:

> 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.

That could actually be used as a feature to create a repeating series. A bit more control would be useful though :P

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.

!DSPAM:737,4d487c1211731974314558!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2011-02-01 21:44:51 Re: zero_damaged_pages doesn't work
Previous Message Tom Lane 2011-02-01 21:31:41 Re: cast problem in Postgresql 9.0.1

Browse pgsql-hackers by date

  From Date Subject
Next Message Nick Rudnick 2011-02-01 21:41:57 Re: [pgsql-general 2011-1-21:] Are there any projects interested in object functionality? (+ rule bases)
Previous Message Nick Rudnick 2011-02-01 21:27:47 Re: [pgsql-general 2011-1-21:] Are there any projects interested in object functionality? (+ rule bases)