Re: Trouble EXITing plpgsql labeled BEGIN blocks with DECLAREs

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Trouble EXITing plpgsql labeled BEGIN blocks with DECLAREs
Date: 2004-09-14 00:51:40
Message-ID: 27933.1095123100@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Karl O. Pinc" <kop(at)meme(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Matthew T. O'Connor 2004-09-14 03:12:21 Corrupted Data?
Previous Message Mitch Pirtle 2004-09-14 00:41:00 Re: Opinions Requested - PG API or Abstraction Layer