From 54124240ae4fc97cd86302df600acf59cab9f982 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Sat, 17 Aug 2002 13:06:50 +0000
Subject: [PATCH] In that case, attached is a patch which locates the beginning
 of the offending token more efficiently (per your suggestion of using
 scanbuf). The new patch does the same as before:

template1=# select * frum pg_class;
ERROR:  parser: parse error at or near "frum" at character 10

It also implement's Tom's suggestion:

template1=# select * from pg_class where\g
ERROR:  parse: parse error at end of input

Gavin Sherry
---
 src/backend/parser/scan.l | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index c8e13c382e5..51e1aa4be8e 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.98 2002/08/04 06:36:18 thomas Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.99 2002/08/17 13:06:50 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -582,8 +582,12 @@ other			.
 void
 yyerror(const char *message)
 {
-	elog(ERROR, "parser: %s at or near \"%s\"", message,
-		 token_start ? token_start : yytext);
+      if(yyleng == 1 && *yytext == YY_END_OF_BUFFER_CHAR)
+              elog(ERROR, "parser: %s at end of input",message);
+      else
+              elog(ERROR, "parser: %s at or near \"%s\" at character %i",
+                      message,token_start ? token_start : yytext,
+                      (unsigned int)(yytext - scanbuf + 1));
 }
 
 
-- 
GitLab