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/