xof@thebuild.com wrote:
bryn@yugabyte.com wrote:
What is the rationale for supporting what seems to be on its face this strange functionality?
It allows you to EXIT or CONTINUE a loop that is not the innermost one, by naming the label of an outer loop. One can debate endlessly whether it's good or bad to include that functionality, but it definitely has use cases. I would assume that at this point, it's not going anywhere. The relevant documentation is here:
https://www.postgresql.org/docs/15/plpgsql-control-structures.html#PLPGSQL-CONTROL-STRUCTURES-LOOPS
Sorry, I should’ve said that I’d read this:
« When used with a BEGIN block, EXIT passes control to the next statement after the end of the block. Note that a label must be used for this purpose; an unlabeled EXIT is never considered to match a BEGIN block. (This is a change from pre-8.4 releases of PostgreSQL, which would allow an unlabeled EXIT to match a BEGIN block.) »
Yes, I see that the doc implies that the functionality that I asked about (premature exit from a block statement) will be supported indefinitely.
I can only assume that somebody implemented this back in the day and that nobody thought to say that it was a bad idea.
FYI, I tied both “exit” and “continue” outside of a loop in PL/SQL (using a fairly recent version of Oracle Database). There, each of these causes "must appear inside a loop" or "label 'B1' must label a LOOP statement".