CONTINUE error, even though inside a loop - Mailing list pgsql-hackers

From Michael Fuhr
Subject CONTINUE error, even though inside a loop
Date
Msg-id 20050622061648.GA98089@winnie.fuhr.org
Whole thread Raw
Responses Re: CONTINUE error, even though inside a loop
List pgsql-hackers
I'm getting "CONTINUE cannot be used outside a loop" errors even
though it's inside a loop.  The error appears to be happening when
CONTINUE passes control to the beginning of the loop but there's
no more iterating to be done.  I'd expect the loop to end at this
point instead of getting an error.  Or did I miss something in the
discussion?

CREATE FUNCTION foo(x integer) RETURNS integer AS $$
DECLARE   i  integer;
BEGIN   FOR i IN 1 .. x LOOP       RAISE INFO 'before CONTINUE: i = %', i;       CONTINUE WHEN i <= 2;       RAISE INFO
'afterCONTINUE: i = %', i;   END LOOP;
 
   RETURN x;
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;

SELECT foo(1);
INFO:  before CONTINUE: i = 1
ERROR:  CONTINUE cannot be used outside a loop
CONTEXT:  PL/pgSQL function "foo"

SELECT foo(2);
INFO:  before CONTINUE: i = 1
INFO:  before CONTINUE: i = 2
ERROR:  CONTINUE cannot be used outside a loop
CONTEXT:  PL/pgSQL function "foo"

SELECT foo(3);
INFO:  before CONTINUE: i = 1
INFO:  before CONTINUE: i = 2
INFO:  before CONTINUE: i = 3
INFO:  after CONTINUE: i = 3foo 
-----  3
(1 row)

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


pgsql-hackers by date:

Previous
From: Neil Conway
Date:
Subject: Re: Schedule for 8.1 feature freeze
Next
From: Neil Conway
Date:
Subject: Re: CONTINUE error, even though inside a loop