Re: Error message with plpgsql CONTINUE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Error message with plpgsql CONTINUE
Date: 2015-08-17 14:48:25
Message-ID: 20708.1439822905@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> writes:
> Calling CONTINUE with a label that's not a loop produces an error
> message with no context info [1].

True.

> I think err_stmt should probably only be reset in the non-return case a
> bit below that. I'm not sure about err_text though.

That is not going to help, as you'd soon find if you experimented:
given your example, the produced error message would be

ERROR: CONTINUE cannot be used outside a loop
CONTEXT: PL/pgSQL function inline_code_block line 2 at statement block

rather than pointing at the CONTINUE. To get where you needed to be,
you'd need to have some complicated and fragile rules about where err_stmt
is reset or not reset as a statement nest gets unwound.

I'm inclined to think that if we wanted to make this better, the way to
improve it would be to detect the error *at compile time*, and get rid of
this hack in plpgsql_exec_function altogether. pl_gram.y already
successfully detects cases where CONTINUE mentions a label that doesn't
exist or isn't surrounding the CONTINUE. What it is missing is that we
don't distinguish labels on loops from labels on non-loop statements, and
thus it can't tell if CONTINUE is referencing a non-loop label or has no
label but is not inside any loop-type statement. Seems like that detail
could be added to the PLpgSQL_nsitem data structure without a huge amount
of work.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2015-08-17 14:51:33 Re: Raising our compiler requirements for 9.6
Previous Message Merlin Moncure 2015-08-17 14:33:20 Re: Raising our compiler requirements for 9.6