diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c index 8bd88b0..52f646f 100644 --- a/src/backend/parser/parse_func.c +++ b/src/backend/parser/parse_func.c @@ -539,6 +539,20 @@ func_match_argtypes(int nargs, FuncCandidateList current_candidate; FuncCandidateList next_candidate; int ncandidates = 0; + CoercionContext ccontext = COERCION_IMPLICIT; + + /* + * Normally, we allow only implicit casts to be used when deciding which + * function signatures a particular call might match. Any other behavior + * risks allowing users to inadvertently call the wrong function. + * However, when there is only one candidate, the risk of confusion is + * minimal. So, in that case, we attempt to match the user's call to the + * lone candidate using either implicit or assignment casts, so that users + * needn't insert explicit casts into the call to match the only available + * candidate. + */ + if (raw_candidates != NULL && raw_candidates->next == NULL) + ccontext = COERCION_ASSIGNMENT; *candidates = NULL; @@ -548,7 +562,7 @@ func_match_argtypes(int nargs, { next_candidate = current_candidate->next; if (can_coerce_type(nargs, input_typeids, current_candidate->args, - COERCION_IMPLICIT)) + ccontext)) { current_candidate->next = *candidates; *candidates = current_candidate; @@ -1356,7 +1370,7 @@ make_fn_arguments(ParseState *pstate, (Node *) na->arg, actual_arg_types[i], declared_arg_types[i], -1, - COERCION_IMPLICIT, + COERCION_ASSIGNMENT, COERCE_IMPLICIT_CAST, -1); na->arg = (Expr *) node; @@ -1367,7 +1381,7 @@ make_fn_arguments(ParseState *pstate, node, actual_arg_types[i], declared_arg_types[i], -1, - COERCION_IMPLICIT, + COERCION_ASSIGNMENT, COERCE_IMPLICIT_CAST, -1); lfirst(current_fargs) = node; diff --git a/src/test/regress/expected/errors.out b/src/test/regress/expected/errors.out index fa0bd82..00be865 100644 --- a/src/test/regress/expected/errors.out +++ b/src/test/regress/expected/errors.out @@ -126,7 +126,7 @@ create aggregate newavg2 (sfunc = int4pl, stype = int4, finalfunc = int2um, initcond = '0'); -ERROR: function int2um(integer) does not exist +ERROR: function int2um(smallint) requires run-time type coercion -- left out basetype create aggregate newcnt1 (sfunc = int4inc, stype = int4,