Re: plpgsql's EXIT versus block and loop nesting - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: plpgsql's EXIT versus block and loop nesting
Date
Msg-id 162867790905010316n6eb4be94yfe408c5c3ff649d4@mail.gmail.com
Whole thread Raw
In response to plpgsql's EXIT versus block and loop nesting  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
2009/4/30 Tom Lane <tgl@sss.pgh.pa.us>:
> Whilst fooling with some plpgsql code translated from Oracle, I found
> out that we interpret this construct differently than they do:
>
>        while true loop
>            begin
>                -- some code that might throw unique_violation
>
>                exit;
>            exception when unique_violation then
>                -- take a recovery action (then go 'round the loop again)
>            end;
>        end loop;
>
> The code author obviously expects that the EXIT will exit the WHILE
> loop, so I assume that's what Oracle does with it.  What plpgsql is
> doing is matching the EXIT to the BEGIN block, which means this is
> an infinite loop.
>
> Aside from the question of Oracle compatibility, ISTM this behavior
> is at variance with what our manual says about EXIT:
>
>        If no label is given, the innermost loop is terminated and the
>        statement following END LOOP is executed next.
>
> I'm not sure we should change this in the back branches, but I propose
> that for 8.4, we fix it so that EXIT will only match to a begin-block
> if the block has a label and it matches the EXIT's.  Unlabeled EXITs
> should match to the innermost loop, like the manual says.  (This looks
> to be about a one-line code change.)

₊1

regards
Pavel Stehule

>
> Comments?
>
>                        regards, tom lane
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: windows shared memory error
Next
From: Dave Page
Date:
Subject: Re: windows shared memory error