diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-10-31 01:41:31 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-10-31 01:41:31 +0000 |
commit | fb5d05805b3f7658e47ad2c6a4631e497bb3f627 (patch) | |
tree | 74ee6327b45c313ac0ac21e92a3d61a52135cd2f /src/backend/parser/parse_func.c | |
parent | 8442317beb8fb6f180880a977c03ccae4304df25 (diff) | |
download | postgresql-fb5d05805b3f7658e47ad2c6a4631e497bb3f627.tar.gz postgresql-fb5d05805b3f7658e47ad2c6a4631e497bb3f627.zip |
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.
Diffstat (limited to 'src/backend/parser/parse_func.c')
-rw-r--r-- | src/backend/parser/parse_func.c | 66 |
1 files changed, 6 insertions, 60 deletions
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c index e752dd8d1ec..d86bd1732f9 100644 --- a/src/backend/parser/parse_func.c +++ b/src/backend/parser/parse_func.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.217 2009/10/08 02:39:23 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.218 2009/10/31 01:41:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -33,8 +33,6 @@ static Oid FuncNameAsType(List *funcname); static Node *ParseComplexProjection(ParseState *pstate, char *funcname, Node *first_arg, int location); -static void unknown_attribute(ParseState *pstate, Node *relref, char *attname, - int location); /* @@ -53,6 +51,8 @@ static void unknown_attribute(ParseState *pstate, Node *relref, char *attname, * not to affect the semantics. When is_column is true, we should have * a single argument (the putative table), unqualified function name * equal to the column name, and no aggregate or variadic decoration. + * Also, when is_column is true, we return NULL on failure rather than + * reporting a no-such-function error. * * The argument expressions (in fargs) must have been transformed already. */ @@ -253,16 +253,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, /* * Oops. Time to die. * - * If we are dealing with the attribute notation rel.function, give an - * error message that is appropriate for that case. + * If we are dealing with the attribute notation rel.function, + * let the caller handle failure. */ if (is_column) - { - Assert(nargs == 1); - Assert(list_length(funcname) == 1); - unknown_attribute(pstate, first_arg, strVal(linitial(funcname)), - location); - } + return NULL; /* * Else generate a detailed complaint for a function @@ -1344,55 +1339,6 @@ ParseComplexProjection(ParseState *pstate, char *funcname, Node *first_arg, } /* - * helper routine for delivering "column does not exist" error message - */ -static void -unknown_attribute(ParseState *pstate, Node *relref, char *attname, - int location) -{ - RangeTblEntry *rte; - - if (IsA(relref, Var) && - ((Var *) relref)->varattno == InvalidAttrNumber) - { - /* Reference the RTE by alias not by actual table name */ - rte = GetRTEByRangeTablePosn(pstate, - ((Var *) relref)->varno, - ((Var *) relref)->varlevelsup); - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_COLUMN), - errmsg("column %s.%s does not exist", - rte->eref->aliasname, attname), - parser_errposition(pstate, location))); - } - else - { - /* Have to do it by reference to the type of the expression */ - Oid relTypeId = exprType(relref); - - if (ISCOMPLEX(relTypeId)) - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_COLUMN), - errmsg("column \"%s\" not found in data type %s", - attname, format_type_be(relTypeId)), - parser_errposition(pstate, location))); - else if (relTypeId == RECORDOID) - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_COLUMN), - errmsg("could not identify column \"%s\" in record data type", - attname), - parser_errposition(pstate, location))); - else - ereport(ERROR, - (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("column notation .%s applied to type %s, " - "which is not a composite type", - attname, format_type_be(relTypeId)), - parser_errposition(pstate, location))); - } -} - -/* * funcname_signature_string * Build a string representing a function name, including arg types. * The result is something like "foo(integer)". |