From e5fe2e84d75f7025cba10a0477335e25d3e83e07 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri, 9 Nov 2007 23:58:32 +0000
Subject: [PATCH] Recognize RETURN QUERY via a textual test, so that QUERY
 doesn't need to be a plpgsql keyword.  This avoids springing a new reserved
 word on plpgsql programmers. For consistency, handle RETURN NEXT the same
 way.

---
 src/pl/plpgsql/src/gram.y | 16 +++++++++++-----
 src/pl/plpgsql/src/scan.l |  4 +---
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/pl/plpgsql/src/gram.y b/src/pl/plpgsql/src/gram.y
index b0bc0ea304c..ffb16bea1c0 100644
--- a/src/pl/plpgsql/src/gram.y
+++ b/src/pl/plpgsql/src/gram.y
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.105 2007/07/25 04:19:08 neilc Exp $
+ *	  $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.106 2007/11/09 23:58:32 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -181,14 +181,12 @@ static	void			 check_labels(const char *start_label,
 %token	K_LOG
 %token	K_LOOP
 %token	K_MOVE
-%token	K_NEXT
 %token	K_NOSCROLL
 %token	K_NOT
 %token	K_NOTICE
 %token	K_NULL
 %token	K_OPEN
 %token	K_OR
-%token	K_QUERY
 %token	K_PERFORM
 %token	K_ROW_COUNT
 %token	K_RAISE
@@ -1169,11 +1167,19 @@ stmt_return		: K_RETURN lno
 						int	tok;
 
 						tok = yylex();
-						if (tok == K_NEXT)
+						if (tok == 0)
+							yyerror("unexpected end of function definition");
+
+						/*
+						 * To avoid making NEXT and QUERY effectively be
+						 * reserved words within plpgsql, recognize them
+						 * via yytext.
+						 */
+						if (pg_strcasecmp(yytext, "next") == 0)
 						{
 							$$ = make_return_next_stmt($2);
 						}
-						else if (tok == K_QUERY)
+						else if (pg_strcasecmp(yytext, "query") == 0)
 						{
 							$$ = make_return_query_stmt($2);
 						}
diff --git a/src/pl/plpgsql/src/scan.l b/src/pl/plpgsql/src/scan.l
index b322a4045e6..3c52f117d7f 100644
--- a/src/pl/plpgsql/src/scan.l
+++ b/src/pl/plpgsql/src/scan.l
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/pl/plpgsql/src/scan.l,v 1.58 2007/07/25 04:19:09 neilc Exp $
+ *	  $PostgreSQL: pgsql/src/pl/plpgsql/src/scan.l,v 1.59 2007/11/09 23:58:32 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -143,7 +143,6 @@ is				{ return K_IS;				}
 log				{ return K_LOG;				}
 loop			{ return K_LOOP;			}
 move			{ return K_MOVE;			}
-next			{ return K_NEXT;			}
 no{space}+scroll { return K_NOSCROLL;		}
 not				{ return K_NOT;				}
 notice			{ return K_NOTICE;			}
@@ -151,7 +150,6 @@ null			{ return K_NULL;			}
 open			{ return K_OPEN;			}
 or				{ return K_OR;				}
 perform			{ return K_PERFORM;			}
-query			{ return K_QUERY;			}
 raise			{ return K_RAISE;			}
 rename			{ return K_RENAME;			}
 result_oid		{ return K_RESULT_OID;		}
-- 
GitLab