Re: Using "exit" to bring "goto" functionality.

From: Bryn Llewellyn <bryn(at)yugabyte(dot)com>
To: Christophe Pettus <xof(at)thebuild(dot)com>
Cc: pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Using "exit" to bring "goto" functionality.
Date: 2023-07-10 20:26:01
Message-ID: 4D9707F8-63DD-4F5D-8E78-789E96B95457@yugabyte.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> xof(at)thebuild(dot)com wrote:
>
>> bryn(at)yugabyte(dot)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".

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2023-07-10 20:52:12 Re: Using "exit" to bring "goto" functionality.
Previous Message Johnathan Tiamoh 2023-07-10 20:20:29 Re: Need Help On Upgrade