Commit a72dd7a9 authored by Tom Lane's avatar Tom Lane

Okay, I've had it with answering newbie questions about why plpgsql

FOR loops are giving weird syntax errors.  Restructure parsing of FOR
loops so that the integer-loop-vs-query-loop decision is driven off
the presence of '..' between IN and LOOP, rather than the presence
of a matching record/row variable name.  Hopefully this will make the
behavior a bit more transparent.
parent f5c798ee
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.38 2004/05/16 23:22:06 neilc Exp $ $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.39 2004/07/04 02:48:52 tgl Exp $
--> -->
<chapter id="plpgsql"> <chapter id="plpgsql">
...@@ -1769,7 +1769,7 @@ END; ...@@ -1769,7 +1769,7 @@ END;
<para> <para>
The <literal>FOR-IN-EXECUTE</> statement is another way to iterate over The <literal>FOR-IN-EXECUTE</> statement is another way to iterate over
records: rows:
<synopsis> <synopsis>
<optional>&lt;&lt;<replaceable>label</replaceable>&gt;&gt;</optional> <optional>&lt;&lt;<replaceable>label</replaceable>&gt;&gt;</optional>
FOR <replaceable>record_or_row</replaceable> IN EXECUTE <replaceable>text_expression</replaceable> LOOP FOR <replaceable>record_or_row</replaceable> IN EXECUTE <replaceable>text_expression</replaceable> LOOP
...@@ -1788,13 +1788,12 @@ END LOOP; ...@@ -1788,13 +1788,12 @@ END LOOP;
<para> <para>
The <application>PL/pgSQL</> parser presently distinguishes the The <application>PL/pgSQL</> parser presently distinguishes the
two kinds of <literal>FOR</> loops (integer or query result) by checking two kinds of <literal>FOR</> loops (integer or query result) by checking
whether the target variable mentioned just after <literal>FOR</> has been whether <literal>..</> appears outside any parentheses between
declared as a record or row variable. If not, it's presumed to be <literal>IN</> and <literal>LOOP</>. If <literal>..</> is not seen then
an integer <literal>FOR</> loop. This can cause rather nonintuitive error the loop is presumed to be a loop over rows. Mistyping the <literal>..</>
messages when the true problem is, say, that one has is thus likely to lead to a complaint along the lines of
misspelled the variable name after the <literal>FOR</>. Typically <quote>loop variable of loop over rows must be a record or row</>,
the complaint will be something like <literal>missing ".." at end of SQL rather than the simple syntax error one might expect to get.
expression</>.
</para> </para>
</note> </note>
</sect2> </sect2>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment