1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Default values for function arguments

Pavel Stehule, with some tweaks by Peter Eisentraut
This commit is contained in:
Peter Eisentraut
2008-12-04 17:51:28 +00:00
parent 7b640b0345
commit 455dffbb73
29 changed files with 2848 additions and 2166 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.207 2008/09/01 20:42:44 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.208 2008/12/04 17:51:26 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -77,6 +77,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
bool retset;
int nvargs;
FuncDetailCode fdresult;
List *argdefaults;
/*
* Most of the rest of the parser just assumes that functions do not have
@ -164,7 +165,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
fdresult = func_get_detail(funcname, fargs, nargs, actual_arg_types,
!func_variadic,
&funcid, &rettype, &retset, &nvargs,
&declared_arg_types);
&declared_arg_types, &argdefaults);
if (fdresult == FUNCDETAIL_COERCION)
{
/*
@ -234,6 +235,21 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
parser_errposition(pstate, location)));
}
/* add stored expressions as called values for arguments with defaults */
if (argdefaults)
{
ListCell *lc;
foreach(lc, argdefaults)
{
Node *expr = (Node *) lfirst(lc);
fargs = lappend(fargs, expr);
actual_arg_types[nargs++] = exprType(expr);
}
}
/*
* enforce consistency with polymorphic argument and return types,
* possibly adjusting return type or declared_arg_types (which will be
@ -729,7 +745,8 @@ func_get_detail(List *funcname,
Oid *rettype, /* return value */
bool *retset, /* return value */
int *nvargs, /* return value */
Oid **true_typeids) /* return value */
Oid **true_typeids, /* return value */
List **argdefaults) /* return value */
{
FuncCandidateList raw_candidates;
FuncCandidateList best_candidate;
@ -870,6 +887,8 @@ func_get_detail(List *funcname,
*funcid = best_candidate->oid;
*nvargs = best_candidate->nvargs;
*true_typeids = best_candidate->args;
if (argdefaults)
*argdefaults = best_candidate->argdefaults;
ftup = SearchSysCache(PROCOID,
ObjectIdGetDatum(best_candidate->oid),