From a72dd7a9e4ddf8a9bc3443b4d10d6fef767ad066 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 4 Jul 2004 02:49:04 +0000 Subject: 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. --- doc/src/sgml/plpgsql.sgml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index b8eadd04552..952351170cc 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -1,5 +1,5 @@ @@ -1769,7 +1769,7 @@ END; The FOR-IN-EXECUTE statement is another way to iterate over - records: + rows: <<label>> FOR record_or_row IN EXECUTE text_expression LOOP @@ -1788,13 +1788,12 @@ END LOOP; The PL/pgSQL parser presently distinguishes the two kinds of FOR loops (integer or query result) by checking - whether the target variable mentioned just after FOR has been - declared as a record or row variable. If not, it's presumed to be - an integer FOR loop. This can cause rather nonintuitive error - messages when the true problem is, say, that one has - misspelled the variable name after the FOR. Typically - the complaint will be something like missing ".." at end of SQL - expression. + whether .. appears outside any parentheses between + IN and LOOP. If .. is not seen then + the loop is presumed to be a loop over rows. Mistyping the .. + is thus likely to lead to a complaint along the lines of + loop variable of loop over rows must be a record or row, + rather than the simple syntax error one might expect to get. -- cgit v1.2.3