Skip to content

Commit a72dd7a

Browse files
committed
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.
1 parent f5c798e commit a72dd7a

File tree

2 files changed

+220
-139
lines changed

2 files changed

+220
-139
lines changed

doc/src/sgml/plpgsql.sgml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.38 2004/05/16 23:22:06 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.39 2004/07/04 02:48:52 tgl Exp $
33
-->
44

55
<chapter id="plpgsql">
@@ -1769,7 +1769,7 @@ END;
17691769

17701770
<para>
17711771
The <literal>FOR-IN-EXECUTE</> statement is another way to iterate over
1772-
records:
1772+
rows:
17731773
<synopsis>
17741774
<optional>&lt;&lt;<replaceable>label</replaceable>&gt;&gt;</optional>
17751775
FOR <replaceable>record_or_row</replaceable> IN EXECUTE <replaceable>text_expression</replaceable> LOOP
@@ -1788,13 +1788,12 @@ END LOOP;
17881788
<para>
17891789
The <application>PL/pgSQL</> parser presently distinguishes the
17901790
two kinds of <literal>FOR</> loops (integer or query result) by checking
1791-
whether the target variable mentioned just after <literal>FOR</> has been
1792-
declared as a record or row variable. If not, it's presumed to be
1793-
an integer <literal>FOR</> loop. This can cause rather nonintuitive error
1794-
messages when the true problem is, say, that one has
1795-
misspelled the variable name after the <literal>FOR</>. Typically
1796-
the complaint will be something like <literal>missing ".." at end of SQL
1797-
expression</>.
1791+
whether <literal>..</> appears outside any parentheses between
1792+
<literal>IN</> and <literal>LOOP</>. If <literal>..</> is not seen then
1793+
the loop is presumed to be a loop over rows. Mistyping the <literal>..</>
1794+
is thus likely to lead to a complaint along the lines of
1795+
<quote>loop variable of loop over rows must be a record or row</>,
1796+
rather than the simple syntax error one might expect to get.
17981797
</para>
17991798
</note>
18001799
</sect2>

0 commit comments

Comments
 (0)