pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: FOR integer loop bug?
Date: Fri, 8 Apr 2022 12:27:43 -0700
Message-ID: <efd5f71b-93f4-3d49-7a6d-43a6cf509659@aklaver.com> (raw)
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>

On 4/8/22 11:23, Ron wrote:
> On 4/8/22 13:07, Adrian Klaver wrote:

>> Hmm, I'm going to have to think on this.
> 
> The only thinking is: "That's a bug waiting to happen!"
> 

That was my first inclination.

 From here:

https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL-CONTROL-STRUCTURES-L...

FOR name IN [ REVERSE ] expression .. expression [ BY expression ] LOOP


So:

CREATE OR REPLACE FUNCTION for_loop_test()
  RETURNS void
  LANGUAGE plpgsql
AS $function$
BEGIN
     FOR i IN   1..(2/3.0) LOOP
         RAISE NOTICE '%', i;
     END LOOP;
END;


select for_loop_test();
NOTICE:  1
  for_loop_test
---------------


Because:

select (2/3.0)::int;
  int4
------
     1

I find the result from this 1...10 surprising, however I have to believe 
there is code counting on the equivalent of (2/3.0) working.


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (5+ messages)

Message-ID: <efd5f71b-93f4-3d49-7a6d-43a6cf509659@aklaver.com>
Permalink:  ../efd5f71b-93f4-3d49-7a6d-43a6cf509659@aklaver.com/
Also on:    postgresql.org/message-id/efd5f71b-93f4-3d49-7a6d-43a6cf509659@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, ronljohnsonjr@gmail.com
  Subject: Re: FOR integer loop bug?
  In-Reply-To: <efd5f71b-93f4-3d49-7a6d-43a6cf509659@aklaver.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> <efd5f71b-93f4-3d49-7a6d-43a6cf509659@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