| From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> | 
|---|---|
| To: | "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> | 
| Subject: | FOR integer loop bug? | 
| Date: | 2022-04-08 17:56:25 | 
| Message-ID: | c276938c-50f7-99db-926f-74dbddd83d27@aklaver.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
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(dot)klaver(at)aklaver(dot)com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Pavel Stehule | 2022-04-08 17:58:46 | Re: FOR integer loop bug? | 
| Previous Message | W.P. | 2022-04-08 17:18:37 | Re: Problem with PG 11 database on OrangePi3 (ARMBIAN, ARM64) after disk disrupion (problem with USB disk connection) |