From: | Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Re: plpgsql's EXIT versus block and loop nesting |
Date: | 2009-05-01 15:07:50 |
Message-ID: | 49FB1046.9080504@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Tom Lane wrote:
> 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.
later in that paragraph:
EXIT can be used with all types of loops; it is not limited to use
with unconditional loops. *When used with a BEGIN block, EXIT passes
control to the next statement after the end of the block.*
Examples:
...
BEGIN
-- some computations
IF stocks > 100000 THEN
EXIT; -- causes exit from the BEGIN block
END IF;
END;
That quite clearly describes the current behavior.
I'm not opposed to changing that, though. I've bumped into the same
incompatibility with Oracle. Is it appropriate for 8.4 given that we're
in beta already?
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Heikki Linnakangas | 2009-05-01 15:10:11 | Re: windows shared memory error |
Previous Message | Andy Lester | 2009-05-01 14:17:12 | Re: GCC 4.4 compiler warnings |