104 char *paramModes = NULL;
110 bool nulls[Natts_pg_proc];
112 bool replaces[Natts_pg_proc];
128 parameterCount = parameterTypes->
dim1;
131 (
errcode(ERRCODE_TOO_MANY_ARGUMENTS),
133 "functions cannot have more than %d arguments",
148 allParamCount =
ARR_DIMS(allParamArray)[0];
150 allParamCount <= 0 ||
153 elog(
ERROR,
"allParameterTypes is not a 1-D Oid array");
155 Assert(allParamCount >= parameterCount);
160 allParamCount = parameterCount;
161 allParams = parameterTypes->
values;
174 ARR_DIMS(modesArray)[0] != allParamCount ||
177 elog(
ERROR,
"parameterModes is not a 1-D char array");
190 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
191 errmsg(
"cannot determine result data type"),
203 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
204 errmsg(
"unsafe use of pseudo-type \"internal\""),
212 for (
i = 0;
i < allParamCount;
i++)
214 if (paramModes == NULL ||
215 paramModes[
i] == PROARGMODE_IN ||
216 paramModes[
i] == PROARGMODE_VARIADIC)
224 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
225 errmsg(
"cannot determine result data type"),
232 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
233 errmsg(
"unsafe use of pseudo-type \"internal\""),
239 if (paramModes != NULL)
246 for (
i = 0;
i < allParamCount;
i++)
248 switch (paramModes[
i])
251 case PROARGMODE_INOUT:
253 elog(
ERROR,
"variadic parameter must be last");
256 if (
OidIsValid(variadicType) && prokind == PROKIND_PROCEDURE)
257 elog(
ERROR,
"variadic parameter must be last");
259 case PROARGMODE_TABLE:
262 case PROARGMODE_VARIADIC:
264 elog(
ERROR,
"variadic parameter must be last");
265 switch (allParams[
i])
268 variadicType = ANYOID;
271 variadicType = ANYELEMENTOID;
273 case ANYCOMPATIBLEARRAYOID:
274 variadicType = ANYCOMPATIBLEOID;
279 elog(
ERROR,
"variadic parameter is not an array");
284 elog(
ERROR,
"invalid parameter mode '%c'", paramModes[
i]);
294 for (
i = 0;
i < Natts_pg_proc; ++
i)
322 values[Anum_pg_proc_proallargtypes - 1] = allParameterTypes;
324 nulls[Anum_pg_proc_proallargtypes - 1] =
true;
326 values[Anum_pg_proc_proargmodes - 1] = parameterModes;
328 nulls[Anum_pg_proc_proargmodes - 1] =
true;
330 values[Anum_pg_proc_proargnames - 1] = parameterNames;
332 nulls[Anum_pg_proc_proargnames - 1] =
true;
333 if (parameterDefaults !=
NIL)
336 nulls[Anum_pg_proc_proargdefaults - 1] =
true;
338 values[Anum_pg_proc_protrftypes - 1] = trftypes;
340 nulls[Anum_pg_proc_protrftypes - 1] =
true;
345 nulls[Anum_pg_proc_probin - 1] =
true;
349 nulls[Anum_pg_proc_prosqlbody - 1] =
true;
351 values[Anum_pg_proc_proconfig - 1] = proconfig;
353 nulls[Anum_pg_proc_proconfig - 1] =
true;
375 (
errcode(ERRCODE_DUPLICATE_FUNCTION),
376 errmsg(
"function \"%s\" already exists with same argument types",
383 if (oldproc->prokind != prokind)
385 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
386 errmsg(
"cannot change routine kind"),
387 (oldproc->prokind == PROKIND_AGGREGATE ?
388 errdetail(
"\"%s\" is an aggregate function.", procedureName) :
389 oldproc->prokind == PROKIND_FUNCTION ?
390 errdetail(
"\"%s\" is a function.", procedureName) :
391 oldproc->prokind == PROKIND_PROCEDURE ?
392 errdetail(
"\"%s\" is a procedure.", procedureName) :
393 oldproc->prokind == PROKIND_WINDOW ?
394 errdetail(
"\"%s\" is a window function.", procedureName) :
397 dropcmd = (prokind == PROKIND_PROCEDURE ?
"DROP PROCEDURE" :
398 prokind == PROKIND_AGGREGATE ?
"DROP AGGREGATE" :
409 if (returnType != oldproc->prorettype ||
410 returnsSet != oldproc->proretset)
412 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
413 prokind == PROKIND_PROCEDURE
414 ?
errmsg(
"cannot change whether a procedure has output parameters")
415 :
errmsg(
"cannot change return type of existing function"),
429 if (returnType == RECORDOID)
439 if (olddesc == NULL && newdesc == NULL)
441 else if (olddesc == NULL || newdesc == NULL ||
444 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
445 errmsg(
"cannot change return type of existing function"),
446 errdetail(
"Row type defined by OUT parameters is different."),
459 Anum_pg_proc_proargnames,
464 char **old_arg_names;
465 char **new_arg_names;
471 Anum_pg_proc_proargmodes,
482 for (
j = 0;
j < n_old_arg_names;
j++)
484 if (old_arg_names[
j] == NULL)
486 if (
j >= n_new_arg_names || new_arg_names[
j] == NULL ||
487 strcmp(old_arg_names[
j], new_arg_names[
j]) != 0)
489 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
490 errmsg(
"cannot change name of input parameter \"%s\"",
507 if (oldproc->pronargdefaults != 0)
509 Datum proargdefaults;
514 if (
list_length(parameterDefaults) < oldproc->pronargdefaults)
516 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
517 errmsg(
"cannot remove parameter defaults from existing function"),
524 Anum_pg_proc_proargdefaults);
531 oldproc->pronargdefaults);
533 foreach(oldlc, oldDefaults)
540 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
541 errmsg(
"cannot change data type of existing parameter default value"),
546 newlc =
lnext(parameterDefaults, newlc);
554 replaces[Anum_pg_proc_oid - 1] =
false;
555 replaces[Anum_pg_proc_proowner - 1] =
false;
556 replaces[Anum_pg_proc_proacl - 1] =
false;
576 nulls[Anum_pg_proc_proacl - 1] =
true;
622 for (
i = 0;
i < allParamCount;
i++)
646 if (languageObjectId == SQLlanguageId && prosqlbody)
650 if (parameterDefaults)
677 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 PointerIsValid(pointer)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
elog(ERROR, "%s: %s", p2, msg)
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
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 equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
void CommandCounterIncrement(void)