pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: FOR integer loop bug?
Date: Fri, 8 Apr 2022 11:07:06 -0700
Message-ID: <e06ecb67-8b02-68c6-e5d3-0a99b61e6a24@aklaver.com> (raw)
In-Reply-To: <CAFj8pRB9W7q_tW9LqoxZERS7286bdLw4uLSnCd2ww_Ph9SgECw@mail.gmail.com>
References: <c276938c-50f7-99db-926f-74dbddd83d27@aklaver.com>
	<CAFj8pRB9W7q_tW9LqoxZERS7286bdLw4uLSnCd2ww_Ph9SgECw@mail.gmail.com>

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.

> 
> 
>     -- 
>     Adrian Klaver
>     adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (5+ messages)  latest in thread

Message-ID: <e06ecb67-8b02-68c6-e5d3-0a99b61e6a24@aklaver.com>
Permalink:  ../e06ecb67-8b02-68c6-e5d3-0a99b61e6a24@aklaver.com/
Also on:    postgresql.org/message-id/e06ecb67-8b02-68c6-e5d3-0a99b61e6a24@aklaver.com

 · 

reply

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: adrian.klaver@aklaver.com, pavel.stehule@gmail.com
  Subject: Re: FOR integer loop bug?
  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>

* 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