Re: Trouble EXITing plpgsql labeled BEGIN blocks with DECLAREs - Mailing list pgsql-general

From Tom Lane
Subject Re: Trouble EXITing plpgsql labeled BEGIN blocks with DECLAREs
Date
Msg-id 27933.1095123100@sss.pgh.pa.us
Whole thread Raw
In response to Trouble EXITing plpgsql labeled BEGIN blocks with DECLAREs  ("Karl O. Pinc" <kop@meme.com>)
List pgsql-general
"Karl O. Pinc" <kop@meme.com> writes:
> begintest4() moves the declariation from the outermost BEGIN block
> to the inner BEGIN block, the one that's EXITed.  It fails with:

> WARNING:  plpgsql: ERROR during compile of begintest4 near line 9
> ERROR:  syntax error at or near "some_label"

You're misreading the syntax.  A <<label>> applies to a whole block
including any declarations.  So instead of

>    BEGIN
>      DECLARE
>        var INT;
>      <<some_label>>
>      BEGIN
>        var := 5;
>        EXIT some_label;
>        var := 0;
>      END;
>      RETURN NULL;
>    END;

write

>    BEGIN
>      <<some_label>>
>      DECLARE
>        var INT;
>      BEGIN
>        var := 5;
>        EXIT some_label;
>        var := 0;
>      END;
>      RETURN NULL;
>    END;

See the definition of "block" at the very top of
http://developer.postgresql.org/docs/postgres/plpgsql-structure.html
...

            regards, tom lane

pgsql-general by date:

Previous
From: "Karl O. Pinc"
Date:
Subject: Trouble EXITing plpgsql labeled BEGIN blocks with DECLAREs
Next
From: "Matthew T. O'Connor"
Date:
Subject: Corrupted Data?