Thread: breaking out of a loop in plpgsql

breaking out of a loop in plpgsql

From
"Celia McInnis"
Date:
How do I break out of a loop in plpgsql?

Thanks
Celia McInnis

Re: breaking out of a loop in plpgsql

From
Oliver Elphick
Date:
On Thu, 2005-06-09 at 12:35 -0500, Celia McInnis wrote:
> How do I break out of a loop in plpgsql?

From the plpgsql docs:

        EXIT [ label ] [ WHEN expression ];

        If no label is given, the innermost loop is terminated and the
        statement following END LOOP is executed next. If label is
        given, it must be the label of the current or some outer level
        of nested loop or block. Then the named loop or block is
        terminated and control continues with the statement after the
        loop's/block's corresponding END.

        If WHEN is present, loop exit occurs only if the specified
        condition is true, otherwise control passes to the statement
        after EXIT.

        EXIT can be used to cause early exit from all types of loops; it
        is not limited to use with unconditional loops.