71 #include "utils/fmgroids.h"
94 Oid *prorettype_p,
bool *returnsSet_p)
106 if (languageOid == SQLlanguageId)
108 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
109 errmsg(
"SQL function cannot return shell type %s",
113 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
114 errmsg(
"return type %s is only a shell",
133 if (languageOid != INTERNALlanguageId &&
134 languageOid != ClanguageId)
136 (
errcode(ERRCODE_UNDEFINED_OBJECT),
137 errmsg(
"type \"%s\" does not exist", typnam)));
142 (
errcode(ERRCODE_SYNTAX_ERROR),
143 errmsg(
"type modifier cannot be specified for shell type \"%s\"",
148 (
errcode(ERRCODE_UNDEFINED_OBJECT),
149 errmsg(
"type \"%s\" is not yet defined", typnam),
150 errdetail(
"Creating a shell type definition.")));
167 *prorettype_p = rettype;
168 *returnsSet_p = returnType->
setof;
193 List **parameterTypes_list,
197 List **inParameterNames_list,
198 List **parameterDefaults,
199 Oid *variadicArgType,
200 Oid *requiredResultType)
210 bool have_names =
false;
211 bool have_defaults =
false;
222 *parameterDefaults =
NIL;
226 foreach(
x, parameters)
231 bool isinput =
false;
246 if (languageOid == SQLlanguageId)
248 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
249 errmsg(
"SQL function cannot accept shell type %s",
254 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
255 errmsg(
"aggregate cannot accept shell type %s",
259 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
260 errmsg(
"argument type %s is only a shell",
269 (
errcode(ERRCODE_UNDEFINED_OBJECT),
270 errmsg(
"type %s does not exist",
283 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
284 errmsg(
"aggregates cannot accept set arguments")));
287 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
288 errmsg(
"procedures cannot accept set arguments")));
291 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
292 errmsg(
"functions cannot accept set arguments")));
301 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
302 errmsg(
"VARIADIC parameter must be the last input parameter")));
303 inTypes[inCount++] = toid;
305 if (parameterTypes_list)
306 *parameterTypes_list =
lappend_oid(*parameterTypes_list, toid);
321 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
322 errmsg(
"VARIADIC parameter must be the last parameter")));
324 *requiredResultType = RECORDOID;
326 else if (outCount == 0)
327 *requiredResultType = toid;
333 *variadicArgType = toid;
339 case ANYCOMPATIBLEARRAYOID:
346 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
347 errmsg(
"VARIADIC parameter must be an array")));
366 foreach(
px, parameters)
374 prevfpmode = prevfp->
mode;
388 if (prevfp->
name && prevfp->
name[0] &&
389 strcmp(prevfp->
name, fp->
name) == 0)
391 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
392 errmsg(
"parameter name \"%s\" used more than once",
400 if (inParameterNames_list)
409 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
410 errmsg(
"only input parameters can have default values")));
424 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
425 errmsg(
"cannot use table references in parameter default value")));
441 *parameterDefaults =
lappend(*parameterDefaults, def);
442 have_defaults =
true;
446 if (isinput && have_defaults)
448 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
449 errmsg(
"input parameters after one with a default value must also have defaults")));
458 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
459 errmsg(
"procedure OUT parameters cannot appear after one with a default value")));
468 if (outCount > 0 || varCount > 0)
473 *requiredResultType = RECORDOID;
478 *allParameterTypes = NULL;
479 *parameterModes = NULL;
484 for (
i = 0;
i < parameterCount;
i++)
492 *parameterNames = NULL;
518 if (strcmp(defel->
defname,
"volatility") == 0)
521 goto procedure_error;
522 if (*volatility_item)
525 *volatility_item = defel;
527 else if (strcmp(defel->
defname,
"strict") == 0)
530 goto procedure_error;
534 *strict_item = defel;
536 else if (strcmp(defel->
defname,
"security") == 0)
541 *security_item = defel;
543 else if (strcmp(defel->
defname,
"leakproof") == 0)
546 goto procedure_error;
550 *leakproof_item = defel;
552 else if (strcmp(defel->
defname,
"set") == 0)
556 else if (strcmp(defel->
defname,
"cost") == 0)
559 goto procedure_error;
565 else if (strcmp(defel->
defname,
"rows") == 0)
568 goto procedure_error;
574 else if (strcmp(defel->
defname,
"support") == 0)
577 goto procedure_error;
581 *support_item = defel;
583 else if (strcmp(defel->
defname,
"parallel") == 0)
586 goto procedure_error;
590 *parallel_item = defel;
600 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
601 errmsg(
"invalid attribute in procedure definition"),
611 if (strcmp(
str,
"immutable") == 0)
612 return PROVOLATILE_IMMUTABLE;
613 else if (strcmp(
str,
"stable") == 0)
614 return PROVOLATILE_STABLE;
615 else if (strcmp(
str,
"volatile") == 0)
616 return PROVOLATILE_VOLATILE;
629 if (strcmp(
str,
"safe") == 0)
630 return PROPARALLEL_SAFE;
631 else if (strcmp(
str,
"unsafe") == 0)
632 return PROPARALLEL_UNSAFE;
633 else if (strcmp(
str,
"restricted") == 0)
634 return PROPARALLEL_RESTRICTED;
638 (
errcode(ERRCODE_SYNTAX_ERROR),
639 errmsg(
"parameter \"parallel\" must be SAFE, RESTRICTED, or UNSAFE")));
640 return PROPARALLEL_UNSAFE;
654 foreach(l, set_items)
685 argList[0] = INTERNALOID;
690 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
691 errmsg(
"function %s does not exist",
696 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
697 errmsg(
"support function %s must return type %s",
707 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
708 errmsg(
"must be superuser to specify a support function")));
728 bool *security_definer,
739 DefElem *transform_item = NULL;
740 DefElem *windowfunc_item = NULL;
741 DefElem *volatility_item = NULL;
744 DefElem *leakproof_item = NULL;
755 if (strcmp(defel->
defname,
"as") == 0)
761 else if (strcmp(defel->
defname,
"language") == 0)
765 language_item = defel;
767 else if (strcmp(defel->
defname,
"transform") == 0)
771 transform_item = defel;
773 else if (strcmp(defel->
defname,
"window") == 0)
779 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
780 errmsg(
"invalid attribute in procedure definition"),
782 windowfunc_item = defel;
801 elog(
ERROR,
"option \"%s\" not recognized",
810 *transform = transform_item->
arg;
812 *windowfunc_p =
boolVal(windowfunc_item->
arg);
818 *security_definer =
boolVal(security_item->
arg);
828 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
829 errmsg(
"COST must be positive")));
836 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
837 errmsg(
"ROWS must be positive")));
858 List *parameterTypes,
List *inParameterNames,
859 char **prosrc_str_p,
char **probin_str_p,
861 const char *queryString)
863 if (!sql_body_in && !as)
865 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
866 errmsg(
"no function body specified")));
868 if (sql_body_in && as)
870 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
871 errmsg(
"duplicate function body specified")));
873 if (sql_body_in && languageOid != SQLlanguageId)
875 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
876 errmsg(
"inline SQL function body only valid for language SQL")));
878 *sql_body_out = NULL;
880 if (languageOid == ClanguageId)
896 if (strcmp(*prosrc_str_p,
"-") == 0)
900 else if (sql_body_in)
915 if (IsPolymorphicType(pinfo->
argtypes[
i]))
917 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
918 errmsg(
"SQL function with unquoted function body cannot have polymorphic arguments")));
943 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
944 errmsg(
"%s is not yet supported in unquoted SQL function body",
946 transformed_stmts =
lappend(transformed_stmts, q);
962 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
963 errmsg(
"%s is not yet supported in unquoted SQL function body",
967 *sql_body_out = (
Node *) q;
980 *probin_str_p = NULL;
986 *probin_str_p = NULL;
990 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
991 errmsg(
"only one AS item needed for language \"%s\"",
994 if (languageOid == INTERNALlanguageId)
1004 if (strlen(*prosrc_str_p) == 0)
1025 Oid languageValidator;
1026 Node *transformDefElem = NULL;
1031 List *parameterTypes_list =
NIL;
1035 List *inParameterNames_list =
NIL;
1036 List *parameterDefaults;
1037 Oid variadicArgType;
1040 Oid requiredResultType;
1068 isWindowFunc =
false;
1071 isLeakProof =
false;
1072 volatility = PROVOLATILE_VOLATILE;
1077 parallel = PROPARALLEL_UNSAFE;
1083 &as_clause, &language, &transformDefElem,
1084 &isWindowFunc, &volatility,
1085 &isStrict, &security, &isLeakProof,
1086 &proconfig, &procost, &prorows,
1087 &prosupport, ¶llel);
1095 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
1096 errmsg(
"no language specified")));
1103 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1104 errmsg(
"language \"%s\" does not exist", language),
1106 errhint(
"Use CREATE EXTENSION to load the language into the database.") : 0)));
1109 languageOid = languageStruct->oid;
1111 if (languageStruct->lanpltrusted)
1117 NameStr(languageStruct->lanname));
1124 NameStr(languageStruct->lanname));
1127 languageValidator = languageStruct->lanvalidator;
1138 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1139 errmsg(
"only superuser can define a leakproof function")));
1141 if (transformDefElem)
1151 typeid = elt ? elt :
typeid;
1154 trftypes_list =
lappend_oid(trftypes_list,
typeid);
1167 ¶meterTypes_list,
1171 &inParameterNames_list,
1174 &requiredResultType);
1176 if (
stmt->is_procedure)
1179 prorettype = requiredResultType ? requiredResultType : VOIDOID;
1182 else if (
stmt->returnType)
1186 &prorettype, &returnsSet);
1187 if (
OidIsValid(requiredResultType) && prorettype != requiredResultType)
1189 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
1190 errmsg(
"function result type must be %s because of OUT parameters",
1196 prorettype = requiredResultType;
1202 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
1203 errmsg(
"function result type must be specified")));
1205 prorettype = VOIDOID;
1209 if (trftypes_list !=
NIL)
1217 foreach(lc, trftypes_list)
1228 parameterTypes_list, inParameterNames_list,
1229 &prosrc_str, &probin_str, &prosqlbody,
1240 if (languageOid == INTERNALlanguageId ||
1241 languageOid == ClanguageId)
1253 else if (!returnsSet)
1255 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1256 errmsg(
"ROWS is not applicable when function does not return a set")));
1273 stmt->is_procedure ? PROKIND_PROCEDURE : (isWindowFunc ? PROKIND_WINDOW : PROKIND_FUNCTION),
1311 elog(
ERROR,
"cache lookup failed for function %u", funcOid);
1326 if (prokind == PROKIND_AGGREGATE)
1332 elog(
ERROR,
"cache lookup failed for pg_aggregate tuple for function %u", funcOid);
1356 DefElem *volatility_item = NULL;
1358 DefElem *security_def_item = NULL;
1359 DefElem *leakproof_item = NULL;
1364 DefElem *parallel_item = NULL;
1375 elog(
ERROR,
"cache lookup failed for function %u", funcOid);
1384 if (procForm->prokind == PROKIND_AGGREGATE)
1386 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1387 errmsg(
"\"%s\" is an aggregate function",
1390 is_procedure = (procForm->prokind == PROKIND_PROCEDURE);
1393 foreach(l,
stmt->actions)
1408 ¶llel_item) ==
false)
1412 if (volatility_item)
1415 procForm->proisstrict =
boolVal(strict_item->
arg);
1416 if (security_def_item)
1417 procForm->prosecdef =
boolVal(security_def_item->
arg);
1420 procForm->proleakproof =
boolVal(leakproof_item->
arg);
1421 if (procForm->proleakproof && !
superuser())
1423 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1424 errmsg(
"only superuser can define a leakproof function")));
1429 if (procForm->procost <= 0)
1431 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1432 errmsg(
"COST must be positive")));
1437 if (procForm->prorows <= 0)
1439 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1440 errmsg(
"ROWS must be positive")));
1441 if (!procForm->proretset)
1443 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1444 errmsg(
"ROWS is not applicable when function does not return a set")));
1455 ProcedureRelationId, procForm->prosupport,
1457 elog(
ERROR,
"could not change support dependency for function %s",
1464 referenced.
classId = ProcedureRelationId;
1470 procForm->prosupport = newsupport;
1479 Datum repl_val[Natts_pg_proc];
1480 bool repl_null[Natts_pg_proc];
1481 bool repl_repl[Natts_pg_proc];
1491 memset(repl_repl,
false,
sizeof(repl_repl));
1492 repl_repl[Anum_pg_proc_proconfig - 1] =
true;
1496 repl_val[Anum_pg_proc_proconfig - 1] = (
Datum) 0;
1497 repl_null[Anum_pg_proc_proconfig - 1] =
true;
1502 repl_null[Anum_pg_proc_proconfig - 1] =
false;
1506 repl_val, repl_null, repl_repl);
1548 if (sourcetyptype == TYPTYPE_PSEUDO)
1550 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1551 errmsg(
"source data type %s is a pseudo-type",
1554 if (targettyptype == TYPTYPE_PSEUDO)
1556 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1557 errmsg(
"target data type %s is a pseudo-type",
1564 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1565 errmsg(
"must be owner of type %s or type %s",
1578 if (sourcetyptype == TYPTYPE_DOMAIN)
1580 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1581 errmsg(
"cast will be ignored because the source data type is a domain")));
1583 else if (targettyptype == TYPTYPE_DOMAIN)
1585 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1586 errmsg(
"cast will be ignored because the target data type is a domain")));
1589 if (
stmt->func != NULL)
1590 castmethod = COERCION_METHOD_FUNCTION;
1591 else if (
stmt->inout)
1592 castmethod = COERCION_METHOD_INOUT;
1594 castmethod = COERCION_METHOD_BINARY;
1596 if (castmethod == COERCION_METHOD_FUNCTION)
1604 elog(
ERROR,
"cache lookup failed for function %u", funcid);
1607 nargs = procstruct->pronargs;
1608 if (nargs < 1 || nargs > 3)
1610 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1611 errmsg(
"cast function must take one to three arguments")));
1613 procstruct->proargtypes.values[0],
1616 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1617 errmsg(
"argument of cast function must match or be binary-coercible from source data type")));
1618 if (nargs > 1 && procstruct->proargtypes.values[1] != INT4OID)
1620 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1621 errmsg(
"second argument of cast function must be type %s",
1623 if (nargs > 2 && procstruct->proargtypes.values[2] != BOOLOID)
1625 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1626 errmsg(
"third argument of cast function must be type %s",
1632 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1633 errmsg(
"return data type of cast function must match or be binary-coercible to target data type")));
1641 if (procstruct->provolatile == PROVOLATILE_VOLATILE)
1643 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1644 errmsg(
"cast function must not be volatile")));
1646 if (procstruct->prokind != PROKIND_FUNCTION)
1648 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1649 errmsg(
"cast function must be a normal function")));
1650 if (procstruct->proretset)
1652 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1653 errmsg(
"cast function must not return a set")));
1663 if (castmethod == COERCION_METHOD_BINARY)
1678 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1679 errmsg(
"must be superuser to create a cast WITHOUT FUNCTION")));
1689 if (typ1len != typ2len ||
1690 typ1byval != typ2byval ||
1691 typ1align != typ2align)
1693 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1694 errmsg(
"source and target data types are not physically compatible")));
1705 if (sourcetyptype == TYPTYPE_COMPOSITE ||
1706 targettyptype == TYPTYPE_COMPOSITE)
1708 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1709 errmsg(
"composite data types are not binary-compatible")));
1711 if (sourcetyptype == TYPTYPE_ENUM ||
1712 targettyptype == TYPTYPE_ENUM)
1714 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1715 errmsg(
"enum data types are not binary-compatible")));
1720 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1721 errmsg(
"array data types are not binary-compatible")));
1734 if (sourcetyptype == TYPTYPE_DOMAIN ||
1735 targettyptype == TYPTYPE_DOMAIN)
1737 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1738 errmsg(
"domain data types must not be marked binary-compatible")));
1745 if (sourcetypeid == targettypeid && nargs < 2)
1747 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1748 errmsg(
"source data type and target data type are the same")));
1751 switch (
stmt->context)
1754 castcontext = COERCION_CODE_IMPLICIT;
1757 castcontext = COERCION_CODE_ASSIGNMENT;
1761 castcontext = COERCION_CODE_EXPLICIT;
1764 elog(
ERROR,
"unrecognized CoercionContext: %d",
stmt->context);
1769 myself =
CastCreate(sourcetypeid, targettypeid, funcid, incastid, outcastid,
1778 if (procstruct->provolatile == PROVOLATILE_VOLATILE)
1780 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1781 errmsg(
"transform function must not be volatile")));
1782 if (procstruct->prokind != PROKIND_FUNCTION)
1784 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1785 errmsg(
"transform function must be a normal function")));
1786 if (procstruct->proretset)
1788 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1789 errmsg(
"transform function must not return a set")));
1790 if (procstruct->pronargs != 1)
1792 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1793 errmsg(
"transform function must take one argument")));
1794 if (procstruct->proargtypes.values[0] != INTERNALOID)
1796 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1797 errmsg(
"first argument of transform function must be type %s",
1816 bool nulls[Natts_pg_transform] = {0};
1817 bool replaces[Natts_pg_transform] = {0};
1833 if (typtype == TYPTYPE_PSEUDO)
1835 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1836 errmsg(
"data type %s is a pseudo-type",
1839 if (typtype == TYPTYPE_DOMAIN)
1841 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1842 errmsg(
"data type %s is a domain",
1877 elog(
ERROR,
"cache lookup failed for function %u", fromsqlfuncid);
1879 if (procstruct->prorettype != INTERNALOID)
1881 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1882 errmsg(
"return data type of FROM SQL function must be %s",
1903 elog(
ERROR,
"cache lookup failed for function %u", tosqlfuncid);
1905 if (procstruct->prorettype !=
typeid)
1907 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1908 errmsg(
"return data type of TO SQL function must be the transform data type")));
1935 errmsg(
"transform for type %s language \"%s\" already exists",
1939 replaces[Anum_pg_transform_trffromsql - 1] =
true;
1940 replaces[Anum_pg_transform_trftosql - 1] =
true;
1945 transformid = form->oid;
1952 Anum_pg_transform_oid);
2020 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2021 errmsg(
"transform for type %s language \"%s\" does not exist",
2044 (
errcode(ERRCODE_DUPLICATE_FUNCTION),
2045 errmsg(
"function %s already exists in schema \"%s\"",
2063 DefElem *language_item = NULL;
2074 if (strcmp(defel->
defname,
"as") == 0)
2080 else if (strcmp(defel->
defname,
"language") == 0)
2084 language_item = defel;
2087 elog(
ERROR,
"option \"%s\" not recognized",
2095 (
errcode(ERRCODE_SYNTAX_ERROR),
2096 errmsg(
"no inline code specified")));
2102 language =
"plpgsql";
2108 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2109 errmsg(
"language \"%s\" does not exist", language),
2111 errhint(
"Use CREATE EXTENSION to load the language into the database.") : 0)));
2114 codeblock->
langOid = languageStruct->oid;
2116 codeblock->
atomic = atomic;
2118 if (languageStruct->lanpltrusted)
2127 NameStr(languageStruct->lanname));
2134 NameStr(languageStruct->lanname));
2138 laninline = languageStruct->laninline;
2141 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2142 errmsg(
"language \"%s\" does not support inline code execution",
2143 NameStr(languageStruct->lanname))));
2196 fexpr =
stmt->funcexpr;
2206 callcontext->
atomic = atomic;
2219 callcontext->
atomic =
true;
2228 callcontext->
atomic =
true;
2236 (
errcode(ERRCODE_TOO_MANY_ARGUMENTS),
2237 errmsg_plural(
"cannot pass more than %d argument to a procedure",
2238 "cannot pass more than %d arguments to a procedure",
2247 (
Node *) callcontext, NULL);
2268 foreach(lc, fexpr->
args)
2278 fcinfo->args[
i].value =
val;
2279 fcinfo->args[
i].isnull = isnull;
2294 if (fexpr->funcresulttype == VOIDOID)
2298 else if (fexpr->funcresulttype == RECORDOID)
2310 elog(
ERROR,
"procedure returned null record");
2347 elog(
ERROR,
"unexpected result type for procedure: %u",
2348 fexpr->funcresulttype);
2363 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)
elog(ERROR, "%s: %s", p2, msg)
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_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
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)