63 #include "utils/fmgroids.h"
126 bool reject_indirect,
130 char *origSchemaName,
140 const char *initialVersion,
141 List *updateVersions,
142 char *origSchemaName,
167 (
errcode(ERRCODE_UNDEFINED_OBJECT),
168 errmsg(
"extension \"%s\" does not exist",
224 int namelen = strlen(extensionname);
232 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
233 errmsg(
"invalid extension name: \"%s\"", extensionname),
234 errdetail(
"Extension names must not be empty.")));
239 if (strstr(extensionname,
"--"))
241 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
242 errmsg(
"invalid extension name: \"%s\"", extensionname),
243 errdetail(
"Extension names must not contain \"--\".")));
251 if (extensionname[0] ==
'-' || extensionname[namelen - 1] ==
'-')
253 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
254 errmsg(
"invalid extension name: \"%s\"", extensionname),
255 errdetail(
"Extension names must not begin or end with \"-\".")));
263 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
264 errmsg(
"invalid extension name: \"%s\"", extensionname),
265 errdetail(
"Extension names must not contain directory separator characters.")));
271 int namelen = strlen(versionname);
279 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
280 errmsg(
"invalid extension version name: \"%s\"", versionname),
281 errdetail(
"Version names must not be empty.")));
286 if (strstr(versionname,
"--"))
288 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
289 errmsg(
"invalid extension version name: \"%s\"", versionname),
290 errdetail(
"Version names must not contain \"--\".")));
295 if (versionname[0] ==
'-' || versionname[namelen - 1] ==
'-')
297 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
298 errmsg(
"invalid extension version name: \"%s\"", versionname),
299 errdetail(
"Version names must not begin or end with \"-\".")));
307 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
308 errmsg(
"invalid extension version name: \"%s\"", versionname),
309 errdetail(
"Version names must not contain directory separator characters.")));
318 const char *extension = strrchr(
filename,
'.');
320 return (extension != NULL) && (strcmp(extension,
".control") == 0);
326 const char *extension = strrchr(
filename,
'.');
328 return (extension != NULL) && (strcmp(extension,
".sql") == 0);
392 scriptdir, control->
name, version);
401 const char *from_version,
const char *version)
411 scriptdir, control->
name, from_version, version);
414 scriptdir, control->
name, version);
462 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
463 errmsg(
"extension \"%s\" is not available", control->
name),
464 errdetail(
"Could not open extension control file \"%s\": %m.",
466 errhint(
"The extension must first be installed on the system where PostgreSQL is running.")));
470 errmsg(
"could not open extension control file \"%s\": %m",
486 for (item = head; item != NULL; item = item->
next)
488 if (strcmp(item->
name,
"directory") == 0)
492 (
errcode(ERRCODE_SYNTAX_ERROR),
493 errmsg(
"parameter \"%s\" cannot be set in a secondary extension control file",
498 else if (strcmp(item->
name,
"default_version") == 0)
502 (
errcode(ERRCODE_SYNTAX_ERROR),
503 errmsg(
"parameter \"%s\" cannot be set in a secondary extension control file",
508 else if (strcmp(item->
name,
"module_pathname") == 0)
512 else if (strcmp(item->
name,
"comment") == 0)
516 else if (strcmp(item->
name,
"schema") == 0)
520 else if (strcmp(item->
name,
"relocatable") == 0)
524 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
525 errmsg(
"parameter \"%s\" requires a Boolean value",
528 else if (strcmp(item->
name,
"superuser") == 0)
532 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
533 errmsg(
"parameter \"%s\" requires a Boolean value",
536 else if (strcmp(item->
name,
"trusted") == 0)
540 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
541 errmsg(
"parameter \"%s\" requires a Boolean value",
544 else if (strcmp(item->
name,
"encoding") == 0)
549 (
errcode(ERRCODE_UNDEFINED_OBJECT),
550 errmsg(
"\"%s\" is not a valid encoding name",
553 else if (strcmp(item->
name,
"requires") == 0)
563 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
564 errmsg(
"parameter \"%s\" must be a list of extension names",
568 else if (strcmp(item->
name,
"no_relocate") == 0)
578 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
579 errmsg(
"parameter \"%s\" must be a list of extension names",
585 (
errcode(ERRCODE_SYNTAX_ERROR),
586 errmsg(
"unrecognized parameter \"%s\" in file \"%s\"",
594 (
errcode(ERRCODE_SYNTAX_ERROR),
595 errmsg(
"parameter \"schema\" cannot be specified when \"relocatable\" is true")));
692 const char *query = callback_arg->
sql;
695 int syntaxerrposition;
696 const char *lastslash;
708 if (syntaxerrposition > 0)
717 if (location < 0 || syntaxerrposition < location ||
718 (
len > 0 && syntaxerrposition > location +
len))
728 int slen = strlen(query);
731 for (
int loc = 0; loc < slen; loc++)
733 if (query[loc] !=
';')
735 if (query[loc + 1] ==
'\r')
737 if (query[loc + 1] ==
'\n')
741 if (bkpt < syntaxerrposition)
743 else if (bkpt > syntaxerrposition)
745 len = bkpt - location;
759 syntaxerrposition -= location;
760 if (syntaxerrposition < 0)
761 syntaxerrposition = 0;
762 else if (syntaxerrposition >
len)
763 syntaxerrposition =
len;
770 else if (location >= 0)
785 lastslash = strrchr(callback_arg->
filename,
'/');
799 for (query = callback_arg->
sql; *query; query++)
806 errcontext(
"extension script file \"%s\", near line %d",
807 lastslash, linenumber);
810 errcontext(
"extension script file \"%s\"", lastslash);
831 List *raw_parsetree_list;
838 callback_arg.
sql = sql;
844 scripterrcontext.
arg = (
void *) &callback_arg;
861 foreach(lc1, raw_parsetree_list)
877 per_parsetree_context =
879 "execute_sql_string per-statement context",
893 foreach(lc2, stmt_list)
901 if (
stmt->utilityStmt == NULL)
908 dest, NULL, NULL, 0);
921 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
922 errmsg(
"transaction control statements are not allowed within an extension script")));
978 const char *from_version,
980 List *requiredSchemas,
981 const char *schemaName,
Oid schemaOid)
983 bool switch_to_superuser =
false;
986 int save_sec_context = 0;
1000 switch_to_superuser =
true;
1001 else if (from_version == NULL)
1003 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1004 errmsg(
"permission denied to create extension \"%s\"",
1007 ?
errhint(
"Must have CREATE privilege on current database to create this extension.")
1008 :
errhint(
"Must be superuser to create this extension.")));
1011 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1012 errmsg(
"permission denied to update extension \"%s\"",
1015 ?
errhint(
"Must have CREATE privilege on current database to update this extension.")
1016 :
errhint(
"Must be superuser to update this extension.")));
1021 if (from_version == NULL)
1022 elog(
DEBUG1,
"executing extension script for \"%s\" version '%s'", control->
name, version);
1024 elog(
DEBUG1,
"executing extension script for \"%s\" update from version '%s' to '%s'", control->
name, from_version, version);
1031 if (switch_to_superuser)
1059 BOOTSTRAP_SUPERUSERID,
1081 foreach(lc, requiredSchemas)
1086 if (reqname && strcmp(reqname,
"pg_catalog") != 0)
1115 const char *quoting_relevant_chars =
"\"$'\\";
1135 if (strstr(c_sql,
"@extowner@"))
1137 Oid uid = switch_to_superuser ? save_userid :
GetUserId();
1146 if (strpbrk(userName, quoting_relevant_chars))
1148 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1149 errmsg(
"invalid character in extension owner: must not contain any of \"%s\"",
1150 quoting_relevant_chars)));
1170 if (t_sql != old && strpbrk(schemaName, quoting_relevant_chars))
1172 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1173 errmsg(
"invalid character in extension \"%s\" schema: must not contain any of \"%s\"",
1174 control->
name, quoting_relevant_chars)));
1185 char *reqextname = (
char *)
lfirst(lc);
1191 repltoken =
psprintf(
"@extschema:%s@", reqextname);
1197 if (t_sql != old && strpbrk(schemaName, quoting_relevant_chars))
1199 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1200 errmsg(
"invalid character in extension \"%s\" schema: must not contain any of \"%s\"",
1201 reqextname, quoting_relevant_chars)));
1237 if (switch_to_superuser)
1255 foreach(lc, *evi_list)
1258 if (strcmp(evi->
name, versionname) == 0)
1271 *evi_list =
lappend(*evi_list, evi);
1288 foreach(lc, evi_list)
1314 int extnamelen = strlen(control->
name);
1321 while ((de =
ReadDir(dir, location)) != NULL)
1333 if (strncmp(de->
d_name, control->
name, extnamelen) != 0 ||
1334 de->
d_name[extnamelen] !=
'-' ||
1335 de->
d_name[extnamelen + 1] !=
'-')
1340 *strrchr(vername,
'.') =
'\0';
1341 vername2 = strstr(vername,
"--");
1353 if (strstr(vername2,
"--"))
1375 const char *oldVersion,
const char *newVersion)
1394 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1395 errmsg(
"extension \"%s\" has no update path from version \"%s\" to version \"%s\"",
1396 control->
name, oldVersion, newVersion)));
1420 bool reject_indirect,
1428 Assert(evi_start != evi_target);
1434 foreach(lc, evi_list)
1450 if (evi == evi_target)
1461 if (newdist < evi2->distance)
1466 else if (newdist == evi2->
distance &&
1489 for (evi = evi_target; evi != evi_start; evi = evi->
previous)
1526 foreach(lc, evi_list)
1543 if (evi_start == NULL ||
1546 strcmp(evi_start->
name, evi1->
name) < 0))
1567 const char *versionName,
1572 char *origSchemaName = schemaName;
1579 List *updateVersions;
1580 List *requiredExtensions;
1581 List *requiredSchemas;
1596 if (versionName == NULL)
1602 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1603 errmsg(
"version to install must be specified")));
1617 updateVersions =
NIL;
1637 if (evi_start == NULL)
1639 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1640 errmsg(
"extension \"%s\" has no installation script nor update path for version \"%s\"",
1641 pcontrol->
name, versionName)));
1644 versionName = evi_start->
name;
1661 if (control->
schema != NULL)
1670 if (schemaName && strcmp(control->
schema, schemaName) != 0 &&
1673 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1674 errmsg(
"extension \"%s\" must be installed in schema \"%s\"",
1679 schemaName = control->
schema;
1711 if (search_path ==
NIL)
1713 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1714 errmsg(
"no schema has been selected to create in")));
1717 if (schemaName == NULL)
1719 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1720 errmsg(
"no schema has been selected to create in")));
1745 requiredExtensions =
NIL;
1746 requiredSchemas =
NIL;
1749 char *curreq = (
char *)
lfirst(lc);
1760 requiredExtensions =
lappend_oid(requiredExtensions, reqext);
1761 requiredSchemas =
lappend_oid(requiredSchemas, reqschema);
1772 requiredExtensions);
1787 schemaName, schemaOid);
1794 versionName, updateVersions,
1795 origSchemaName, cascade, is_create);
1805 char *extensionName,
1806 char *origSchemaName,
1811 Oid reqExtensionOid;
1820 List *cascade_parents;
1827 foreach(lc, parents)
1829 char *pname = (
char *)
lfirst(lc);
1831 if (strcmp(pname, reqExtensionName) == 0)
1833 (
errcode(ERRCODE_INVALID_RECURSION),
1834 errmsg(
"cyclic dependency detected between extensions \"%s\" and \"%s\"",
1835 reqExtensionName, extensionName)));
1839 (
errmsg(
"installing required extension \"%s\"",
1840 reqExtensionName)));
1861 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1862 errmsg(
"required extension \"%s\" is not installed",
1865 errhint(
"Use CREATE EXTENSION ... CASCADE to install required extensions too.") : 0));
1868 return reqExtensionOid;
1878 DefElem *d_new_version = NULL;
1880 char *schemaName = NULL;
1881 char *versionName = NULL;
1882 bool cascade =
false;
1896 if (
stmt->if_not_exists)
1900 errmsg(
"extension \"%s\" already exists, skipping",
1907 errmsg(
"extension \"%s\" already exists",
1917 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1918 errmsg(
"nested CREATE EXTENSION is not supported")));
1921 foreach(lc,
stmt->options)
1925 if (strcmp(defel->
defname,
"schema") == 0)
1932 else if (strcmp(defel->
defname,
"new_version") == 0)
1936 d_new_version = defel;
1939 else if (strcmp(defel->
defname,
"cascade") == 0)
1974 Oid schemaOid,
bool relocatable,
const char *extVersion,
1976 List *requiredExtensions)
1981 bool nulls[Natts_pg_extension];
1994 memset(nulls, 0,
sizeof(nulls));
1997 Anum_pg_extension_oid);
1999 values[Anum_pg_extension_extname - 1] =
2007 nulls[Anum_pg_extension_extconfig - 1] =
true;
2009 values[Anum_pg_extension_extconfig - 1] = extConfig;
2012 nulls[Anum_pg_extension_extcondition - 1] =
true;
2014 values[Anum_pg_extension_extcondition - 1] = extCondition;
2035 foreach(lc, requiredExtensions)
2081 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2082 errmsg(
"cannot drop extension \"%s\" because it is being modified",
2088 Anum_pg_extension_oid,
2132 if (dir == NULL && errno == ENOENT)
2138 while ((de =
ReadDir(dir, location)) != NULL)
2149 extname =
pstrdup(de->d_name);
2150 *strrchr(extname,
'.') =
'\0';
2153 if (strstr(extname,
"--"))
2159 memset(nulls, 0,
sizeof(nulls));
2212 if (dir == NULL && errno == ENOENT)
2218 while ((de =
ReadDir(dir, location)) != NULL)
2227 extname =
pstrdup(de->d_name);
2228 *strrchr(extname,
'.') =
'\0';
2231 if (strstr(extname,
"--"))
2264 foreach(lc, evi_list)
2281 memset(nulls, 0,
sizeof(nulls));
2295 if (control->
schema == NULL)
2318 foreach(lc2, evi_list)
2369 bool result =
false;
2381 if (dir == NULL && errno == ENOENT)
2387 while ((de =
ReadDir(dir, location)) != NULL)
2396 *strrchr(extname,
'.') =
'\0';
2399 if (strstr(extname,
"--"))
2403 if (strcmp(extname, extensionName) == 0)
2430 foreach(lc, requires)
2432 char *curreq = (
char *)
lfirst(lc);
2467 foreach(lc1, evi_list)
2472 foreach(lc2, evi_list)
2487 memset(nulls, 0,
sizeof(nulls));
2506 char *versionName = (
char *)
lfirst(lcv);
2545 Datum repl_val[Natts_pg_extension];
2546 bool repl_null[Natts_pg_extension];
2547 bool repl_repl[Natts_pg_extension];
2556 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2557 errmsg(
"%s can only be called from an SQL script executed by CREATE EXTENSION",
2558 "pg_extension_config_dump()")));
2566 if (tablename == NULL)
2569 errmsg(
"OID %u does not refer to a table", tableoid)));
2573 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2574 errmsg(
"table \"%s\" is not a member of the extension being created",
2589 Anum_pg_extension_oid,
2599 elog(
ERROR,
"could not find tuple for extension %u",
2602 memset(repl_val, 0,
sizeof(repl_val));
2603 memset(repl_null,
false,
sizeof(repl_null));
2604 memset(repl_repl,
false,
sizeof(repl_repl));
2609 arrayDatum =
heap_getattr(extTup, Anum_pg_extension_extconfig,
2633 elog(
ERROR,
"extconfig is not a 1-D Oid array");
2636 arrayIndex = arrayLength + 1;
2638 for (
i = 0;
i < arrayLength;
i++)
2640 if (arrayData[
i] == tableoid)
2656 repl_repl[Anum_pg_extension_extconfig - 1] =
true;
2661 arrayDatum =
heap_getattr(extTup, Anum_pg_extension_extcondition,
2665 if (arrayLength != 0)
2666 elog(
ERROR,
"extconfig and extcondition arrays do not match");
2678 elog(
ERROR,
"extcondition is not a 1-D text array");
2680 elog(
ERROR,
"extconfig and extcondition arrays do not match");
2692 repl_repl[Anum_pg_extension_extcondition - 1] =
true;
2695 repl_val, repl_null, repl_repl);
2724 Datum repl_val[Natts_pg_extension];
2725 bool repl_null[Natts_pg_extension];
2726 bool repl_repl[Natts_pg_extension];
2733 Anum_pg_extension_oid,
2743 elog(
ERROR,
"could not find tuple for extension %u",
2747 arrayDatum =
heap_getattr(extTup, Anum_pg_extension_extconfig,
2769 elog(
ERROR,
"extconfig is not a 1-D Oid array");
2774 for (
i = 0;
i < arrayLength;
i++)
2776 if (arrayData[
i] == tableoid)
2793 memset(repl_val, 0,
sizeof(repl_val));
2794 memset(repl_null,
false,
sizeof(repl_null));
2795 memset(repl_repl,
false,
sizeof(repl_repl));
2797 if (arrayLength <= 1)
2800 repl_null[Anum_pg_extension_extconfig - 1] =
true;
2812 for (
i = arrayIndex;
i < arrayLength - 1;
i++)
2813 dvalues[
i] = dvalues[
i + 1];
2819 repl_repl[Anum_pg_extension_extconfig - 1] =
true;
2822 arrayDatum =
heap_getattr(extTup, Anum_pg_extension_extcondition,
2826 elog(
ERROR,
"extconfig and extcondition arrays do not match");
2836 elog(
ERROR,
"extcondition is not a 1-D text array");
2838 elog(
ERROR,
"extconfig and extcondition arrays do not match");
2841 if (arrayLength <= 1)
2844 repl_null[Anum_pg_extension_extcondition - 1] =
true;
2856 for (
i = arrayIndex;
i < arrayLength - 1;
i++)
2857 dvalues[
i] = dvalues[
i + 1];
2863 repl_repl[Anum_pg_extension_extcondition - 1] =
true;
2866 repl_val, repl_null, repl_repl);
2919 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2920 errmsg(
"cannot move extension \"%s\" into schema \"%s\" "
2921 "because the extension contains the schema",
2922 extensionName, newschema)));
2928 Anum_pg_extension_oid,
2938 elog(
ERROR,
"could not find tuple for extension %u",
2951 if (extForm->extnamespace == nspOid)
2958 if (!extForm->extrelocatable)
2960 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2961 errmsg(
"extension \"%s\" does not support SET SCHEMA",
2967 oldNspOid = extForm->extnamespace;
2976 Anum_pg_depend_refclassid,
2980 Anum_pg_depend_refobjid,
3003 pg_depend->classid == ExtensionRelationId)
3012 char *nrextname = (
char *)
lfirst(lc);
3014 if (strcmp(nrextname,
NameStr(extForm->extname)) == 0)
3017 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3018 errmsg(
"cannot SET SCHEMA of extension \"%s\" because other extensions prevent it",
3020 errdetail(
"Extension \"%s\" requests no relocation of extension \"%s\".",
3035 dep.
classId = pg_depend->classid;
3040 elog(
ERROR,
"extension should not have a sub-object dependency");
3052 if (dep_oldNspOid !=
InvalidOid && dep_oldNspOid != oldNspOid)
3054 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3055 errmsg(
"extension \"%s\" does not support SET SCHEMA",
3057 errdetail(
"%s is not in the extension's schema \"%s\"",
3064 *oldschema = oldNspOid;
3071 extForm->extnamespace = nspOid;
3079 NamespaceRelationId, oldNspOid, nspOid) != 1)
3080 elog(
ERROR,
"could not change schema dependency for extension %s",
3096 DefElem *d_new_version = NULL;
3098 char *oldVersionName;
3105 List *updateVersions;
3117 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3118 errmsg(
"nested ALTER EXTENSION is not supported")));
3126 Anum_pg_extension_extname,
3137 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3138 errmsg(
"extension \"%s\" does not exist",
3146 datum =
heap_getattr(extTup, Anum_pg_extension_extversion,
3171 foreach(lc,
stmt->options)
3175 if (strcmp(defel->
defname,
"new_version") == 0)
3179 d_new_version = defel;
3188 if (d_new_version && d_new_version->
arg)
3189 versionName =
strVal(d_new_version->
arg);
3195 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3196 errmsg(
"version to install must be specified")));
3204 if (strcmp(oldVersionName, versionName) == 0)
3207 (
errmsg(
"version \"%s\" of extension \"%s\" is already installed",
3208 versionName,
stmt->extname)));
3224 oldVersionName, updateVersions,
3225 NULL,
false,
false);
3243 const char *initialVersion,
3244 List *updateVersions,
3245 char *origSchemaName,
3249 const char *oldVersionName = initialVersion;
3252 foreach(lcv, updateVersions)
3254 char *versionName = (
char *)
lfirst(lcv);
3258 List *requiredExtensions;
3259 List *requiredSchemas;
3266 bool nulls[Natts_pg_extension];
3267 bool repl[Natts_pg_extension];
3280 Anum_pg_extension_oid,
3290 elog(
ERROR,
"could not find tuple for extension %u",
3298 schemaOid = extForm->extnamespace;
3305 memset(nulls, 0,
sizeof(nulls));
3306 memset(repl, 0,
sizeof(repl));
3308 values[Anum_pg_extension_extrelocatable - 1] =
3310 repl[Anum_pg_extension_extrelocatable - 1] =
true;
3311 values[Anum_pg_extension_extversion - 1] =
3313 repl[Anum_pg_extension_extversion - 1] =
true;
3329 requiredExtensions =
NIL;
3330 requiredSchemas =
NIL;
3333 char *curreq = (
char *)
lfirst(lc);
3344 requiredExtensions =
lappend_oid(requiredExtensions, reqext);
3345 requiredSchemas =
lappend_oid(requiredSchemas, reqschema);
3352 ExtensionRelationId,
3355 myself.
classId = ExtensionRelationId;
3359 foreach(lc, requiredExtensions)
3364 otherext.
classId = ExtensionRelationId;
3377 oldVersionName, versionName,
3379 schemaName, schemaOid);
3386 oldVersionName = versionName;
3406 switch (
stmt->objtype)
3417 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3418 errmsg(
"cannot add an object of this type to an extension")));
3451 Assert(
object.objectSubId == 0);
3457 stmt->object, relation);
3471 if (relation != NULL)
3496 if (
stmt->action > 0)
3503 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3504 errmsg(
"%s is already a member of extension \"%s\"",
3512 if (
object.classId == NamespaceRelationId &&
3515 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3516 errmsg(
"cannot add schema \"%s\" to extension \"%s\" "
3517 "because the schema contains the extension",
3541 if (oldExtension != extension.
objectId)
3543 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3544 errmsg(
"%s is not a member of extension \"%s\"",
3552 ExtensionRelationId,
3554 elog(
ERROR,
"unexpected number of extension dependency records");
3560 if (
object.classId == RelationRelationId)
3579 if (
object.classId == TypeRelationId)
3583 depobject.
classId = TypeRelationId;
3597 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3598 errmsg(
"could not find multirange type for data type %s",
3603 if (
object.classId == RelationRelationId)
3607 depobject.
classId = TypeRelationId;
3628 size_t bytes_to_read;
3638 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3640 bytes_to_read = (size_t) fst.
st_size;
3645 errmsg(
"could not open file \"%s\" for reading: %m",
3648 buf = (
char *)
palloc(bytes_to_read + 1);
3650 *length = fread(
buf, 1, bytes_to_read, file);
3659 buf[*length] =
'\0';
void recordExtObjInitPriv(Oid objoid, Oid classoid)
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 removeExtObjInitPriv(Oid objoid, Oid classoid)
Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, ObjectAddresses *objsMoved)
#define DatumGetArrayTypeP(X)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
bool parse_bool(const char *value, bool *result)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define Assert(condition)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
#define CONF_FILE_START_DEPTH
bool defGetBoolean(DefElem *def)
char * defGetString(DefElem *def)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
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)
DestReceiver * CreateDestReceiver(CommandDest dest)
int internalerrquery(const char *query)
int internalerrposition(int cursorpos)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
ErrorContextCallback * error_context_stack
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
int errposition(int cursorpos)
#define ereport(elevel,...)
void ExecutorEnd(QueryDesc *queryDesc)
void ExecutorFinish(QueryDesc *queryDesc)
void ExecutorStart(QueryDesc *queryDesc, int eflags)
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once)
static ExtensionVersionInfo * get_ext_ver_info(const char *versionname, List **evi_list)
Oid get_extension_schema(Oid ext_oid)
static bool is_extension_script_filename(const char *filename)
static char * read_whole_file(const char *filename, int *length)
ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner, Oid schemaOid, bool relocatable, const char *extVersion, Datum extConfig, Datum extCondition, List *requiredExtensions)
static void check_valid_extension_name(const char *extensionname)
static char * read_extension_script_file(const ExtensionControlFile *control, const char *filename)
static List * identify_update_path(ExtensionControlFile *control, const char *oldVersion, const char *newVersion)
struct ExtensionVersionInfo ExtensionVersionInfo
ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt)
static void check_valid_version_name(const char *versionname)
static bool is_extension_control_filename(const char *filename)
static Oid get_required_extension(char *reqExtensionName, char *extensionName, char *origSchemaName, bool cascade, List *parents, bool is_create)
static void script_error_callback(void *arg)
static char * get_extension_script_filename(ExtensionControlFile *control, const char *from_version, const char *version)
static List * get_ext_ver_list(ExtensionControlFile *control)
static void execute_extension_script(Oid extensionOid, ExtensionControlFile *control, const char *from_version, const char *version, List *requiredSchemas, const char *schemaName, Oid schemaOid)
static void parse_extension_control_file(ExtensionControlFile *control, const char *version)
Datum pg_available_extension_versions(PG_FUNCTION_ARGS)
static void extension_config_remove(Oid extensionoid, Oid tableoid)
static void execute_sql_string(const char *sql, const char *filename)
static ExtensionVersionInfo * get_nearest_unprocessed_vertex(List *evi_list)
ObjectAddress AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *oldschema)
static char * get_extension_control_directory(void)
static char * get_extension_script_directory(ExtensionControlFile *control)
static ExtensionControlFile * read_extension_control_file(const char *extname)
ObjectAddress ExecAlterExtensionStmt(ParseState *pstate, AlterExtensionStmt *stmt)
Oid CurrentExtensionObject
ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, ObjectAddress *objAddr)
Datum pg_extension_update_paths(PG_FUNCTION_ARGS)
static void ExecAlterExtensionContentsRecurse(AlterExtensionContentsStmt *stmt, ObjectAddress extension, ObjectAddress object)
Oid get_extension_oid(const char *extname, bool missing_ok)
Datum pg_available_extensions(PG_FUNCTION_ARGS)
Datum pg_extension_config_dump(PG_FUNCTION_ARGS)
static ExtensionVersionInfo * find_install_path(List *evi_list, ExtensionVersionInfo *evi_target, List **best_path)
static Datum convert_requires_to_datum(List *requires)
static char * get_extension_control_filename(const char *extname)
static ExtensionControlFile * read_extension_aux_control_file(const ExtensionControlFile *pcontrol, const char *version)
struct ExtensionControlFile ExtensionControlFile
char * get_extension_name(Oid ext_oid)
void RemoveExtensionById(Oid extId)
static void get_available_versions_for_extension(ExtensionControlFile *pcontrol, Tuplestorestate *tupstore, TupleDesc tupdesc)
static List * find_update_path(List *evi_list, ExtensionVersionInfo *evi_start, ExtensionVersionInfo *evi_target, bool reject_indirect, bool reinitialize)
bool extension_file_exists(const char *extensionName)
static bool extension_is_trusted(ExtensionControlFile *control)
static void ApplyExtensionUpdates(Oid extensionOid, ExtensionControlFile *pcontrol, const char *initialVersion, List *updateVersions, char *origSchemaName, bool cascade, bool is_create)
static ObjectAddress CreateExtensionInternal(char *extensionName, char *schemaName, const char *versionName, bool cascade, List *parents, bool is_create)
static char * get_extension_aux_control_filename(ExtensionControlFile *control, const char *version)
struct dirent * ReadDir(DIR *dir, const char *dirname)
FILE * AllocateFile(const char *name, const char *mode)
DIR * AllocateDir(const char *dirname)
Datum DirectFunctionCall4Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Datum DirectFunctionCall3Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3)
#define PG_GETARG_TEXT_PP(n)
#define DatumGetTextPP(X)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_NAME(n)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
char my_exec_path[MAXPGPATH]
int set_config_option_ext(const char *name, const char *value, GucContext context, GucSource source, Oid srole, GucAction action, bool changeVal, int elevel, bool is_reload)
int NewGUCNestLevel(void)
void AtEOXact_GUC(bool isCommit, int nestLevel)
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
void FreeConfigVariables(ConfigVariable *list)
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
bool check_function_bodies
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
HeapTuple heap_copytuple(HeapTuple tuple)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
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)
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
List * list_copy(const List *oldlist)
void list_free(List *list)
List * lcons(void *datum, List *list)
#define ShareUpdateExclusiveLock
bool type_is_range(Oid typid)
char * get_namespace_name(Oid nspid)
Oid get_rel_type_id(Oid relid)
char * get_rel_name(Oid relid)
Oid get_range_multirange(Oid rangeOid)
Oid get_array_type(Oid typid)
char * pg_any_to_server(const char *s, int len, int encoding)
int GetDatabaseEncoding(void)
bool pg_verify_mbstr(int encoding, const char *mbstr, int len, bool noError)
char * pnstrdup(const char *in, Size len)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define SECURITY_LOCAL_USERID_CHANGE
char * GetUserNameFromId(Oid roleid, bool noerr)
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
void SetUserIdAndSecContext(Oid userid, int sec_context)
Datum namein(PG_FUNCTION_ARGS)
bool isTempNamespace(Oid namespaceId)
Oid LookupCreationNamespace(const char *nspname)
List * fetch_search_path(bool includeImplicit)
Oid get_namespace_oid(const char *nspname, bool missing_ok)
#define IsA(nodeptr, _type_)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
void check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
const ObjectAddress InvalidObjectAddress
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define ObjectAddressSet(addr, class_id, object_id)
#define CURSOR_OPT_PARALLEL_OK
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
Oid getExtensionOfObject(Oid classId, Oid objectId)
FormData_pg_depend * Form_pg_depend
FormData_pg_extension * Form_pg_extension
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
#define pg_valid_server_encoding
#define ERRCODE_UNDEFINED_TABLE
void get_share_path(const char *my_exec_path, char *ret_path)
#define is_absolute_path(filename)
char * first_dir_separator(const char *filename)
List * pg_parse_query(const char *query_string)
List * pg_analyze_and_rewrite_fixedparams(RawStmt *parsetree, const char *query_string, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
List * pg_plan_queries(List *querytrees, const char *query_string, int cursorOptions, ParamListInfo boundParams)
static Datum PointerGetDatum(const void *X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
void FreeQueryDesc(QueryDesc *qdesc)
QueryDesc * CreateQueryDesc(PlannedStmt *plannedstmt, const char *sourceText, Snapshot snapshot, Snapshot crosscheck_snapshot, DestReceiver *dest, ParamListInfo params, QueryEnvironment *queryEnv, int instrument_options)
char * psprintf(const char *fmt,...)
const char * CleanQuerytext(const char *query, int *location, int *len)
MemoryContextSwitchTo(old_ctx)
Datum textregexreplace(PG_FUNCTION_ARGS)
#define RelationGetDescr(relation)
const char * quote_identifier(const char *ident)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Oid CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Snapshot GetTransactionSnapshot(void)
void PushActiveSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
Snapshot GetActiveSnapshot(void)
void relation_close(Relation relation, LOCKMODE lockmode)
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
struct ConfigVariable * next
struct ErrorContextCallback * previous
void(* callback)(void *arg)
struct ExtensionVersionInfo * previous
Tuplestorestate * setResult
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define GetSysCacheOid1(cacheId, oidcol, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
String * makeString(char *str)
char * text_to_cstring(const text *t)
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Datum replace_text(PG_FUNCTION_ARGS)
void CommandCounterIncrement(void)
#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE