102 char *paramModes = NULL;
108 bool nulls[Natts_pg_proc];
110 bool replaces[Natts_pg_proc];
126 parameterCount = parameterTypes->
dim1;
129 (
errcode(ERRCODE_TOO_MANY_ARGUMENTS),
131 "functions cannot have more than %d arguments",
146 allParamCount =
ARR_DIMS(allParamArray)[0];
148 allParamCount <= 0 ||
151 elog(
ERROR,
"allParameterTypes is not a 1-D Oid array");
153 Assert(allParamCount >= parameterCount);
158 allParamCount = parameterCount;
159 allParams = parameterTypes->
values;
172 ARR_DIMS(modesArray)[0] != allParamCount ||
175 elog(
ERROR,
"parameterModes is not a 1-D char array");
188 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
189 errmsg(
"cannot determine result data type"),
201 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
202 errmsg(
"unsafe use of pseudo-type \"internal\""),
210 for (
i = 0;
i < allParamCount;
i++)
212 if (paramModes == NULL ||
213 paramModes[
i] == PROARGMODE_IN ||
214 paramModes[
i] == PROARGMODE_VARIADIC)
222 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
223 errmsg(
"cannot determine result data type"),
230 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
231 errmsg(
"unsafe use of pseudo-type \"internal\""),
237 if (paramModes != NULL)
244 for (
i = 0;
i < allParamCount;
i++)
246 switch (paramModes[
i])
249 case PROARGMODE_INOUT:
251 elog(
ERROR,
"variadic parameter must be last");
254 if (
OidIsValid(variadicType) && prokind == PROKIND_PROCEDURE)
255 elog(
ERROR,
"variadic parameter must be last");
257 case PROARGMODE_TABLE:
260 case PROARGMODE_VARIADIC:
262 elog(
ERROR,
"variadic parameter must be last");
263 switch (allParams[
i])
266 variadicType = ANYOID;
269 variadicType = ANYELEMENTOID;
271 case ANYCOMPATIBLEARRAYOID:
272 variadicType = ANYCOMPATIBLEOID;
277 elog(
ERROR,
"variadic parameter is not an array");
282 elog(
ERROR,
"invalid parameter mode '%c'", paramModes[
i]);
292 for (
i = 0;
i < Natts_pg_proc; ++
i)
320 values[Anum_pg_proc_proallargtypes - 1] = allParameterTypes;
322 nulls[Anum_pg_proc_proallargtypes - 1] =
true;
324 values[Anum_pg_proc_proargmodes - 1] = parameterModes;
326 nulls[Anum_pg_proc_proargmodes - 1] =
true;
328 values[Anum_pg_proc_proargnames - 1] = parameterNames;
330 nulls[Anum_pg_proc_proargnames - 1] =
true;
331 if (parameterDefaults !=
NIL)
334 nulls[Anum_pg_proc_proargdefaults - 1] =
true;
336 values[Anum_pg_proc_protrftypes - 1] = trftypes;
338 nulls[Anum_pg_proc_protrftypes - 1] =
true;
343 nulls[Anum_pg_proc_probin - 1] =
true;
347 nulls[Anum_pg_proc_prosqlbody - 1] =
true;
349 values[Anum_pg_proc_proconfig - 1] = proconfig;
351 nulls[Anum_pg_proc_proconfig - 1] =
true;
373 (
errcode(ERRCODE_DUPLICATE_FUNCTION),
374 errmsg(
"function \"%s\" already exists with same argument types",
381 if (oldproc->prokind != prokind)
383 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
384 errmsg(
"cannot change routine kind"),
385 (oldproc->prokind == PROKIND_AGGREGATE ?
386 errdetail(
"\"%s\" is an aggregate function.", procedureName) :
387 oldproc->prokind == PROKIND_FUNCTION ?
388 errdetail(
"\"%s\" is a function.", procedureName) :
389 oldproc->prokind == PROKIND_PROCEDURE ?
390 errdetail(
"\"%s\" is a procedure.", procedureName) :
391 oldproc->prokind == PROKIND_WINDOW ?
392 errdetail(
"\"%s\" is a window function.", procedureName) :
395 dropcmd = (prokind == PROKIND_PROCEDURE ?
"DROP PROCEDURE" :
396 prokind == PROKIND_AGGREGATE ?
"DROP AGGREGATE" :
407 if (returnType != oldproc->prorettype ||
408 returnsSet != oldproc->proretset)
410 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
411 prokind == PROKIND_PROCEDURE
412 ?
errmsg(
"cannot change whether a procedure has output parameters")
413 :
errmsg(
"cannot change return type of existing function"),
427 if (returnType == RECORDOID)
437 if (olddesc == NULL && newdesc == NULL)
439 else if (olddesc == NULL || newdesc == NULL ||
442 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
443 errmsg(
"cannot change return type of existing function"),
444 errdetail(
"Row type defined by OUT parameters is different."),
457 Anum_pg_proc_proargnames,
462 char **old_arg_names;
463 char **new_arg_names;
469 Anum_pg_proc_proargmodes,
480 for (
j = 0;
j < n_old_arg_names;
j++)
482 if (old_arg_names[
j] == NULL)
484 if (
j >= n_new_arg_names || new_arg_names[
j] == NULL ||
485 strcmp(old_arg_names[
j], new_arg_names[
j]) != 0)
487 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
488 errmsg(
"cannot change name of input parameter \"%s\"",
505 if (oldproc->pronargdefaults != 0)
507 Datum proargdefaults;
512 if (
list_length(parameterDefaults) < oldproc->pronargdefaults)
514 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
515 errmsg(
"cannot remove parameter defaults from existing function"),
522 Anum_pg_proc_proargdefaults);
529 oldproc->pronargdefaults);
531 foreach(oldlc, oldDefaults)
538 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
539 errmsg(
"cannot change data type of existing parameter default value"),
544 newlc =
lnext(parameterDefaults, newlc);
552 replaces[Anum_pg_proc_oid - 1] =
false;
553 replaces[Anum_pg_proc_proowner - 1] =
false;
554 replaces[Anum_pg_proc_proacl - 1] =
false;
574 nulls[Anum_pg_proc_proacl - 1] =
true;
620 for (
i = 0;
i < allParamCount;
i++)
644 if (languageObjectId == SQLlanguageId && prosqlbody)
648 if (parameterDefaults)
675 int save_nestlevel = 0;
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
#define CStringGetTextDatum(s)
#define TextDatumGetCString(d)
#define Assert(condition)
#define PointerIsValid(pointer)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
ObjectAddresses * new_object_addresses(void)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
void free_object_addresses(ObjectAddresses *addrs)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
int errdetail_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define OidFunctionCall1(functionId, arg1)
TupleDesc build_function_result_tupdesc_t(HeapTuple procTuple)
TupleDesc build_function_result_tupdesc_d(char prokind, Datum proallargtypes, Datum proargmodes, Datum proargnames)
int get_func_input_arg_names(Datum proargnames, Datum proargmodes, char ***arg_names)
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
int NewGUCNestLevel(void)
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
void AtEOXact_GUC(bool isCommit, int nestLevel)
bool check_function_bodies
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Oid get_element_type(Oid typid)
void namestrcpy(Name name, const char *str)
Oid exprType(const Node *expr)
#define castNode(_type_, nodeptr)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define ObjectAddressSet(addr, class_id, object_id)
char * nodeToString(const void *obj)
char * check_valid_internal_signature(Oid ret_type, const Oid *declared_arg_types, int nargs)
char * check_valid_polymorphic_signature(Oid ret_type, const Oid *declared_arg_types, int nargs)
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
static int list_length(const List *l)
static ListCell * list_nth_cell(const List *list, int n)
static ListCell * lnext(const List *l, const ListCell *c)
FormData_pg_proc * Form_pg_proc
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
void pgstat_create_function(Oid proid)
static Datum PointerGetDatum(const void *X)
static Datum Float4GetDatum(float4 X)
static Datum UInt16GetDatum(uint16 X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum NameGetDatum(const NameData *X)
static Pointer DatumGetPointer(Datum X)
static Datum CharGetDatum(char X)
void * stringToNode(const char *str)
char * format_procedure(Oid procedure_oid)
#define RelationGetDescr(relation)
Oid values[FLEXIBLE_ARRAY_MEMBER]
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
bool equalRowTypes(TupleDesc tupdesc1, TupleDesc tupdesc2)
void CommandCounterIncrement(void)