* lookup_agg_function * common code for finding aggregate support functions * * fnName: possibly-schema-qualified function name * nargs, input_types: expected function argument types * variadicArgType: type of variadic argument if any, else InvalidOid * * Returns OID of function, and stores its return type into *rettype * * NB: must not scribble on input_types[], as we may re-use those *
| 829 | * NB: must not scribble on input_types[], as we may re-use those |
| 830 | */ |
| 831 | static Oid |
| 832 | lookup_agg_function(List *fnName, |
| 833 | int nargs, |
| 834 | Oid *input_types, |
| 835 | Oid variadicArgType, |
| 836 | Oid *rettype) |
| 837 | { |
| 838 | Oid fnOid; |
| 839 | bool retset; |
| 840 | int nvargs; |
| 841 | Oid vatype; |
| 842 | Oid *true_oid_array; |
| 843 | FuncDetailCode fdresult; |
| 844 | AclResult aclresult; |
| 845 | int i; |
| 846 | |
| 847 | /* |
| 848 | * func_get_detail looks up the function in the catalogs, does |
| 849 | * disambiguation for polymorphic functions, handles inheritance, and |
| 850 | * returns the funcid and type and set or singleton status of the |
| 851 | * function's return value. it also returns the true argument types to |
| 852 | * the function. |
| 853 | */ |
| 854 | fdresult = func_get_detail(fnName, NIL, NIL, |
| 855 | nargs, input_types, false, false, false, |
| 856 | &fnOid, rettype, &retset, |
| 857 | &nvargs, &vatype, |
| 858 | &true_oid_array, NULL); |
| 859 | |
| 860 | /* only valid case is a normal function not returning a set */ |
| 861 | if (fdresult != FUNCDETAIL_NORMAL || !OidIsValid(fnOid)) |
| 862 | ereport(ERROR, |
| 863 | (errcode(ERRCODE_UNDEFINED_FUNCTION), |
| 864 | errmsg("function %s does not exist", |
| 865 | func_signature_string(fnName, nargs, |
| 866 | NIL, input_types)))); |
| 867 | if (retset) |
| 868 | ereport(ERROR, |
| 869 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 870 | errmsg("function %s returns a set", |
| 871 | func_signature_string(fnName, nargs, |
| 872 | NIL, input_types)))); |
| 873 | |
| 874 | /* |
| 875 | * If the agg is declared to take VARIADIC ANY, the underlying functions |
| 876 | * had better be declared that way too, else they may receive too many |
| 877 | * parameters; but func_get_detail would have been happy with plain ANY. |
| 878 | * (Probably nothing very bad would happen, but it wouldn't work as the |
| 879 | * user expects.) Other combinations should work without any special |
| 880 | * pushups, given that we told func_get_detail not to expand VARIADIC. |
| 881 | */ |
| 882 | if (variadicArgType == ANYOID && vatype != ANYOID) |
| 883 | ereport(ERROR, |
| 884 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 885 | errmsg("function %s must accept VARIADIC ANY to be used in this aggregate", |
| 886 | func_signature_string(fnName, nargs, |
| 887 | NIL, input_types)))); |
| 888 |
no test coverage detected