Re: Error message with plpgsql CONTINUE - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Error message with plpgsql CONTINUE
Date
Msg-id 20708.1439822905@sss.pgh.pa.us
Whole thread Raw
In response to Error message with plpgsql CONTINUE  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Responses Re: Error message with plpgsql CONTINUE
List pgsql-hackers
Jim Nasby <Jim.Nasby@BlueTreble.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



pgsql-hackers by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Raising our compiler requirements for 9.6
Next
From: Greg Stark
Date:
Subject: Re: Raising our compiler requirements for 9.6