* generate_function_name * Compute the name to display for a function specified by OID, * given that it is being called with the specified actual arg names and * types. (Those matter because of ambiguous-function resolution rules.) * * If we're dealing with a potentially variadic function (in practice, this * means a FuncExpr or Aggref, not some other way of calling a function), then *
| 12125 | * The result includes all necessary quoting and schema-prefixing. |
| 12126 | */ |
| 12127 | static char * |
| 12128 | generate_function_name(Oid funcid, int nargs, List *argnames, Oid *argtypes, |
| 12129 | bool has_variadic, bool *use_variadic_p, |
| 12130 | ParseExprKind special_exprkind) |
| 12131 | { |
| 12132 | char *result; |
| 12133 | HeapTuple proctup; |
| 12134 | Form_pg_proc procform; |
| 12135 | char *proname; |
| 12136 | bool use_variadic; |
| 12137 | char *nspname; |
| 12138 | FuncDetailCode p_result; |
| 12139 | Oid p_funcid; |
| 12140 | Oid p_rettype; |
| 12141 | bool p_retset; |
| 12142 | int p_nvargs; |
| 12143 | Oid p_vatype; |
| 12144 | Oid *p_true_typeids; |
| 12145 | bool force_qualify = false; |
| 12146 | |
| 12147 | proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcid)); |
| 12148 | if (!HeapTupleIsValid(proctup)) |
| 12149 | elog(ERROR, "cache lookup failed for function %u", funcid); |
| 12150 | procform = (Form_pg_proc) GETSTRUCT(proctup); |
| 12151 | proname = NameStr(procform->proname); |
| 12152 | |
| 12153 | /* |
| 12154 | * Due to parser hacks to avoid needing to reserve CUBE, we need to force |
| 12155 | * qualification in some special cases. |
| 12156 | */ |
| 12157 | if (special_exprkind == EXPR_KIND_GROUP_BY) |
| 12158 | { |
| 12159 | if (strcmp(proname, "cube") == 0 || strcmp(proname, "rollup") == 0) |
| 12160 | force_qualify = true; |
| 12161 | } |
| 12162 | |
| 12163 | /* |
| 12164 | * Determine whether VARIADIC should be printed. We must do this first |
| 12165 | * since it affects the lookup rules in func_get_detail(). |
| 12166 | * |
| 12167 | * We always print VARIADIC if the function has a merged variadic-array |
| 12168 | * argument. Note that this is always the case for functions taking a |
| 12169 | * VARIADIC argument type other than VARIADIC ANY. If we omitted VARIADIC |
| 12170 | * and printed the array elements as separate arguments, the call could |
| 12171 | * match a newer non-VARIADIC function. |
| 12172 | */ |
| 12173 | if (use_variadic_p) |
| 12174 | { |
| 12175 | /* Parser should not have set funcvariadic unless fn is variadic */ |
| 12176 | Assert(!has_variadic || OidIsValid(procform->provariadic)); |
| 12177 | use_variadic = has_variadic; |
| 12178 | *use_variadic_p = use_variadic; |
| 12179 | } |
| 12180 | else |
| 12181 | { |
| 12182 | Assert(!has_variadic); |
| 12183 | use_variadic = false; |
| 12184 | } |
no test coverage detected