* Common code for pg_get_function_arguments and pg_get_function_result: * append the desired subset of arguments to buf. We print only TABLE * arguments when print_table_args is true, and all the others when it's false. * We print argument defaults only if print_defaults is true. * Function return value is the number of arguments printed. */
| 3172 | * Function return value is the number of arguments printed. |
| 3173 | */ |
| 3174 | static int |
| 3175 | print_function_arguments(StringInfo buf, HeapTuple proctup, |
| 3176 | bool print_table_args, bool print_defaults) |
| 3177 | { |
| 3178 | Form_pg_proc proc = (Form_pg_proc) GETSTRUCT(proctup); |
| 3179 | int numargs; |
| 3180 | Oid *argtypes; |
| 3181 | char **argnames; |
| 3182 | char *argmodes; |
| 3183 | int insertorderbyat = -1; |
| 3184 | int argsprinted; |
| 3185 | int inputargno; |
| 3186 | int nlackdefaults; |
| 3187 | List *argdefaults = NIL; |
| 3188 | ListCell *nextargdefault = NULL; |
| 3189 | int i; |
| 3190 | |
| 3191 | numargs = get_func_arg_info(proctup, |
| 3192 | &argtypes, &argnames, &argmodes); |
| 3193 | |
| 3194 | nlackdefaults = numargs; |
| 3195 | if (print_defaults && proc->pronargdefaults > 0) |
| 3196 | { |
| 3197 | Datum proargdefaults; |
| 3198 | bool isnull; |
| 3199 | |
| 3200 | proargdefaults = SysCacheGetAttr(PROCOID, proctup, |
| 3201 | Anum_pg_proc_proargdefaults, |
| 3202 | &isnull); |
| 3203 | if (!isnull) |
| 3204 | { |
| 3205 | char *str; |
| 3206 | |
| 3207 | str = TextDatumGetCString(proargdefaults); |
| 3208 | argdefaults = castNode(List, stringToNode(str)); |
| 3209 | pfree(str); |
| 3210 | nextargdefault = list_head(argdefaults); |
| 3211 | /* nlackdefaults counts only *input* arguments lacking defaults */ |
| 3212 | nlackdefaults = proc->pronargs - list_length(argdefaults); |
| 3213 | } |
| 3214 | } |
| 3215 | |
| 3216 | /* Check for special treatment of ordered-set aggregates */ |
| 3217 | if (proc->prokind == PROKIND_AGGREGATE) |
| 3218 | { |
| 3219 | HeapTuple aggtup; |
| 3220 | Form_pg_aggregate agg; |
| 3221 | |
| 3222 | aggtup = SearchSysCache1(AGGFNOID, proc->oid); |
| 3223 | if (!HeapTupleIsValid(aggtup)) |
| 3224 | elog(ERROR, "cache lookup failed for aggregate %u", |
| 3225 | proc->oid); |
| 3226 | agg = (Form_pg_aggregate) GETSTRUCT(aggtup); |
| 3227 | if (AGGKIND_IS_ORDERED_SET(agg->aggkind)) |
| 3228 | insertorderbyat = agg->aggnumdirectargs; |
| 3229 | ReleaseSysCache(aggtup); |
| 3230 | } |
| 3231 |
no test coverage detected