diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-06-10 17:11:36 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-06-10 17:11:36 -0400 |
commit | e56bce5d43789cce95d099554ae9593ada92b3b7 (patch) | |
tree | 7c5db32085c578c1ec662a05a4404f75e5f824a9 /src/backend/executor/functions.c | |
parent | 3a09d75b4f6cabc8331e228b6988dbfcd9afdfbe (diff) | |
download | postgresql-e56bce5d43789cce95d099554ae9593ada92b3b7.tar.gz postgresql-e56bce5d43789cce95d099554ae9593ada92b3b7.zip |
Reconsider the handling of procedure OUT parameters.
Commit 2453ea142 redefined pg_proc.proargtypes to include the types of
OUT parameters, for procedures only. While that had some advantages
for implementing the SQL-spec behavior of DROP PROCEDURE, it was pretty
disastrous from a number of other perspectives. Notably, since the
primary key of pg_proc is name + proargtypes, this made it possible to
have multiple procedures with identical names + input arguments and
differing output argument types. That would make it impossible to call
any one of the procedures by writing just NULL (or "?", or any other
data-type-free notation) for the output argument(s). The change also
seems likely to cause grave confusion for client applications that
examine pg_proc and expect the traditional definition of proargtypes.
Hence, revert the definition of proargtypes to what it was, and
undo a number of complications that had been added to support that.
To support the SQL-spec behavior of DROP PROCEDURE, when there are
no argmode markers in the command's parameter list, we perform the
lookup both ways (that is, matching against both proargtypes and
proallargtypes), succeeding if we get just one unique match.
In principle this could result in ambiguous-function failures
that would not happen when using only one of the two rules.
However, overloading of procedure names is thought to be a pretty
rare usage, so this shouldn't cause many problems in practice.
Postgres-specific code such as pg_dump can defend against any
possibility of such failures by being careful to specify argmodes
for all procedure arguments.
This also fixes a few other bugs in the area of CALL statements
with named parameters, and improves the documentation a little.
catversion bump forced because the representation of procedures
with OUT arguments changes.
Discussion: https://postgr.es/m/3742981.1621533210@sss.pgh.pa.us
Diffstat (limited to 'src/backend/executor/functions.c')
-rw-r--r-- | src/backend/executor/functions.c | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index 39580f7d577..32668f85a1d 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -245,8 +245,7 @@ prepare_sql_fn_parse_info(HeapTuple procedureTuple, if (isNull) proargmodes = PointerGetDatum(NULL); /* just to be sure */ - n_arg_names = get_func_input_arg_names(procedureStruct->prokind, - proargnames, proargmodes, + n_arg_names = get_func_input_arg_names(proargnames, proargmodes, &pinfo->argnames); /* Paranoia: ignore the result if too few array entries */ @@ -1536,7 +1535,7 @@ check_sql_fn_statements(List *queryTreeLists) Query *query = lfirst_node(Query, lc2); /* - * Disallow procedures with output arguments. The current + * Disallow calling procedures with output arguments. The current * implementation would just throw the output values away, unless * the statement is the last one. Per SQL standard, we should * assign the output values by name. By disallowing this here, we @@ -1545,31 +1544,12 @@ check_sql_fn_statements(List *queryTreeLists) if (query->commandType == CMD_UTILITY && IsA(query->utilityStmt, CallStmt)) { - CallStmt *stmt = castNode(CallStmt, query->utilityStmt); - HeapTuple tuple; - int numargs; - Oid *argtypes; - char **argnames; - char *argmodes; - int i; - - tuple = SearchSysCache1(PROCOID, - ObjectIdGetDatum(stmt->funcexpr->funcid)); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "cache lookup failed for function %u", - stmt->funcexpr->funcid); - numargs = get_func_arg_info(tuple, - &argtypes, &argnames, &argmodes); - ReleaseSysCache(tuple); - - for (i = 0; i < numargs; i++) - { - if (argmodes && (argmodes[i] == PROARGMODE_INOUT || - argmodes[i] == PROARGMODE_OUT)) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("calling procedures with output arguments is not supported in SQL functions"))); - } + CallStmt *stmt = (CallStmt *) query->utilityStmt; + + if (stmt->outargs != NIL) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("calling procedures with output arguments is not supported in SQL functions"))); } } } |