88 Oid *prorettype_p,
bool *returnsSet_p)
100 if (languageOid == SQLlanguageId)
102 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
103 errmsg(
"SQL function cannot return shell type %s",
107 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
108 errmsg(
"return type %s is only a shell",
127 if (languageOid != INTERNALlanguageId &&
128 languageOid != ClanguageId)
130 (
errcode(ERRCODE_UNDEFINED_OBJECT),
131 errmsg(
"type \"%s\" does not exist", typnam)));
136 (
errcode(ERRCODE_SYNTAX_ERROR),
137 errmsg(
"type modifier cannot be specified for shell type \"%s\"",
142 (
errcode(ERRCODE_UNDEFINED_OBJECT),
143 errmsg(
"type \"%s\" is not yet defined", typnam),
144 errdetail(
"Creating a shell type definition.")));
161 *prorettype_p = rettype;
162 *returnsSet_p = returnType->
setof;
187 List **parameterTypes_list,
191 List **inParameterNames_list,
192 List **parameterDefaults,
193 Oid *variadicArgType,
194 Oid *requiredResultType)
204 bool have_names =
false;
205 bool have_defaults =
false;
216 *parameterDefaults =
NIL;
220 foreach(
x, parameters)
225 bool isinput =
false;
240 if (languageOid == SQLlanguageId)
242 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
243 errmsg(
"SQL function cannot accept shell type %s",
248 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
249 errmsg(
"aggregate cannot accept shell type %s",
253 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
254 errmsg(
"argument type %s is only a shell",
263 (
errcode(ERRCODE_UNDEFINED_OBJECT),
264 errmsg(
"type %s does not exist",
277 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
278 errmsg(
"aggregates cannot accept set arguments")));
281 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
282 errmsg(
"procedures cannot accept set arguments")));
285 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
286 errmsg(
"functions cannot accept set arguments")));
295 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
296 errmsg(
"VARIADIC parameter must be the last input parameter")));
297 inTypes[inCount++] = toid;
299 if (parameterTypes_list)
300 *parameterTypes_list =
lappend_oid(*parameterTypes_list, toid);
315 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
316 errmsg(
"VARIADIC parameter must be the last parameter")));
318 *requiredResultType = RECORDOID;
320 else if (outCount == 0)
321 *requiredResultType = toid;
327 *variadicArgType = toid;
333 case ANYCOMPATIBLEARRAYOID:
340 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
341 errmsg(
"VARIADIC parameter must be an array")));
360 foreach(
px, parameters)
368 prevfpmode = prevfp->
mode;
382 if (prevfp->
name && prevfp->
name[0] &&
383 strcmp(prevfp->
name, fp->
name) == 0)
385 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
386 errmsg(
"parameter name \"%s\" used more than once",
394 if (inParameterNames_list)
403 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
404 errmsg(
"only input parameters can have default values")));
418 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
419 errmsg(
"cannot use table references in parameter default value")));
435 *parameterDefaults =
lappend(*parameterDefaults, def);
436 have_defaults =
true;
440 if (isinput && have_defaults)
442 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
443 errmsg(
"input parameters after one with a default value must also have defaults")));
452 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
453 errmsg(
"procedure OUT parameters cannot appear after one with a default value")));
462 if (outCount > 0 || varCount > 0)
467 *requiredResultType = RECORDOID;
472 *allParameterTypes = NULL;
473 *parameterModes = NULL;
478 for (
i = 0;
i < parameterCount;
i++)
486 *parameterNames = NULL;
512 if (strcmp(defel->
defname,
"volatility") == 0)
515 goto procedure_error;
516 if (*volatility_item)
519 *volatility_item = defel;
521 else if (strcmp(defel->
defname,
"strict") == 0)
524 goto procedure_error;
528 *strict_item = defel;
530 else if (strcmp(defel->
defname,
"security") == 0)
535 *security_item = defel;
537 else if (strcmp(defel->
defname,
"leakproof") == 0)
540 goto procedure_error;
544 *leakproof_item = defel;
546 else if (strcmp(defel->
defname,
"set") == 0)
550 else if (strcmp(defel->
defname,
"cost") == 0)
553 goto procedure_error;
559 else if (strcmp(defel->
defname,
"rows") == 0)
562 goto procedure_error;
568 else if (strcmp(defel->
defname,
"support") == 0)
571 goto procedure_error;
575 *support_item = defel;
577 else if (strcmp(defel->
defname,
"parallel") == 0)
580 goto procedure_error;
584 *parallel_item = defel;
594 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
595 errmsg(
"invalid attribute in procedure definition"),
605 if (strcmp(
str,
"immutable") == 0)
606 return PROVOLATILE_IMMUTABLE;
607 else if (strcmp(
str,
"stable") == 0)
608 return PROVOLATILE_STABLE;
609 else if (strcmp(
str,
"volatile") == 0)
610 return PROVOLATILE_VOLATILE;
623 if (strcmp(
str,
"safe") == 0)
624 return PROPARALLEL_SAFE;
625 else if (strcmp(
str,
"unsafe") == 0)
626 return PROPARALLEL_UNSAFE;
627 else if (strcmp(
str,
"restricted") == 0)
628 return PROPARALLEL_RESTRICTED;
632 (
errcode(ERRCODE_SYNTAX_ERROR),
633 errmsg(
"parameter \"parallel\" must be SAFE, RESTRICTED, or UNSAFE")));
634 return PROPARALLEL_UNSAFE;
648 foreach(l, set_items)
679 argList[0] = INTERNALOID;
684 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
685 errmsg(
"function %s does not exist",
690 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
691 errmsg(
"support function %s must return type %s",
701 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
702 errmsg(
"must be superuser to specify a support function")));
722 bool *security_definer,
733 DefElem *transform_item = NULL;
734 DefElem *windowfunc_item = NULL;
735 DefElem *volatility_item = NULL;
738 DefElem *leakproof_item = NULL;
749 if (strcmp(defel->
defname,
"as") == 0)
755 else if (strcmp(defel->
defname,
"language") == 0)
759 language_item = defel;
761 else if (strcmp(defel->
defname,
"transform") == 0)
765 transform_item = defel;
767 else if (strcmp(defel->
defname,
"window") == 0)
773 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
774 errmsg(
"invalid attribute in procedure definition"),
776 windowfunc_item = defel;
795 elog(
ERROR,
"option \"%s\" not recognized",
804 *transform = transform_item->
arg;
806 *windowfunc_p =
boolVal(windowfunc_item->
arg);
812 *security_definer =
boolVal(security_item->
arg);
822 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
823 errmsg(
"COST must be positive")));
830 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
831 errmsg(
"ROWS must be positive")));
852 List *parameterTypes,
List *inParameterNames,
853 char **prosrc_str_p,
char **probin_str_p,
855 const char *queryString)
857 if (!sql_body_in && !as)
859 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
860 errmsg(
"no function body specified")));
862 if (sql_body_in && as)
864 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
865 errmsg(
"duplicate function body specified")));
867 if (sql_body_in && languageOid != SQLlanguageId)
869 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
870 errmsg(
"inline SQL function body only valid for language SQL")));
872 *sql_body_out = NULL;
874 if (languageOid == ClanguageId)
890 if (strcmp(*prosrc_str_p,
"-") == 0)
894 else if (sql_body_in)
909 if (IsPolymorphicType(pinfo->
argtypes[
i]))
911 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
912 errmsg(
"SQL function with unquoted function body cannot have polymorphic arguments")));
937 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
938 errmsg(
"%s is not yet supported in unquoted SQL function body",
940 transformed_stmts =
lappend(transformed_stmts, q);
956 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
957 errmsg(
"%s is not yet supported in unquoted SQL function body",
961 *sql_body_out = (
Node *) q;
974 *probin_str_p = NULL;
980 *probin_str_p = NULL;
984 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
985 errmsg(
"only one AS item needed for language \"%s\"",
988 if (languageOid == INTERNALlanguageId)
998 if (strlen(*prosrc_str_p) == 0)
1019 Oid languageValidator;
1020 Node *transformDefElem = NULL;
1025 List *parameterTypes_list =
NIL;
1029 List *inParameterNames_list =
NIL;
1030 List *parameterDefaults;
1031 Oid variadicArgType;
1034 Oid requiredResultType;
1062 isWindowFunc =
false;
1065 isLeakProof =
false;
1066 volatility = PROVOLATILE_VOLATILE;
1071 parallel = PROPARALLEL_UNSAFE;
1077 &as_clause, &language, &transformDefElem,
1078 &isWindowFunc, &volatility,
1079 &isStrict, &security, &isLeakProof,
1080 &proconfig, &procost, &prorows,
1081 &prosupport, ¶llel);
1089 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
1090 errmsg(
"no language specified")));
1097 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1098 errmsg(
"language \"%s\" does not exist", language),
1100 errhint(
"Use CREATE EXTENSION to load the language into the database.") : 0)));
1103 languageOid = languageStruct->oid;
1105 if (languageStruct->lanpltrusted)
1111 NameStr(languageStruct->lanname));
1118 NameStr(languageStruct->lanname));
1121 languageValidator = languageStruct->lanvalidator;
1132 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1133 errmsg(
"only superuser can define a leakproof function")));
1135 if (transformDefElem)
1145 typeid = elt ? elt :
typeid;
1148 trftypes_list =
lappend_oid(trftypes_list,
typeid);
1161 ¶meterTypes_list,
1165 &inParameterNames_list,
1168 &requiredResultType);
1170 if (
stmt->is_procedure)
1173 prorettype = requiredResultType ? requiredResultType : VOIDOID;
1176 else if (
stmt->returnType)
1180 &prorettype, &returnsSet);
1181 if (
OidIsValid(requiredResultType) && prorettype != requiredResultType)
1183 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
1184 errmsg(
"function result type must be %s because of OUT parameters",
1190 prorettype = requiredResultType;
1196 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
1197 errmsg(
"function result type must be specified")));
1199 prorettype = VOIDOID;
1203 if (trftypes_list !=
NIL)
1211 foreach(lc, trftypes_list)
1222 parameterTypes_list, inParameterNames_list,
1223 &prosrc_str, &probin_str, &prosqlbody,
1234 if (languageOid == INTERNALlanguageId ||
1235 languageOid == ClanguageId)
1247 else if (!returnsSet)
1249 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1250 errmsg(
"ROWS is not applicable when function does not return a set")));
1267 stmt->is_procedure ? PROKIND_PROCEDURE : (isWindowFunc ? PROKIND_WINDOW : PROKIND_FUNCTION),
1305 elog(
ERROR,
"cache lookup failed for function %u", funcOid);
1320 if (prokind == PROKIND_AGGREGATE)
1326 elog(
ERROR,
"cache lookup failed for pg_aggregate tuple for function %u", funcOid);
1350 DefElem *volatility_item = NULL;
1352 DefElem *security_def_item = NULL;
1353 DefElem *leakproof_item = NULL;
1358 DefElem *parallel_item = NULL;
1369 elog(
ERROR,
"cache lookup failed for function %u", funcOid);
1378 if (procForm->prokind == PROKIND_AGGREGATE)
1380 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1381 errmsg(
"\"%s\" is an aggregate function",
1384 is_procedure = (procForm->prokind == PROKIND_PROCEDURE);
1387 foreach(l,
stmt->actions)
1402 ¶llel_item) ==
false)
1406 if (volatility_item)
1409 procForm->proisstrict =
boolVal(strict_item->
arg);
1410 if (security_def_item)
1411 procForm->prosecdef =
boolVal(security_def_item->
arg);
1414 procForm->proleakproof =
boolVal(leakproof_item->
arg);
1415 if (procForm->proleakproof && !
superuser())
1417 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1418 errmsg(
"only superuser can define a leakproof function")));
1423 if (procForm->procost <= 0)
1425 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1426 errmsg(
"COST must be positive")));
1431 if (procForm->prorows <= 0)
1433 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1434 errmsg(
"ROWS must be positive")));
1435 if (!procForm->proretset)
1437 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1438 errmsg(
"ROWS is not applicable when function does not return a set")));
1449 ProcedureRelationId, procForm->prosupport,
1451 elog(
ERROR,
"could not change support dependency for function %s",
1458 referenced.
classId = ProcedureRelationId;
1464 procForm->prosupport = newsupport;
1473 Datum repl_val[Natts_pg_proc];
1474 bool repl_null[Natts_pg_proc];
1475 bool repl_repl[Natts_pg_proc];
1478 datum =
SysCacheGetAttr(PROCOID, tup, Anum_pg_proc_proconfig, &isnull);
1485 memset(repl_repl,
false,
sizeof(repl_repl));
1486 repl_repl[Anum_pg_proc_proconfig - 1] =
true;
1490 repl_val[Anum_pg_proc_proconfig - 1] = (
Datum) 0;
1491 repl_null[Anum_pg_proc_proconfig - 1] =
true;
1496 repl_null[Anum_pg_proc_proconfig - 1] =
false;
1500 repl_val, repl_null, repl_repl);
1542 if (sourcetyptype == TYPTYPE_PSEUDO)
1544 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1545 errmsg(
"source data type %s is a pseudo-type",
1548 if (targettyptype == TYPTYPE_PSEUDO)
1550 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1551 errmsg(
"target data type %s is a pseudo-type",
1558 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1559 errmsg(
"must be owner of type %s or type %s",
1572 if (sourcetyptype == TYPTYPE_DOMAIN)
1574 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1575 errmsg(
"cast will be ignored because the source data type is a domain")));
1577 else if (targettyptype == TYPTYPE_DOMAIN)
1579 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1580 errmsg(
"cast will be ignored because the target data type is a domain")));
1583 if (
stmt->func != NULL)
1584 castmethod = COERCION_METHOD_FUNCTION;
1585 else if (
stmt->inout)
1586 castmethod = COERCION_METHOD_INOUT;
1588 castmethod = COERCION_METHOD_BINARY;
1590 if (castmethod == COERCION_METHOD_FUNCTION)
1598 elog(
ERROR,
"cache lookup failed for function %u", funcid);
1601 nargs = procstruct->pronargs;
1602 if (nargs < 1 || nargs > 3)
1604 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1605 errmsg(
"cast function must take one to three arguments")));
1607 procstruct->proargtypes.values[0],
1610 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1611 errmsg(
"argument of cast function must match or be binary-coercible from source data type")));
1612 if (nargs > 1 && procstruct->proargtypes.values[1] != INT4OID)
1614 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1615 errmsg(
"second argument of cast function must be type %s",
1617 if (nargs > 2 && procstruct->proargtypes.values[2] != BOOLOID)
1619 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1620 errmsg(
"third argument of cast function must be type %s",
1626 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1627 errmsg(
"return data type of cast function must match or be binary-coercible to target data type")));
1635 if (procstruct->provolatile == PROVOLATILE_VOLATILE)
1637 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1638 errmsg(
"cast function must not be volatile")));
1640 if (procstruct->prokind != PROKIND_FUNCTION)
1642 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1643 errmsg(
"cast function must be a normal function")));
1644 if (procstruct->proretset)
1646 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1647 errmsg(
"cast function must not return a set")));
1657 if (castmethod == COERCION_METHOD_BINARY)
1672 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1673 errmsg(
"must be superuser to create a cast WITHOUT FUNCTION")));
1683 if (typ1len != typ2len ||
1684 typ1byval != typ2byval ||
1685 typ1align != typ2align)
1687 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1688 errmsg(
"source and target data types are not physically compatible")));
1699 if (sourcetyptype == TYPTYPE_COMPOSITE ||
1700 targettyptype == TYPTYPE_COMPOSITE)
1702 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1703 errmsg(
"composite data types are not binary-compatible")));
1705 if (sourcetyptype == TYPTYPE_ENUM ||
1706 targettyptype == TYPTYPE_ENUM)
1708 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1709 errmsg(
"enum data types are not binary-compatible")));
1714 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1715 errmsg(
"array data types are not binary-compatible")));
1728 if (sourcetyptype == TYPTYPE_DOMAIN ||
1729 targettyptype == TYPTYPE_DOMAIN)
1731 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1732 errmsg(
"domain data types must not be marked binary-compatible")));
1739 if (sourcetypeid == targettypeid && nargs < 2)
1741 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1742 errmsg(
"source data type and target data type are the same")));
1745 switch (
stmt->context)
1748 castcontext = COERCION_CODE_IMPLICIT;
1751 castcontext = COERCION_CODE_ASSIGNMENT;
1755 castcontext = COERCION_CODE_EXPLICIT;
1758 elog(
ERROR,
"unrecognized CoercionContext: %d",
stmt->context);
1763 myself =
CastCreate(sourcetypeid, targettypeid, funcid, incastid, outcastid,
1772 if (procstruct->provolatile == PROVOLATILE_VOLATILE)
1774 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1775 errmsg(
"transform function must not be volatile")));
1776 if (procstruct->prokind != PROKIND_FUNCTION)
1778 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1779 errmsg(
"transform function must be a normal function")));
1780 if (procstruct->proretset)
1782 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1783 errmsg(
"transform function must not return a set")));
1784 if (procstruct->pronargs != 1)
1786 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1787 errmsg(
"transform function must take one argument")));
1788 if (procstruct->proargtypes.values[0] != INTERNALOID)
1790 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1791 errmsg(
"first argument of transform function must be type %s",
1810 bool nulls[Natts_pg_transform] = {0};
1811 bool replaces[Natts_pg_transform] = {0};
1827 if (typtype == TYPTYPE_PSEUDO)
1829 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1830 errmsg(
"data type %s is a pseudo-type",
1833 if (typtype == TYPTYPE_DOMAIN)
1835 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1836 errmsg(
"data type %s is a domain",
1871 elog(
ERROR,
"cache lookup failed for function %u", fromsqlfuncid);
1873 if (procstruct->prorettype != INTERNALOID)
1875 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1876 errmsg(
"return data type of FROM SQL function must be %s",
1897 elog(
ERROR,
"cache lookup failed for function %u", tosqlfuncid);
1899 if (procstruct->prorettype !=
typeid)
1901 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1902 errmsg(
"return data type of TO SQL function must be the transform data type")));
1929 errmsg(
"transform for type %s language \"%s\" already exists",
1933 replaces[Anum_pg_transform_trffromsql - 1] =
true;
1934 replaces[Anum_pg_transform_trftosql - 1] =
true;
1939 transformid = form->oid;
1946 Anum_pg_transform_oid);
2014 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2015 errmsg(
"transform for type %s language \"%s\" does not exist",
2038 (
errcode(ERRCODE_DUPLICATE_FUNCTION),
2039 errmsg(
"function %s already exists in schema \"%s\"",
2057 DefElem *language_item = NULL;
2068 if (strcmp(defel->
defname,
"as") == 0)
2074 else if (strcmp(defel->
defname,
"language") == 0)
2078 language_item = defel;
2081 elog(
ERROR,
"option \"%s\" not recognized",
2089 (
errcode(ERRCODE_SYNTAX_ERROR),
2090 errmsg(
"no inline code specified")));
2096 language =
"plpgsql";
2102 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2103 errmsg(
"language \"%s\" does not exist", language),
2105 errhint(
"Use CREATE EXTENSION to load the language into the database.") : 0)));
2108 codeblock->
langOid = languageStruct->oid;
2110 codeblock->
atomic = atomic;
2112 if (languageStruct->lanpltrusted)
2121 NameStr(languageStruct->lanname));
2128 NameStr(languageStruct->lanname));
2132 laninline = languageStruct->laninline;
2135 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2136 errmsg(
"language \"%s\" does not support inline code execution",
2137 NameStr(languageStruct->lanname))));
2190 fexpr =
stmt->funcexpr;
2200 callcontext->
atomic = atomic;
2213 callcontext->
atomic =
true;
2222 callcontext->
atomic =
true;
2230 (
errcode(ERRCODE_TOO_MANY_ARGUMENTS),
2231 errmsg_plural(
"cannot pass more than %d argument to a procedure",
2232 "cannot pass more than %d arguments to a procedure",
2241 (
Node *) callcontext, NULL);
2262 foreach(lc, fexpr->
args)
2272 fcinfo->args[
i].value =
val;
2273 fcinfo->args[
i].isnull = isnull;
2288 if (fexpr->funcresulttype == VOIDOID)
2292 else if (fexpr->funcresulttype == RECORDOID)
2304 elog(
ERROR,
"procedure returned null record");
2341 elog(
ERROR,
"unexpected result type for procedure: %u",
2342 fexpr->funcresulttype);
2357 fexpr =
stmt->funcexpr;
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
#define DatumGetArrayTypeP(X)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
const char * GetCommandTagName(CommandTag commandTag)
List * defGetQualifiedName(DefElem *def)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
double defGetNumeric(DefElem *def)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, 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(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
ExprState * ExecPrepareExpr(Expr *node, EState *estate)
void end_tup_output(TupOutputState *tstate)
TupleTableSlot * ExecStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
const TupleTableSlotOps TTSOpsHeapTuple
TupOutputState * begin_tup_output_tupdesc(DestReceiver *dest, TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
EState * CreateExecutorState(void)
ExprContext * CreateExprContext(EState *estate)
void FreeExecutorState(EState *estate)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
bool extension_file_exists(const char *extensionName)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
#define OidFunctionCall1(functionId, arg1)
#define DatumGetHeapTupleHeader(X)
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
#define LOCAL_FCINFO(name, nargs)
#define FunctionCallInvoke(fcinfo)
#define fmgr_info_set_expr(expr, finfo)
TupleDesc build_function_result_tupdesc_t(HeapTuple procTuple)
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
ObjectAddress CreateCast(CreateCastStmt *stmt)
static ArrayType * update_proconfig_value(ArrayType *a, List *set_items)
static void compute_return_type(TypeName *returnType, Oid languageOid, Oid *prorettype_p, bool *returnsSet_p)
static Oid interpret_func_support(DefElem *defel)
static void compute_function_attributes(ParseState *pstate, bool is_procedure, List *options, List **as, char **language, Node **transform, bool *windowfunc_p, char *volatility_p, bool *strict_p, bool *security_definer, bool *leakproof_p, ArrayType **proconfig, float4 *procost, float4 *prorows, Oid *prosupport, char *parallel_p)
void interpret_function_parameter_list(ParseState *pstate, List *parameters, Oid languageOid, ObjectType objtype, oidvector **parameterTypes, List **parameterTypes_list, ArrayType **allParameterTypes, ArrayType **parameterModes, ArrayType **parameterNames, List **inParameterNames_list, List **parameterDefaults, Oid *variadicArgType, Oid *requiredResultType)
static bool compute_common_attribute(ParseState *pstate, bool is_procedure, DefElem *defel, DefElem **volatility_item, DefElem **strict_item, DefElem **security_item, DefElem **leakproof_item, List **set_items, DefElem **cost_item, DefElem **rows_item, DefElem **support_item, DefElem **parallel_item)
static char interpret_func_volatility(DefElem *defel)
ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
void IsThereFunctionInNamespace(const char *proname, int pronargs, oidvector *proargtypes, Oid nspOid)
ObjectAddress AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt)
TupleDesc CallStmtResultDesc(CallStmt *stmt)
static void interpret_AS_clause(Oid languageOid, const char *languageName, char *funcname, List *as, Node *sql_body_in, List *parameterTypes, List *inParameterNames, char **prosrc_str_p, char **probin_str_p, Node **sql_body_out, const char *queryString)
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
void ExecuteDoStmt(ParseState *pstate, DoStmt *stmt, bool atomic)
static void check_transform_function(Form_pg_proc procstruct)
ObjectAddress CreateTransform(CreateTransformStmt *stmt)
void RemoveFunctionById(Oid funcOid)
static char interpret_func_parallel(DefElem *defel)
void sql_fn_parser_setup(struct ParseState *pstate, SQLFunctionParseInfoPtr pinfo)
SQLFunctionParseInfo * SQLFunctionParseInfoPtr
void px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
ArrayType * GUCArrayAdd(ArrayType *array, const char *name, const char *value)
ArrayType * GUCArrayDelete(ArrayType *array, const char *name)
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
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)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
#define HeapTupleHeaderGetTypMod(tup)
#define HeapTupleHeaderGetTypeId(tup)
#define HeapTupleHeaderGetDatumLength(tup)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
if(TABLE==NULL||TABLE_index==NULL)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
char * get_language_name(Oid langoid, bool missing_ok)
Oid get_element_type(Oid typid)
char * get_namespace_name(Oid nspid)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
char * get_func_name(Oid funcid)
char get_typtype(Oid typid)
Oid get_base_element_type(Oid typid)
Oid get_func_rettype(Oid funcid)
char * pstrdup(const char *in)
void * palloc0(Size size)
Oid QualifiedNameGetCreationNamespace(const List *names, char **objname_p)
char * NameListToString(const List *names)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
#define InvokeFunctionExecuteHook(objectId)
#define ObjectAddressSet(addr, class_id, object_id)
oidvector * buildoidvector(const Oid *oids, int n)
Node * coerce_to_specific_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *constructName)
bool IsBinaryCoercibleWithCast(Oid srctype, Oid targettype, Oid *castoid)
void assign_expr_collations(ParseState *pstate, Node *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
const char * func_signature_string(List *funcname, int nargs, List *argnames, const Oid *argtypes)
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
const char * funcname_signature_string(const char *funcname, int nargs, List *argnames, const Oid *argtypes)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
void free_parsestate(ParseState *pstate)
int parser_errposition(ParseState *pstate, int location)
ParseState * make_parsestate(ParseState *parentParseState)
@ EXPR_KIND_FUNCTION_DEFAULT
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
char * TypeNameToString(const TypeName *typeName)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Query * transformStmt(ParseState *pstate, Node *parseTree)
ObjectAddress CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, Oid incastid, Oid outcastid, char castcontext, char castmethod, DependencyType behavior)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
FormData_pg_language * Form_pg_language
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
static Oid list_nth_oid(const List *list, int n)
static void * list_nth(const List *list, int n)
ObjectAddress ProcedureCreate(const char *procedureName, Oid procNamespace, bool replace, bool returnsSet, Oid returnType, Oid proowner, Oid languageObjectId, Oid languageValidator, const char *prosrc, const char *probin, Node *prosqlbody, char prokind, bool security_definer, bool isLeakProof, bool isStrict, char volatility, char parallel, oidvector *parameterTypes, Datum allParameterTypes, Datum parameterModes, Datum parameterNames, List *parameterDefaults, Datum trftypes, Datum proconfig, Oid prosupport, float4 procost, float4 prorows)
FormData_pg_proc * Form_pg_proc
ObjectAddress TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
FormData_pg_type * Form_pg_type
void pgstat_drop_function(Oid proid)
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum CharGetDatum(char X)
void EnsurePortalSnapshotExists(void)
Oid get_language_oid(const char *langname, bool missing_ok)
#define RelationGetDescr(relation)
Snapshot GetTransactionSnapshot(void)
void PushActiveSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
#define ERRCODE_DUPLICATE_OBJECT
ParamListInfo es_param_list_info
FunctionParameterMode mode
const char * p_sourcetext
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Oid values[FLEXIBLE_ARRAY_MEMBER]
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
#define SearchSysCacheCopy1(cacheId, key1)
#define SearchSysCacheExists3(cacheId, key1, key2, key3)
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
#define ReleaseTupleDesc(tupdesc)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
CommandTag CreateCommandTag(Node *parsetree)
String * makeString(char *str)
bool contain_var_clause(Node *node)