pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: FOR integer loop bug?
Date: Fri, 8 Apr 2022 10:56:25 -0700
Message-ID: <c276938c-50f7-99db-926f-74dbddd83d27@aklaver.com> (raw)

Postgres 14.2

In commenting on a SO question I came across the below.

Given:

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

$function$
;

select for_loop_test();
NOTICE:  1
NOTICE:  2
NOTICE:  3
NOTICE:  4
NOTICE:  5
NOTICE:  6
NOTICE:  7
NOTICE:  8
NOTICE:  9
NOTICE:  10

Then, note 1...10:

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

$function$

select for_loop_test();
  for_loop_test
---------------

If you do:

FOR i IN 1....10 LOOP

or

FOR i IN 1.10 LOOP

You get:

ERROR:  syntax error at or near ".."
LINE 6:     FOR i IN 1....10 LOOP

ERROR:  syntax error at or near "1.10"
LINE 6:     FOR i IN 1.10 LOOP

respectively.

Why is the three period form allowed through and why does it produce no 
result?

-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (5+ messages)  latest in thread

Message-ID: <c276938c-50f7-99db-926f-74dbddd83d27@aklaver.com>
Permalink:  ../c276938c-50f7-99db-926f-74dbddd83d27@aklaver.com/
Also on:    postgresql.org/message-id/c276938c-50f7-99db-926f-74dbddd83d27@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
  Subject: Re: FOR integer loop bug?
  In-Reply-To: <c276938c-50f7-99db-926f-74dbddd83d27@aklaver.com>
  References: <c276938c-50f7-99db-926f-74dbddd83d27@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