Re: plpgsql FOR loop doesn't guard against strange step values - Mailing list pgsql-hackers

From Tom Lane
Subject Re: plpgsql FOR loop doesn't guard against strange step values
Date
Msg-id 22590.1184448228@sss.pgh.pa.us
Whole thread Raw
In response to Re: plpgsql FOR loop doesn't guard against strange step values  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: plpgsql FOR loop doesn't guard against strange step values  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> Tom Lane wrote:
>> I just noticed that when the BY option was added to plpgsql FOR
>> loops, no real error checking was done.  If you specify a zero step
>> value, you'll have an infinite loop.  If you specify a negative
>> value, the loop variable will increment in the "wrong direction"
>> until integer overflow occurs.  Neither of these behaviors seem
>> desirable in the least.

> That seems to be fairly normal proramming language behavior.

Well, it's about what I'd expect from C or something at a similar level
of (non) abstraction.  But I dislike the idea that plpgsql should have
behavior as machine-dependent as that the number of iterations will
depend on the value of INT_MIN.  Also, at the SQL level our usual policy
is to throw errors for obvious programmer mistakes, and it's hard to
argue that a zero or negative step isn't a programmer mistake.  Had we
defined the stepping behavior differently (ie, make "BY -1" work like
REVERSE) then there would be some sanity in allowing negative steps,
but I don't see the sanity in it given the implemented behavior.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: plpgsql and qualified variable names
Next
From: Heikki Linnakangas
Date:
Subject: Re: plpgsql and qualified variable names