diff options
Diffstat (limited to 'src/backend/parser')
-rw-r--r-- | src/backend/parser/parse_expr.c | 17 | ||||
-rw-r--r-- | src/backend/parser/parse_relation.c | 109 | ||||
-rw-r--r-- | src/backend/parser/parse_target.c | 10 |
3 files changed, 34 insertions, 102 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 3fccba1ab5a..c6f3abe7caa 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.244 2009/10/08 02:39:23 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.245 2009/10/21 20:22:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -500,14 +500,13 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref) name2 = strVal(field2); /* Try to identify as a once-qualified column */ - node = qualifiedNameToVar(pstate, NULL, name1, name2, true, + node = qualifiedNameToVar(pstate, NULL, name1, name2, cref->location); if (node == NULL) { /* * Not known as a column of any range-table entry, so try - * it as a function call. Here, we will create an - * implicit RTE for tables not already entered. + * it as a function call. */ node = transformWholeRowRef(pstate, NULL, name1, cref->location); @@ -545,7 +544,7 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref) name3 = strVal(field3); /* Try to identify as a twice-qualified column */ - node = qualifiedNameToVar(pstate, name1, name2, name3, true, + node = qualifiedNameToVar(pstate, name1, name2, name3, cref->location); if (node == NULL) { @@ -600,7 +599,7 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref) name4 = strVal(field4); /* Try to identify as a twice-qualified column */ - node = qualifiedNameToVar(pstate, name2, name3, name4, true, + node = qualifiedNameToVar(pstate, name2, name3, name4, cref->location); if (node == NULL) { @@ -1906,14 +1905,14 @@ transformWholeRowRef(ParseState *pstate, char *schemaname, char *relname, int sublevels_up; Oid toid; - /* Look up the referenced RTE, creating it if needed */ + /* Look up the referenced RTE, failing if not present */ rte = refnameRangeTblEntry(pstate, schemaname, relname, location, &sublevels_up); if (rte == NULL) - rte = addImplicitRTE(pstate, - makeRangeVar(schemaname, relname, location)); + errorMissingRTE(pstate, + makeRangeVar(schemaname, relname, location)); vnum = RTERangeTablePosn(pstate, rte, &sublevels_up); diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index b0fb0b6ae03..4a0a50504bb 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.143 2009/07/16 06:33:43 petere Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.144 2009/10/21 20:22:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -32,9 +32,6 @@ #include "utils/syscache.h" -/* GUC parameter */ -bool add_missing_from; - static RangeTblEntry *scanNameSpaceForRefname(ParseState *pstate, const char *refname, int location); static RangeTblEntry *scanNameSpaceForRelid(ParseState *pstate, Oid relid, @@ -51,7 +48,6 @@ static void expandTupleDesc(TupleDesc tupdesc, Alias *eref, int location, bool include_dropped, List **colnames, List **colvars); static int specialAttNum(const char *attname); -static void warnAutoRange(ParseState *pstate, RangeVar *relation); /* @@ -249,7 +245,7 @@ isFutureCTE(ParseState *pstate, const char *refname) * visible in the p_relnamespace lists. This behavior is invalid per the SQL * spec, and it may give ambiguous results (there might be multiple equally * valid matches, but only one will be returned). This must be used ONLY - * as a heuristic in giving suitable error messages. See warnAutoRange. + * as a heuristic in giving suitable error messages. See errorMissingRTE. * * Notice that we consider both matches on actual relation (or CTE) name * and matches on alias. @@ -573,7 +569,6 @@ qualifiedNameToVar(ParseState *pstate, char *schemaname, char *refname, char *colname, - bool implicitRTEOK, int location) { RangeTblEntry *rte; @@ -581,14 +576,8 @@ qualifiedNameToVar(ParseState *pstate, rte = refnameRangeTblEntry(pstate, schemaname, refname, location, &sublevels_up); - if (rte == NULL) - { - if (!implicitRTEOK) - return NULL; - rte = addImplicitRTE(pstate, - makeRangeVar(schemaname, refname, location)); - } + return NULL; return scanRTEForColumn(pstate, rte, colname, location); } @@ -1528,42 +1517,6 @@ addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte, } /* - * Add a POSTQUEL-style implicit RTE. - * - * We assume caller has already checked that there is no RTE or join with - * a conflicting name. - */ -RangeTblEntry * -addImplicitRTE(ParseState *pstate, RangeVar *relation) -{ - CommonTableExpr *cte = NULL; - Index levelsup = 0; - RangeTblEntry *rte; - - /* issue warning or error as needed */ - warnAutoRange(pstate, relation); - - /* if it is an unqualified name, it might be a CTE reference */ - if (!relation->schemaname) - cte = scanNameSpaceForCTE(pstate, relation->relname, &levelsup); - - /* - * Note that we set inFromCl true, so that the RTE will be listed - * explicitly if the parsetree is ever decompiled by ruleutils.c. This - * provides a migration path for views/rules that were originally written - * with implicit-RTE syntax. - */ - if (cte) - rte = addRangeTableEntryForCTE(pstate, cte, levelsup, NULL, true); - else - rte = addRangeTableEntry(pstate, relation, NULL, false, true); - /* Add to joinlist and relnamespace, but not varnamespace */ - addRTEtoQuery(pstate, rte, true, true, false); - - return rte; -} - -/* * expandRTE -- expand the columns of a rangetable entry * * This creates lists of an RTE's column names (aliases if provided, else @@ -2417,13 +2370,13 @@ attnumTypeId(Relation rd, int attid) } /* - * Generate a warning or error about an implicit RTE, if appropriate. + * Generate a suitable error about a missing RTE. * - * If ADD_MISSING_FROM is not enabled, raise an error. Otherwise, emit - * a warning. + * Since this is a very common type of error, we work rather hard to + * produce a helpful message. */ -static void -warnAutoRange(ParseState *pstate, RangeVar *relation) +void +errorMissingRTE(ParseState *pstate, RangeVar *relation) { RangeTblEntry *rte; int sublevels_up; @@ -2431,7 +2384,7 @@ warnAutoRange(ParseState *pstate, RangeVar *relation) /* * Check to see if there are any potential matches in the query's - * rangetable. This affects the message we provide. + * rangetable. */ rte = searchRangeTable(pstate, relation); @@ -2452,39 +2405,21 @@ warnAutoRange(ParseState *pstate, RangeVar *relation) &sublevels_up) == rte) badAlias = rte->eref->aliasname; - if (!add_missing_from) - { - if (rte) - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_TABLE), - errmsg("invalid reference to FROM-clause entry for table \"%s\"", - relation->relname), - (badAlias ? - errhint("Perhaps you meant to reference the table alias \"%s\".", - badAlias) : - errhint("There is an entry for table \"%s\", but it cannot be referenced from this part of the query.", - rte->eref->aliasname)), - parser_errposition(pstate, relation->location))); - else - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_TABLE), - errmsg("missing FROM-clause entry for table \"%s\"", - relation->relname), - parser_errposition(pstate, relation->location))); - } - else - { - /* just issue a warning */ - ereport(NOTICE, + if (rte) + ereport(ERROR, (errcode(ERRCODE_UNDEFINED_TABLE), - errmsg("adding missing FROM-clause entry for table \"%s\"", + errmsg("invalid reference to FROM-clause entry for table \"%s\"", relation->relname), (badAlias ? - errhint("Perhaps you meant to reference the table alias \"%s\".", - badAlias) : - (rte ? - errhint("There is an entry for table \"%s\", but it cannot be referenced from this part of the query.", - rte->eref->aliasname) : 0)), + errhint("Perhaps you meant to reference the table alias \"%s\".", + badAlias) : + errhint("There is an entry for table \"%s\", but it cannot be referenced from this part of the query.", + rte->eref->aliasname)), + parser_errposition(pstate, relation->location))); + else + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_TABLE), + errmsg("missing FROM-clause entry for table \"%s\"", + relation->relname), parser_errposition(pstate, relation->location))); - } } diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index 1635c74ae1d..3aff83955b8 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.172 2009/07/16 06:33:43 petere Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.173 2009/10/21 20:22:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -927,9 +927,8 @@ ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref, rte = refnameRangeTblEntry(pstate, schemaname, relname, cref->location, &sublevels_up); if (rte == NULL) - rte = addImplicitRTE(pstate, - makeRangeVar(schemaname, relname, - cref->location)); + errorMissingRTE(pstate, + makeRangeVar(schemaname, relname, cref->location)); rtindex = RTERangeTablePosn(pstate, rte, &sublevels_up); @@ -973,8 +972,7 @@ ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref, * * tlist entries are generated for each relation appearing in the query's * varnamespace. We do not consider relnamespace because that would include - * input tables of aliasless JOINs, NEW/OLD pseudo-entries, implicit RTEs, - * etc. + * input tables of aliasless JOINs, NEW/OLD pseudo-entries, etc. * * The referenced relations/columns are marked as requiring SELECT access. */ |