From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: FOR integer loop bug?
Date: Fri, 8 Apr 2022 13:23:06 -0500
Message-ID: <373613a6-7e62-1b03-0010-c0ae55541fd8@gmail.com> (raw)
In-Reply-To: <e06ecb67-8b02-68c6-e5d3-0a99b61e6a24@aklaver.com>
References: <c276938c-50f7-99db-926f-74dbddd83d27@aklaver.com>
<CAFj8pRB9W7q_tW9LqoxZERS7286bdLw4uLSnCd2ww_Ph9SgECw@mail.gmail.com>
<e06ecb67-8b02-68c6-e5d3-0a99b61e6a24@aklaver.com>
On 4/8/22 13:07, Adrian Klaver wrote:
> On 4/8/22 10:58 AM, Pavel Stehule wrote:
>>
>>
>> pá 8. 4. 2022 v 19:56 odesílatel Adrian Klaver <a
>>
>> Why is the three period form allowed through and why does it produce no
>> result?
>>
>>
>> Maybe
>>
>> (2022-04-08 19:57:57) postgres=# select .10;
>> ┌──────────┐
>> │ ?column? │
>> ╞══════════╡
>> │ 0.10 │
>> └──────────┘
>> (1 row)
>
> Alright so 1...10 is taken as 1::integer .. 0.10::integer CAST results in
> 0 and ends up as 1..0. This then is covered by:
>
> "If the lower bound is greater than the upper bound (or less than, in the
> REVERSE case), the loop body is not executed at all. No error is raised."
>
> Confirmed by:
>
> CREATE OR REPLACE FUNCTION utility.for_loop_test()
> RETURNS void
> LANGUAGE plpgsql
> AS $function$
> BEGIN
> FOR i IN REVERSE 1...10 LOOP
> RAISE NOTICE '%', i;
> END LOOP;
> END;
>
> $function$
> ;
>
> select for_loop_test();
> NOTICE: 1
> NOTICE: 0
> for_loop_test
> ---------------
>
> Hmm, I'm going to have to think on this.
The only thinking is: "That's a bug waiting to happen!"
--
Angular momentum makes the world go 'round.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: ronljohnsonjr@gmail.com
Subject: Re: FOR integer loop bug?
In-Reply-To: <373613a6-7e62-1b03-0010-c0ae55541fd8@gmail.com>
References: <c276938c-50f7-99db-926f-74dbddd83d27@aklaver.com> <CAFj8pRB9W7q_tW9LqoxZERS7286bdLw4uLSnCd2ww_Ph9SgECw@mail.gmail.com> <e06ecb67-8b02-68c6-e5d3-0a99b61e6a24@aklaver.com> <373613a6-7e62-1b03-0010-c0ae55541fd8@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox