54 int nargs,
const Oid *argtypes,
99 bool agg_within_group = (
fn ?
fn->agg_within_group :
false);
100 bool agg_star = (
fn ?
fn->agg_star :
false);
101 bool agg_distinct = (
fn ?
fn->agg_distinct :
false);
102 bool func_variadic = (
fn ?
fn->func_variadic :
false);
142 errmsg_plural(
"cannot pass more than %d argument to a function",
143 "cannot pass more than %d arguments to a function",
193 foreach(
lc, argnames)
198 errmsg(
"argument name \"%s\" used more than once",
209 errmsg(
"positional argument cannot follow named argument"),
228 agg_order ==
NIL && agg_filter ==
NULL &&
229 !agg_star && !agg_distinct && over ==
NULL &&
230 !func_variadic && argnames ==
NIL &&
274 &funcid, &rettype, &retset,
292 errmsg(
"%s is not a procedure",
296 errhint(
"To call a function, use SELECT."),
302 errmsg(
"%s is a procedure",
306 errhint(
"To call a procedure, use CALL."),
320 errmsg(
"%s(*) specified, but %s is not an aggregate function",
327 errmsg(
"DISTINCT specified, but %s is not an aggregate function",
330 if (agg_within_group)
333 errmsg(
"WITHIN GROUP specified, but %s is not an aggregate function",
336 if (agg_order !=
NIL)
339 errmsg(
"ORDER BY specified, but %s is not an aggregate function",
345 errmsg(
"FILTER specified, but %s is not an aggregate function",
351 errmsg(
"OVER specified, but %s is not a window function nor an aggregate function",
358 errmsg(
"%s specified, but %s is not a window function",
381 elog(
ERROR,
"cache lookup failed for aggregate %u", funcid);
393 if (!agg_within_group)
396 errmsg(
"WITHIN GROUP is required for ordered-set aggregate %s",
402 errmsg(
"OVER is not supported for ordered-set aggregate %s",
429 errmsg(
"function %s does not exist",
433 errhint_plural(
"There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
434 "There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
460 errmsg(
"function %s does not exist",
464 errhint_plural(
"There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
465 "There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
487 errmsg(
"function %s does not exist",
491 errhint(
"To use the hypothetical-set aggregate %s, the number of hypothetical direct arguments (here %d) must match the number of ordering columns (here %d).",
501 errmsg(
"function %s does not exist",
505 errhint_plural(
"There is an ordered-set aggregate %s, but it requires at least %d direct argument.",
506 "There is an ordered-set aggregate %s, but it requires at least %d direct arguments.",
523 if (agg_within_group)
526 errmsg(
"%s is not an ordered-set aggregate, so it cannot have WITHIN GROUP",
534 errmsg(
"aggregate functions do not accept RESPECT/IGNORE NULLS"),
545 errmsg(
"window function %s requires an OVER clause",
549 if (agg_within_group)
552 errmsg(
"window function %s cannot have WITHIN GROUP",
581 errmsg(
"procedure %s is not unique",
584 errdetail(
"Could not choose a best candidate procedure."),
585 errhint(
"You might need to add explicit type casts."),
590 errmsg(
"function %s is not unique",
593 errdetail(
"Could not choose a best candidate function."),
594 errhint(
"You might need to add explicit type casts."),
626 if (
list_length(agg_order) > 1 && !agg_within_group)
631 errmsg(
"function %s does not exist",
634 errdetail(
"No aggregate function matches the given name and argument types."),
635 errhint(
"Perhaps you misplaced ORDER BY; ORDER BY must appear "
636 "after all regular arguments of the aggregate."),
642 errmsg(
"procedure %s does not exist",
651 errmsg(
"function %s does not exist",
675 errmsg_plural(
"cannot pass more than %d argument to a function",
676 "cannot pass more than %d arguments to a function",
706 func_variadic =
false;
730 errmsg(
"could not find array type for data type %s",
734 newa->multidims =
false;
742 func_variadic =
true;
756 errmsg(
"VARIADIC argument must be an array"),
770 funcexpr->
funcid = funcid;
771 funcexpr->funcresulttype = rettype;
772 funcexpr->funcretset = retset;
773 funcexpr->funcvariadic = func_variadic;
774 funcexpr->funcformat = funcformat;
779 retval = (
Node *) funcexpr;
787 aggref->aggtype = rettype;
794 aggref->aggstar = agg_star;
795 aggref->aggvariadic = func_variadic;
797 aggref->aggpresorted =
false;
801 aggref->aggtransno = -1;
808 if (
fargs ==
NIL && !agg_star && !agg_within_group)
811 errmsg(
"%s(*) must be used to call a parameterless aggregate function",
818 errmsg(
"aggregates cannot return sets"),
833 errmsg(
"aggregates cannot use named arguments"),
839 retval = (
Node *) aggref;
847 Assert(!agg_within_group);
850 wfunc->wintype = rettype;
854 wfunc->winstar = agg_star;
858 wfunc->runCondition =
NIL;
867 errmsg(
"DISTINCT is not implemented for window functions"),
874 if (wfunc->winagg &&
fargs ==
NIL && !agg_star)
877 errmsg(
"%s(*) must be used to call a parameterless aggregate function",
884 if (agg_order !=
NIL)
887 errmsg(
"aggregate ORDER BY is not implemented for window functions"),
893 if (!wfunc->winagg && agg_filter)
896 errmsg(
"FILTER is not implemented for non-aggregate window functions"),
905 errmsg(
"window function calls cannot contain set-returning function calls"),
906 errhint(
"You might be able to move the set-returning function into a LATERAL FROM item."),
913 errmsg(
"window functions cannot return sets"),
919 retval = (
Node *) wfunc;
956 return errdetail(
"There is no procedure of that name.");
958 return errdetail(
"There is no function of that name.");
963 return errdetail(
"A procedure of that name exists, but it is not in the search_path.");
965 return errdetail(
"A function of that name exists, but it is not in the search_path.");
977 return errdetail(
"No procedure of that name accepts the given number of arguments.");
979 return errdetail(
"No function of that name accepts the given number of arguments.");
989 return errdetail(
"No procedure of that name accepts the given argument names.");
991 return errdetail(
"No function of that name accepts the given argument names.");
1004 return errdetail(
"In the closest available match, "
1005 "an argument was specified both positionally and by name.");
1008 return errdetail(
"In the closest available match, "
1009 "not all required arguments were supplied.");
1012 return errhint(
"This call would be correct if the variadic array were labeled VARIADIC and placed last.");
1015 return errhint(
"The VARIADIC parameter must be placed last, even when using argument names.");
1021 (
void)
errdetail(
"No procedure of that name accepts the given argument types.");
1023 (
void)
errdetail(
"No function of that name accepts the given argument types.");
1024 return errhint(
"You might need to add explicit type casts.");
1154 errmsg_plural(
"cannot pass more than %d argument to a function",
1155 "cannot pass more than %d arguments to a function",
1173 for (
i = 0;
i < nargs;
i++)
1198 for (
i = 0;
i < nargs;
i++)
1236 for (
i = 0;
i < nargs;
i++)
1247 for (
i = 0;
i < nargs;
i++)
1307 for (
i = 0;
i < nargs;
i++)
1376 for (
i = 0;
i < nargs;
i++)
1437 for (
i = 0;
i < nargs;
i++)
1454 for (
i = 0;
i < nargs;
i++)
1758 elog(
ERROR,
"cache lookup failed for function %u",
1761 *rettype =
pform->prorettype;
1762 *retset =
pform->proretset;
1773 elog(
ERROR,
"not enough default arguments");
1805 foreach(
lc, defaults)
1830 switch (
pform->prokind)
1887 elog(
ERROR,
"incorrect number of arguments to hypothetical-set aggregate");
1900 elog(
ERROR,
"hypothetical-set aggregate has inconsistent declared argument types");
2023 NULL,
false,
false);
2087 for (
i = 0;
i < tupdesc->
natts;
i++)
2099 fselect->resulttype = att->atttypid;
2100 fselect->resulttypmod = att->atttypmod;
2102 fselect->resultcollid = att->attcollation;
2124 List *argnames,
const Oid *argtypes)
2138 for (
i = 0;
i < nargs;
i++)
2161 List *argnames,
const Oid *argtypes)
2164 nargs, argnames, argtypes);
2180 int nargs,
const Oid *argtypes,
2299 errmsg(
"could not find a function named \"%s\"",
2304 errmsg(
"function %s does not exist",
2313 errmsg(
"function name \"%s\" is not unique",
2315 errhint(
"Specify the argument list to select the function unambiguously.")));
2359 errmsg_plural(
"procedures cannot have more than %d argument",
2360 "procedures cannot have more than %d arguments",
2366 errmsg_plural(
"functions cannot have more than %d argument",
2367 "functions cannot have more than %d arguments",
2490 errmsg(
"%s is not a function",
2500 errmsg(
"%s is not a procedure",
2510 errmsg(
"function %s is not an aggregate",
2538 errmsg(
"could not find a procedure named \"%s\"",
2543 errmsg(
"procedure %s does not exist",
2552 errmsg(
"could not find an aggregate named \"%s\"",
2557 errmsg(
"aggregate %s(*) does not exist",
2562 errmsg(
"aggregate %s does not exist",
2572 errmsg(
"could not find a function named \"%s\"",
2577 errmsg(
"function %s does not exist",
2590 errmsg(
"function name \"%s\" is not unique",
2593 errhint(
"Specify the argument list to select the function unambiguously.") : 0));
2598 errmsg(
"procedure name \"%s\" is not unique",
2601 errhint(
"Specify the argument list to select the procedure unambiguously.") : 0));
2606 errmsg(
"aggregate name \"%s\" is not unique",
2609 errhint(
"Specify the argument list to select the aggregate unambiguously.") : 0));
2614 errmsg(
"routine name \"%s\" is not unique",
2617 errhint(
"Specify the argument list to select the routine unambiguously.") : 0));
2672 err =
_(
"set-returning functions are not allowed in JOIN conditions");
2685 errmsg(
"set-returning functions must appear at top level of FROM"),
2693 err =
_(
"set-returning functions are not allowed in policy expressions");
2709 err =
_(
"set-returning functions are not allowed in window definitions");
2747 err =
_(
"set-returning functions are not allowed in MERGE WHEN conditions");
2751 err =
_(
"set-returning functions are not allowed in check constraints");
2755 err =
_(
"set-returning functions are not allowed in DEFAULT expressions");
2758 err =
_(
"set-returning functions are not allowed in index expressions");
2761 err =
_(
"set-returning functions are not allowed in index predicates");
2764 err =
_(
"set-returning functions are not allowed in statistics expressions");
2767 err =
_(
"set-returning functions are not allowed in transform expressions");
2770 err =
_(
"set-returning functions are not allowed in EXECUTE parameters");
2773 err =
_(
"set-returning functions are not allowed in trigger WHEN conditions");
2776 err =
_(
"set-returning functions are not allowed in partition bound");
2779 err =
_(
"set-returning functions are not allowed in partition key expressions");
2782 err =
_(
"set-returning functions are not allowed in CALL arguments");
2785 err =
_(
"set-returning functions are not allowed in COPY FROM WHERE conditions");
2788 err =
_(
"set-returning functions are not allowed in column generation expressions");
2794 err =
_(
"set-returning functions are not allowed in property definition expressions");
2797 err =
_(
"set-returning functions are not allowed in FOR PORTION OF expressions");
2817 errmsg(
"set-returning functions are not allowed in %s",
#define InvalidAttrNumber
void bms_free(Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
#define TextDatumGetCString(d)
#define Assert(condition)
#define OidIsValid(objectId)
int errcode(int sqlerrcode)
int errhint(const char *fmt,...) pg_attribute_printf(1
int int int errhint_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
int int int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
#define ereport(elevel,...)
void err(int eval, const char *fmt,...)
TupleDesc get_expr_result_tupdesc(Node *expr, bool noError)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
List * lappend(List *list, void *datum)
List * list_copy_tail(const List *oldlist, int nskip)
List * list_delete_first_n(List *list, int n)
List * list_truncate(List *list, int new_size)
char get_func_prokind(Oid funcid)
Oid get_base_element_type(Oid typid)
Oid getBaseType(Oid typid)
Oid get_array_type(Oid typid)
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
TypeName * makeTypeNameFromNameList(List *names)
void pfree(void *pointer)
char * NameListToString(const List *names)
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool include_out_arguments, bool missing_ok, int *fgc_flags)
#define FGC_ARGNAMES_VALID
#define FGC_ARGNAMES_MATCH
#define FGC_ARGCOUNT_MATCH
#define FGC_ARGNAMES_NONDUP
#define FGC_VARIADIC_FAIL
Oid exprType(const Node *expr)
int exprLocation(const Node *expr)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
void transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc, WindowDef *windef)
void transformAggregateCall(ParseState *pstate, Aggref *agg, List *args, List *aggorder, bool agg_distinct)
Node * transformWhereClause(ParseState *pstate, Node *clause, ParseExprKind exprKind, const char *constructName)
TYPCATEGORY TypeCategory(Oid type)
Oid enforce_generic_type_consistency(const Oid *actual_arg_types, Oid *declared_arg_types, int nargs, Oid rettype, bool allow_poly)
CoercionPathType find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
int32 select_common_typmod(ParseState *pstate, List *exprs, Oid common_type)
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
bool IsPreferredType(TYPCATEGORY category, Oid type)
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
@ COERCION_PATH_COERCEVIAIO
@ COERCION_PATH_RELABELTYPE
const char * ParseExprKindName(ParseExprKind exprKind)
FuncDetailCode func_get_detail(List *funcname, List *fargs, List *fargnames, int nargs, Oid *argtypes, bool expand_variadic, bool expand_defaults, bool include_out_arguments, int *fgc_flags, Oid *funcid, Oid *rettype, bool *retset, int *nvargs, Oid *vatype, Oid **true_typeids, List **argdefaults)
const char * funcname_signature_string(const char *funcname, int nargs, List *argnames, const Oid *argtypes)
static Node * ParseComplexProjection(ParseState *pstate, const char *funcname, Node *first_arg, int location)
void make_fn_arguments(ParseState *pstate, List *fargs, Oid *actual_arg_types, Oid *declared_arg_types)
static Oid LookupFuncNameInternal(ObjectType objtype, List *funcname, int nargs, const Oid *argtypes, bool include_out_arguments, bool missing_ok, FuncLookupError *lookupError)
FuncCandidateList func_select_candidate(int nargs, Oid *input_typeids, FuncCandidateList candidates)
static void unify_hypothetical_args(ParseState *pstate, List *fargs, int numAggregatedArgs, Oid *actual_arg_types, Oid *declared_arg_types)
Node * ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, Node *last_srf, FuncCall *fn, bool proc_call, int location)
const char * func_signature_string(List *funcname, int nargs, List *argnames, const Oid *argtypes)
void check_srf_call_placement(ParseState *pstate, Node *last_srf, int location)
static Oid FuncNameAsType(List *funcname)
static int func_lookup_failure_details(int fgc_flags, List *argnames, bool proc_call)
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
int func_match_argtypes(int nargs, Oid *input_typeids, FuncCandidateList raw_candidates, FuncCandidateList *candidates)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
int parser_errposition(ParseState *pstate, int location)
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
@ EXPR_KIND_EXECUTE_PARAMETER
@ EXPR_KIND_COLUMN_DEFAULT
@ EXPR_KIND_STATS_EXPRESSION
@ EXPR_KIND_INDEX_EXPRESSION
@ EXPR_KIND_MERGE_RETURNING
@ EXPR_KIND_PROPGRAPH_PROPERTY
@ EXPR_KIND_PARTITION_BOUND
@ EXPR_KIND_FUNCTION_DEFAULT
@ EXPR_KIND_WINDOW_FRAME_RANGE
@ EXPR_KIND_FROM_SUBSELECT
@ EXPR_KIND_WINDOW_FRAME_GROUPS
@ EXPR_KIND_PARTITION_EXPRESSION
@ EXPR_KIND_INDEX_PREDICATE
@ EXPR_KIND_INSERT_TARGET
@ EXPR_KIND_ALTER_COL_TRANSFORM
@ EXPR_KIND_UPDATE_TARGET
@ EXPR_KIND_SELECT_TARGET
@ EXPR_KIND_GENERATED_COLUMN
@ EXPR_KIND_CALL_ARGUMENT
@ EXPR_KIND_FROM_FUNCTION
@ EXPR_KIND_UPDATE_SOURCE
@ EXPR_KIND_CHECK_CONSTRAINT
@ EXPR_KIND_WINDOW_PARTITION
@ EXPR_KIND_WINDOW_FRAME_ROWS
@ EXPR_KIND_VALUES_SINGLE
Node * scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, const char *colname, int location)
ParseNamespaceItem * GetNSItemByVar(ParseState *pstate, Var *var)
TupleDesc expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
Oid typeTypeRelid(Type typ)
Type LookupTypeNameExtended(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool temp_ok, bool missing_ok)
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
#define ISCOMPLEX(typeid)
END_CATALOG_STRUCT typedef FormData_pg_aggregate * Form_pg_aggregate
FormData_pg_attribute * Form_pg_attribute
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define foreach_delete_current(lst, var_or_cell)
static ListCell * list_nth_cell(const List *list, int n)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make2(x1, x2)
END_CATALOG_STRUCT typedef FormData_pg_proc * Form_pg_proc
END_CATALOG_STRUCT typedef FormData_pg_type * Form_pg_type
static Datum ObjectIdGetDatum(Oid X)
void * stringToNode(const char *str)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
FunctionParameterMode mode
ParseExprKind p_expr_kind
struct _FuncCandidateList * next
void ReleaseSysCache(HeapTuple tuple)
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
static void * fn(void *arg)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)