From 20ab467d76d78271006818d2baf4c9c8658d1f38 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 14 Mar 2006 22:48:25 +0000 Subject: Improve parser so that we can show an error cursor position for errors during parse analysis, not only errors detected in the flex/bison stages. This is per my earlier proposal. This commit includes all the basic infrastructure, but locations are only tracked and reported for errors involving column references, function calls, and operators. More could be done later but this seems like a good set to start with. I've also moved the ReportSyntaxErrorPosition logic out of psql and into libpq, which should make it available to more people --- even within psql this is an improvement because warnings weren't handled by ReportSyntaxErrorPosition. --- src/backend/parser/parse_clause.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/backend/parser/parse_clause.c') diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index fdc2e41b3aa..4384a4eaab8 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.147 2006/03/05 21:34:34 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.148 2006/03/14 22:48:20 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -303,7 +303,9 @@ transformJoinUsingClause(ParseState *pstate, List *leftVars, List *rightVars) Node *rvar = (Node *) lfirst(rvars); A_Expr *e; - e = makeSimpleA_Expr(AEXPR_OP, "=", copyObject(lvar), copyObject(rvar)); + e = makeSimpleA_Expr(AEXPR_OP, "=", + copyObject(lvar), copyObject(rvar), + -1); if (result == NULL) result = (Node *) e; @@ -311,7 +313,7 @@ transformJoinUsingClause(ParseState *pstate, List *leftVars, List *rightVars) { A_Expr *a; - a = makeA_Expr(AEXPR_AND, NIL, result, (Node *) e); + a = makeA_Expr(AEXPR_AND, NIL, result, (Node *) e, -1); result = (Node *) a; } } @@ -1182,6 +1184,7 @@ findTargetlistEntry(ParseState *pstate, Node *node, List **tlist, int clause) list_length(((ColumnRef *) node)->fields) == 1) { char *name = strVal(linitial(((ColumnRef *) node)->fields)); + int location = ((ColumnRef *) node)->location; if (clause == GROUP_CLAUSE) { @@ -1201,7 +1204,7 @@ findTargetlistEntry(ParseState *pstate, Node *node, List **tlist, int clause) * breaks no cases that are legal per spec, and it seems a more * self-consistent behavior. */ - if (colNameToVar(pstate, name, true) != NULL) + if (colNameToVar(pstate, name, true, location) != NULL) name = NULL; } @@ -1225,7 +1228,8 @@ findTargetlistEntry(ParseState *pstate, Node *node, List **tlist, int clause) * construct, eg ORDER BY */ errmsg("%s \"%s\" is ambiguous", - clauseText[clause], name))); + clauseText[clause], name), + parser_errposition(pstate, location))); } else target_result = tle; -- cgit v1.2.3