From fb5d05805b3f7658e47ad2c6a4631e497bb3f627 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 31 Oct 2009 01:41:31 +0000 Subject: Implement parser hooks for processing ColumnRef and ParamRef nodes, as per my recent proposal. As proof of concept, remove knowledge of Params from the core parser, arranging for them to be handled entirely by parser hook functions. It turns out we need an additional hook for that --- I had forgotten about the code that handles inferring a parameter's type from context. This is a preliminary step towards letting plpgsql handle its variables through parser hooks. Additional work remains to be done to expose the facility through SPI, but I think this is all the changes needed in the core parser. --- src/backend/parser/parse_relation.c | 43 ++++++++++++------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) (limited to 'src/backend/parser/parse_relation.c') diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 9b35577ec3c..184bc7c47a0 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.146 2009/10/27 17:11:18 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.147 2009/10/31 01:41:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -86,7 +86,17 @@ refnameRangeTblEntry(ParseState *pstate, { Oid namespaceId; - namespaceId = LookupExplicitNamespace(schemaname); + /* + * We can use LookupNamespaceNoError() here because we are only + * interested in finding existing RTEs. Checking USAGE permission + * on the schema is unnecessary since it would have already been + * checked when the RTE was made. Furthermore, we want to report + * "RTE not found", not "no permissions for schema", if the name + * happens to match a schema name the user hasn't got access to. + */ + namespaceId = LookupNamespaceNoError(schemaname); + if (!OidIsValid(relId)) + return NULL; relId = get_relname_relid(refname, namespaceId); if (!OidIsValid(relId)) return NULL; @@ -555,32 +565,6 @@ colNameToVar(ParseState *pstate, char *colname, bool localonly, return result; } -/* - * qualifiedNameToVar - * Search for a qualified column name: either refname.colname or - * schemaname.relname.colname. - * - * If found, return the appropriate Var node. - * If not found, return NULL. If the name proves ambiguous, raise error. - */ -Node * -qualifiedNameToVar(ParseState *pstate, - char *schemaname, - char *refname, - char *colname, - int location) -{ - RangeTblEntry *rte; - int sublevels_up; - - rte = refnameRangeTblEntry(pstate, schemaname, refname, location, - &sublevels_up); - if (rte == NULL) - return NULL; - - return scanRTEForColumn(pstate, rte, colname, location); -} - /* * markRTEForSelectPriv * Mark the specified column of an RTE as requiring SELECT privilege @@ -2389,7 +2373,8 @@ errorMissingRTE(ParseState *pstate, RangeVar *relation) /* * Check to see if there are any potential matches in the query's - * rangetable. + * rangetable. (Note: cases involving a bad schema name in the + * RangeVar will throw error immediately here. That seems OK.) */ rte = searchRangeTable(pstate, relation); -- cgit v1.2.3