Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc91bf01

Browse files
committed
Fix plpgsql's EXIT so that an EXIT without a label only matches a loop,
never a BEGIN block. This is required for Oracle compatibility and isalso plainly stated to be the behavior by our original documentation(up until 8.1, in which the docs were adjusted to match the code's behavior;but actually the old docs said the correct thing and the code was wrong).Not back-patched because this introduces an incompatibility that couldbreak working applications. Requires release note.
1 parentccc6759 commitc91bf01

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

‎doc/src/sgml/plpgsql.sgml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.140 2009/04/19 18:52:56 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.141 2009/05/02 17:27:57 tgl Exp $ -->
22

33
<chapter id="plpgsql">
44
<title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title>
@@ -1904,8 +1904,8 @@ END LOOP <optional> <replaceable>label</replaceable> </optional>;
19041904
indefinitely until terminated by an <literal>EXIT</> or
19051905
<command>RETURN</command> statement. The optional
19061906
<replaceable>label</replaceable> can be used by <literal>EXIT</>
1907-
and <literal>CONTINUE</literal> statementsin nested loops to
1908-
specify which loopthe statement should be applied to.
1907+
and <literal>CONTINUE</literal> statementswithin nested loops to
1908+
specify which loopthose statements refer to.
19091909
</para>
19101910
</sect3>
19111911

@@ -1939,9 +1939,19 @@ EXIT <optional> <replaceable>label</replaceable> </optional> <optional> WHEN <re
19391939

19401940
<para>
19411941
<literal>EXIT</> can be used with all types of loops; it is
1942-
not limited to use with unconditional loops. When used with a
1942+
not limited to use with unconditional loops.
1943+
</para>
1944+
1945+
<para>
1946+
When used with a
19431947
<literal>BEGIN</literal> block, <literal>EXIT</literal> passes
19441948
control to the next statement after the end of the block.
1949+
Note that a label must be used for this purpose; an unlabelled
1950+
<literal>EXIT</literal> is never considered to match a
1951+
<literal>BEGIN</literal> block. (This is a change from
1952+
pre-8.4 releases of <productname>PostgreSQL</productname>, which
1953+
would allow an unlabelled <literal>EXIT</literal> to match
1954+
a <literal>BEGIN</literal> block.)
19451955
</para>
19461956

19471957
<para>
@@ -1959,11 +1969,13 @@ LOOP
19591969
EXIT WHEN count &gt; 0; -- same result as previous example
19601970
END LOOP;
19611971

1972+
&lt;&lt;ablock&gt;&gt;
19621973
BEGIN
19631974
-- some computations
19641975
IF stocks &gt; 100000 THEN
1965-
EXIT; -- causes exit from the BEGIN block
1976+
EXIT ablock; -- causes exit from the BEGIN block
19661977
END IF;
1978+
-- computations here will be skipped when stocks &gt; 100000
19671979
END;
19681980
</programlisting>
19691981
</para>

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.240 2009/04/09 02:57:53 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.241 2009/05/02 17:27:57 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1145,11 +1145,15 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
11451145
returnrc;
11461146

11471147
casePLPGSQL_RC_EXIT:
1148+
/*
1149+
* This is intentionally different from the handling of RC_EXIT
1150+
* for loops: to match a block, we require a match by label.
1151+
*/
11481152
if (estate->exitlabel==NULL)
1149-
returnPLPGSQL_RC_OK;
1153+
returnPLPGSQL_RC_EXIT;
11501154
if (block->label==NULL)
11511155
returnPLPGSQL_RC_EXIT;
1152-
if (strcmp(block->label,estate->exitlabel))
1156+
if (strcmp(block->label,estate->exitlabel)!=0)
11531157
returnPLPGSQL_RC_EXIT;
11541158
estate->exitlabel=NULL;
11551159
returnPLPGSQL_RC_OK;
@@ -1604,7 +1608,7 @@ exec_stmt_while(PLpgSQL_execstate *estate, PLpgSQL_stmt_while *stmt)
16041608
returnPLPGSQL_RC_OK;
16051609
if (stmt->label==NULL)
16061610
returnPLPGSQL_RC_EXIT;
1607-
if (strcmp(stmt->label,estate->exitlabel))
1611+
if (strcmp(stmt->label,estate->exitlabel)!=0)
16081612
returnPLPGSQL_RC_EXIT;
16091613
estate->exitlabel=NULL;
16101614
returnPLPGSQL_RC_OK;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp