CONTINUE error, even though inside a loop

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: CONTINUE error, even though inside a loop
Date: 2005-06-22 06:16:49
Message-ID: 20050622061648.GA98089@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 'after CONTINUE: 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 = 3
foo
-----
3
(1 row)

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Neil Conway 2005-06-22 07:29:21 Re: CONTINUE error, even though inside a loop
Previous Message Neil Conway 2005-06-22 05:31:41 Re: Schedule for 8.1 feature freeze