64#include "utils/fmgroids.h"
131 bool reject_indirect,
135 char *origSchemaName,
145 const char *initialVersion,
146 List *updateVersions,
147 char *origSchemaName,
173 (
errcode(ERRCODE_UNDEFINED_OBJECT),
174 errmsg(
"extension \"%s\" does not exist",
230 int namelen = strlen(extensionname);
238 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
239 errmsg(
"invalid extension name: \"%s\"", extensionname),
240 errdetail(
"Extension names must not be empty.")));
245 if (strstr(extensionname,
"--"))
247 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
248 errmsg(
"invalid extension name: \"%s\"", extensionname),
249 errdetail(
"Extension names must not contain \"--\".")));
257 if (extensionname[0] ==
'-' || extensionname[namelen - 1] ==
'-')
259 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
260 errmsg(
"invalid extension name: \"%s\"", extensionname),
261 errdetail(
"Extension names must not begin or end with \"-\".")));
269 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
270 errmsg(
"invalid extension name: \"%s\"", extensionname),
271 errdetail(
"Extension names must not contain directory separator characters.")));
277 int namelen = strlen(versionname);
285 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
286 errmsg(
"invalid extension version name: \"%s\"", versionname),
287 errdetail(
"Version names must not be empty.")));
292 if (strstr(versionname,
"--"))
294 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
295 errmsg(
"invalid extension version name: \"%s\"", versionname),
296 errdetail(
"Version names must not contain \"--\".")));
301 if (versionname[0] ==
'-' || versionname[namelen - 1] ==
'-')
303 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
304 errmsg(
"invalid extension version name: \"%s\"", versionname),
305 errdetail(
"Version names must not begin or end with \"-\".")));
313 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
314 errmsg(
"invalid extension version name: \"%s\"", versionname),
315 errdetail(
"Version names must not contain directory separator characters.")));
324 const char *extension = strrchr(
filename,
'.');
326 return (extension != NULL) && (strcmp(extension,
".control") == 0);
332 const char *extension = strrchr(
filename,
'.');
334 return (extension != NULL) && (strcmp(extension,
".sql") == 0);
350 system_dir =
psprintf(
"%s/extension", sharepath);
354 paths =
lappend(paths, system_dir);
383 paths =
lappend(paths, mangled);
386 if (ecp[
len] ==
'\0')
413 system_dir =
psprintf(
"%s/extension", sharepath);
423 if (strlen(ecp) == 0)
425 result =
find_in_path(basename, ecp,
"extension_control_path",
"$system", system_dir);
431 p = strrchr(result,
'/');
473 scriptdir, control->
name, version);
482 const char *from_version,
const char *version)
492 scriptdir, control->
name, from_version, version);
495 scriptdir, control->
name, version);
548 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
549 errmsg(
"extension \"%s\" is not available", control->
name),
550 errhint(
"The extension must first be installed on the system where PostgreSQL is running.")));
556 if (errno == ENOENT && version)
564 errmsg(
"could not open extension control file \"%s\": %m",
580 for (item = head; item != NULL; item = item->
next)
582 if (strcmp(item->
name,
"directory") == 0)
586 (
errcode(ERRCODE_SYNTAX_ERROR),
587 errmsg(
"parameter \"%s\" cannot be set in a secondary extension control file",
592 else if (strcmp(item->
name,
"default_version") == 0)
596 (
errcode(ERRCODE_SYNTAX_ERROR),
597 errmsg(
"parameter \"%s\" cannot be set in a secondary extension control file",
602 else if (strcmp(item->
name,
"module_pathname") == 0)
606 else if (strcmp(item->
name,
"comment") == 0)
610 else if (strcmp(item->
name,
"schema") == 0)
614 else if (strcmp(item->
name,
"relocatable") == 0)
618 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
619 errmsg(
"parameter \"%s\" requires a Boolean value",
622 else if (strcmp(item->
name,
"superuser") == 0)
626 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
627 errmsg(
"parameter \"%s\" requires a Boolean value",
630 else if (strcmp(item->
name,
"trusted") == 0)
634 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
635 errmsg(
"parameter \"%s\" requires a Boolean value",
638 else if (strcmp(item->
name,
"encoding") == 0)
643 (
errcode(ERRCODE_UNDEFINED_OBJECT),
644 errmsg(
"\"%s\" is not a valid encoding name",
647 else if (strcmp(item->
name,
"requires") == 0)
657 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
658 errmsg(
"parameter \"%s\" must be a list of extension names",
662 else if (strcmp(item->
name,
"no_relocate") == 0)
672 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
673 errmsg(
"parameter \"%s\" must be a list of extension names",
679 (
errcode(ERRCODE_SYNTAX_ERROR),
680 errmsg(
"unrecognized parameter \"%s\" in file \"%s\"",
688 (
errcode(ERRCODE_SYNTAX_ERROR),
689 errmsg(
"parameter \"schema\" cannot be specified when \"relocatable\" is true")));
776 const char *query = callback_arg->
sql;
779 int syntaxerrposition;
780 const char *lastslash;
792 if (syntaxerrposition > 0)
801 if (location < 0 || syntaxerrposition < location ||
802 (
len > 0 && syntaxerrposition > location +
len))
816 int slen = strlen(query);
819 for (
int loc = 0; loc < slen; loc++)
821 if (query[loc] !=
';')
823 if (query[loc + 1] ==
'\r')
825 if (query[loc + 1] ==
'\n')
829 if (bkpt < syntaxerrposition)
831 else if (bkpt > syntaxerrposition)
833 len = bkpt - location;
847 syntaxerrposition -= location;
848 if (syntaxerrposition < 0)
849 syntaxerrposition = 0;
850 else if (syntaxerrposition >
len)
851 syntaxerrposition =
len;
858 else if (location >= 0)
873 lastslash = strrchr(callback_arg->
filename,
'/');
887 for (query = callback_arg->
sql; *query; query++)
894 errcontext(
"extension script file \"%s\", near line %d",
895 lastslash, linenumber);
898 errcontext(
"extension script file \"%s\"", lastslash);
919 List *raw_parsetree_list;
926 callback_arg.
sql = sql;
932 scripterrcontext.
arg = (
void *) &callback_arg;
949 foreach(lc1, raw_parsetree_list)
965 per_parsetree_context =
967 "execute_sql_string per-statement context",
981 foreach(lc2, stmt_list)
989 if (
stmt->utilityStmt == NULL)
997 dest, NULL, NULL, 0);
1000 elog(
ERROR,
"ExecutorStart() failed unexpectedly");
1011 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1012 errmsg(
"transaction control statements are not allowed within an extension script")));
1068 const char *from_version,
1069 const char *version,
1070 List *requiredSchemas,
1071 const char *schemaName)
1073 bool switch_to_superuser =
false;
1075 Oid save_userid = 0;
1076 int save_sec_context = 0;
1090 switch_to_superuser =
true;
1091 else if (from_version == NULL)
1093 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1094 errmsg(
"permission denied to create extension \"%s\"",
1097 ?
errhint(
"Must have CREATE privilege on current database to create this extension.")
1098 :
errhint(
"Must be superuser to create this extension.")));
1101 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1102 errmsg(
"permission denied to update extension \"%s\"",
1105 ?
errhint(
"Must have CREATE privilege on current database to update this extension.")
1106 :
errhint(
"Must be superuser to update this extension.")));
1111 if (from_version == NULL)
1112 elog(
DEBUG1,
"executing extension script for \"%s\" version '%s'", control->
name, version);
1114 elog(
DEBUG1,
"executing extension script for \"%s\" update from version '%s' to '%s'", control->
name, from_version, version);
1121 if (switch_to_superuser)
1149 BOOTSTRAP_SUPERUSERID,
1171 foreach(lc, requiredSchemas)
1176 if (reqname && strcmp(reqname,
"pg_catalog") != 0)
1205 const char *quoting_relevant_chars =
"\"$'\\";
1225 if (strstr(c_sql,
"@extowner@"))
1227 Oid uid = switch_to_superuser ? save_userid :
GetUserId();
1236 if (strpbrk(userName, quoting_relevant_chars))
1238 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1239 errmsg(
"invalid character in extension owner: must not contain any of \"%s\"",
1240 quoting_relevant_chars)));
1260 if (t_sql != old && strpbrk(schemaName, quoting_relevant_chars))
1262 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1263 errmsg(
"invalid character in extension \"%s\" schema: must not contain any of \"%s\"",
1264 control->
name, quoting_relevant_chars)));
1272 forboth(lc, control->requires, lc2, requiredSchemas)
1275 char *reqextname = (
char *)
lfirst(lc);
1281 repltoken =
psprintf(
"@extschema:%s@", reqextname);
1287 if (t_sql != old && strpbrk(schemaName, quoting_relevant_chars))
1289 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1290 errmsg(
"invalid character in extension \"%s\" schema: must not contain any of \"%s\"",
1291 reqextname, quoting_relevant_chars)));
1327 if (switch_to_superuser)
1345 foreach(lc, *evi_list)
1348 if (strcmp(evi->
name, versionname) == 0)
1361 *evi_list =
lappend(*evi_list, evi);
1378 foreach(lc, evi_list)
1404 int extnamelen = strlen(control->
name);
1411 while ((de =
ReadDir(dir, location)) != NULL)
1423 if (strncmp(de->
d_name, control->
name, extnamelen) != 0 ||
1424 de->
d_name[extnamelen] !=
'-' ||
1425 de->
d_name[extnamelen + 1] !=
'-')
1430 *strrchr(vername,
'.') =
'\0';
1431 vername2 = strstr(vername,
"--");
1443 if (strstr(vername2,
"--"))
1465 const char *oldVersion,
const char *newVersion)
1484 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1485 errmsg(
"extension \"%s\" has no update path from version \"%s\" to version \"%s\"",
1486 control->
name, oldVersion, newVersion)));
1510 bool reject_indirect,
1518 Assert(evi_start != evi_target);
1524 foreach(lc, evi_list)
1540 if (evi == evi_target)
1551 if (newdist < evi2->distance)
1556 else if (newdist == evi2->
distance &&
1579 for (evi = evi_target; evi != evi_start; evi = evi->
previous)
1616 foreach(lc, evi_list)
1633 if (evi_start == NULL ||
1636 strcmp(evi_start->
name, evi1->
name) < 0))
1657 const char *versionName,
1662 char *origSchemaName = schemaName;
1669 List *updateVersions;
1670 List *requiredExtensions;
1671 List *requiredSchemas;
1686 if (versionName == NULL)
1692 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1693 errmsg(
"version to install must be specified")));
1707 updateVersions =
NIL;
1727 if (evi_start == NULL)
1729 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1730 errmsg(
"extension \"%s\" has no installation script nor update path for version \"%s\"",
1731 pcontrol->
name, versionName)));
1734 versionName = evi_start->
name;
1751 if (control->
schema != NULL)
1760 if (schemaName && strcmp(control->
schema, schemaName) != 0 &&
1763 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1764 errmsg(
"extension \"%s\" must be installed in schema \"%s\"",
1769 schemaName = control->
schema;
1801 if (search_path ==
NIL)
1803 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1804 errmsg(
"no schema has been selected to create in")));
1807 if (schemaName == NULL)
1809 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1810 errmsg(
"no schema has been selected to create in")));
1835 requiredExtensions =
NIL;
1836 requiredSchemas =
NIL;
1837 foreach(lc, control->requires)
1839 char *curreq = (
char *)
lfirst(lc);
1850 requiredExtensions =
lappend_oid(requiredExtensions, reqext);
1851 requiredSchemas =
lappend_oid(requiredSchemas, reqschema);
1862 requiredExtensions);
1884 versionName, updateVersions,
1885 origSchemaName, cascade, is_create);
1895 char *extensionName,
1896 char *origSchemaName,
1901 Oid reqExtensionOid;
1910 List *cascade_parents;
1917 foreach(lc, parents)
1919 char *pname = (
char *)
lfirst(lc);
1921 if (strcmp(pname, reqExtensionName) == 0)
1923 (
errcode(ERRCODE_INVALID_RECURSION),
1924 errmsg(
"cyclic dependency detected between extensions \"%s\" and \"%s\"",
1925 reqExtensionName, extensionName)));
1929 (
errmsg(
"installing required extension \"%s\"",
1930 reqExtensionName)));
1951 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1952 errmsg(
"required extension \"%s\" is not installed",
1955 errhint(
"Use CREATE EXTENSION ... CASCADE to install required extensions too.") : 0));
1958 return reqExtensionOid;
1968 DefElem *d_new_version = NULL;
1970 char *schemaName = NULL;
1971 char *versionName = NULL;
1972 bool cascade =
false;
1986 if (
stmt->if_not_exists)
1990 errmsg(
"extension \"%s\" already exists, skipping",
1997 errmsg(
"extension \"%s\" already exists",
2007 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2008 errmsg(
"nested CREATE EXTENSION is not supported")));
2011 foreach(lc,
stmt->options)
2015 if (strcmp(defel->
defname,
"schema") == 0)
2022 else if (strcmp(defel->
defname,
"new_version") == 0)
2026 d_new_version = defel;
2029 else if (strcmp(defel->
defname,
"cascade") == 0)
2064 Oid schemaOid,
bool relocatable,
const char *extVersion,
2066 List *requiredExtensions)
2071 bool nulls[Natts_pg_extension];
2084 memset(nulls, 0,
sizeof(nulls));
2087 Anum_pg_extension_oid);
2089 values[Anum_pg_extension_extname - 1] =
2097 nulls[Anum_pg_extension_extconfig - 1] =
true;
2099 values[Anum_pg_extension_extconfig - 1] = extConfig;
2102 nulls[Anum_pg_extension_extcondition - 1] =
true;
2104 values[Anum_pg_extension_extcondition - 1] = extCondition;
2125 foreach(lc, requiredExtensions)
2171 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2172 errmsg(
"cannot drop extension \"%s\" because it is being modified",
2178 Anum_pg_extension_oid,
2225 if (dir == NULL && errno == ENOENT)
2231 while ((de =
ReadDir(dir, location)) != NULL)
2242 extname =
pstrdup(de->d_name);
2243 *strrchr(extname,
'.') =
'\0';
2246 if (strstr(extname,
"--"))
2254 memset(nulls, 0,
sizeof(nulls));
2311 if (dir == NULL && errno == ENOENT)
2317 while ((de =
ReadDir(dir, location)) != NULL)
2326 extname =
pstrdup(de->d_name);
2327 *strrchr(extname,
'.') =
'\0';
2330 if (strstr(extname,
"--"))
2366 foreach(lc, evi_list)
2383 memset(nulls, 0,
sizeof(nulls));
2397 if (control->
schema == NULL)
2403 if (control->requires ==
NIL)
2420 foreach(lc2, evi_list)
2445 if (control->requires ==
NIL)
2471 bool result =
false;
2486 if (dir == NULL && errno == ENOENT)
2492 while ((de =
ReadDir(dir, location)) != NULL)
2501 *strrchr(extname,
'.') =
'\0';
2504 if (strstr(extname,
"--"))
2508 if (strcmp(extname, extensionName) == 0)
2538 foreach(lc,
requires)
2540 char *curreq = (
char *)
lfirst(lc);
2575 foreach(lc1, evi_list)
2580 foreach(lc2, evi_list)
2595 memset(nulls, 0,
sizeof(nulls));
2614 char *versionName = (
char *)
lfirst(lcv);
2653 Datum repl_val[Natts_pg_extension];
2654 bool repl_null[Natts_pg_extension];
2655 bool repl_repl[Natts_pg_extension];
2664 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2665 errmsg(
"%s can only be called from an SQL script executed by CREATE EXTENSION",
2666 "pg_extension_config_dump()")));
2674 if (tablename == NULL)
2677 errmsg(
"OID %u does not refer to a table", tableoid)));
2681 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2682 errmsg(
"table \"%s\" is not a member of the extension being created",
2697 Anum_pg_extension_oid,
2707 elog(
ERROR,
"could not find tuple for extension %u",
2710 memset(repl_val, 0,
sizeof(repl_val));
2711 memset(repl_null,
false,
sizeof(repl_null));
2712 memset(repl_repl,
false,
sizeof(repl_repl));
2717 arrayDatum =
heap_getattr(extTup, Anum_pg_extension_extconfig,
2741 elog(
ERROR,
"extconfig is not a 1-D Oid array");
2744 arrayIndex = arrayLength + 1;
2746 for (
i = 0;
i < arrayLength;
i++)
2748 if (arrayData[
i] == tableoid)
2764 repl_repl[Anum_pg_extension_extconfig - 1] =
true;
2769 arrayDatum =
heap_getattr(extTup, Anum_pg_extension_extcondition,
2773 if (arrayLength != 0)
2774 elog(
ERROR,
"extconfig and extcondition arrays do not match");
2786 elog(
ERROR,
"extcondition is not a 1-D text array");
2788 elog(
ERROR,
"extconfig and extcondition arrays do not match");
2800 repl_repl[Anum_pg_extension_extcondition - 1] =
true;
2803 repl_val, repl_null, repl_repl);
2833 const char *library_path,
2838 bool nulls[3] = {0};
2845 if (module_name == NULL)
2849 if (module_version == NULL)
2857 library_path = sep + 1;
2885 Datum repl_val[Natts_pg_extension];
2886 bool repl_null[Natts_pg_extension];
2887 bool repl_repl[Natts_pg_extension];
2894 Anum_pg_extension_oid,
2904 elog(
ERROR,
"could not find tuple for extension %u",
2908 arrayDatum =
heap_getattr(extTup, Anum_pg_extension_extconfig,
2930 elog(
ERROR,
"extconfig is not a 1-D Oid array");
2935 for (
i = 0;
i < arrayLength;
i++)
2937 if (arrayData[
i] == tableoid)
2954 memset(repl_val, 0,
sizeof(repl_val));
2955 memset(repl_null,
false,
sizeof(repl_null));
2956 memset(repl_repl,
false,
sizeof(repl_repl));
2958 if (arrayLength <= 1)
2961 repl_null[Anum_pg_extension_extconfig - 1] =
true;
2973 for (
i = arrayIndex;
i < arrayLength - 1;
i++)
2974 dvalues[
i] = dvalues[
i + 1];
2980 repl_repl[Anum_pg_extension_extconfig - 1] =
true;
2983 arrayDatum =
heap_getattr(extTup, Anum_pg_extension_extcondition,
2987 elog(
ERROR,
"extconfig and extcondition arrays do not match");
2997 elog(
ERROR,
"extcondition is not a 1-D text array");
2999 elog(
ERROR,
"extconfig and extcondition arrays do not match");
3002 if (arrayLength <= 1)
3005 repl_null[Anum_pg_extension_extcondition - 1] =
true;
3017 for (
i = arrayIndex;
i < arrayLength - 1;
i++)
3018 dvalues[
i] = dvalues[
i + 1];
3024 repl_repl[Anum_pg_extension_extcondition - 1] =
true;
3027 repl_val, repl_null, repl_repl);
3080 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3081 errmsg(
"cannot move extension \"%s\" into schema \"%s\" "
3082 "because the extension contains the schema",
3083 extensionName, newschema)));
3089 Anum_pg_extension_oid,
3099 elog(
ERROR,
"could not find tuple for extension %u",
3112 if (extForm->extnamespace == nspOid)
3119 if (!extForm->extrelocatable)
3121 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3122 errmsg(
"extension \"%s\" does not support SET SCHEMA",
3128 oldNspOid = extForm->extnamespace;
3137 Anum_pg_depend_refclassid,
3141 Anum_pg_depend_refobjid,
3164 pg_depend->classid == ExtensionRelationId)
3173 char *nrextname = (
char *)
lfirst(lc);
3175 if (strcmp(nrextname,
NameStr(extForm->extname)) == 0)
3178 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3179 errmsg(
"cannot SET SCHEMA of extension \"%s\" because other extensions prevent it",
3181 errdetail(
"Extension \"%s\" requests no relocation of extension \"%s\".",
3196 dep.
classId = pg_depend->classid;
3201 elog(
ERROR,
"extension should not have a sub-object dependency");
3213 if (dep_oldNspOid !=
InvalidOid && dep_oldNspOid != oldNspOid)
3215 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3216 errmsg(
"extension \"%s\" does not support SET SCHEMA",
3218 errdetail(
"%s is not in the extension's schema \"%s\"",
3225 *oldschema = oldNspOid;
3232 extForm->extnamespace = nspOid;
3240 NamespaceRelationId, oldNspOid, nspOid) != 1)
3241 elog(
ERROR,
"could not change schema dependency for extension %s",
3257 DefElem *d_new_version = NULL;
3259 char *oldVersionName;
3266 List *updateVersions;
3278 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3279 errmsg(
"nested ALTER EXTENSION is not supported")));
3287 Anum_pg_extension_extname,
3298 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3299 errmsg(
"extension \"%s\" does not exist",
3307 datum =
heap_getattr(extTup, Anum_pg_extension_extversion,
3332 foreach(lc,
stmt->options)
3336 if (strcmp(defel->
defname,
"new_version") == 0)
3340 d_new_version = defel;
3349 if (d_new_version && d_new_version->
arg)
3350 versionName =
strVal(d_new_version->
arg);
3356 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3357 errmsg(
"version to install must be specified")));
3365 if (strcmp(oldVersionName, versionName) == 0)
3368 (
errmsg(
"version \"%s\" of extension \"%s\" is already installed",
3369 versionName,
stmt->extname)));
3385 oldVersionName, updateVersions,
3386 NULL,
false,
false);
3404 const char *initialVersion,
3405 List *updateVersions,
3406 char *origSchemaName,
3410 const char *oldVersionName = initialVersion;
3413 foreach(lcv, updateVersions)
3415 char *versionName = (
char *)
lfirst(lcv);
3419 List *requiredExtensions;
3420 List *requiredSchemas;
3427 bool nulls[Natts_pg_extension];
3428 bool repl[Natts_pg_extension];
3441 Anum_pg_extension_oid,
3451 elog(
ERROR,
"could not find tuple for extension %u",
3459 schemaOid = extForm->extnamespace;
3466 memset(nulls, 0,
sizeof(nulls));
3467 memset(repl, 0,
sizeof(repl));
3469 values[Anum_pg_extension_extrelocatable - 1] =
3471 repl[Anum_pg_extension_extrelocatable - 1] =
true;
3472 values[Anum_pg_extension_extversion - 1] =
3474 repl[Anum_pg_extension_extversion - 1] =
true;
3490 requiredExtensions =
NIL;
3491 requiredSchemas =
NIL;
3492 foreach(lc, control->requires)
3494 char *curreq = (
char *)
lfirst(lc);
3505 requiredExtensions =
lappend_oid(requiredExtensions, reqext);
3506 requiredSchemas =
lappend_oid(requiredSchemas, reqschema);
3513 ExtensionRelationId,
3516 myself.
classId = ExtensionRelationId;
3520 foreach(lc, requiredExtensions)
3525 otherext.
classId = ExtensionRelationId;
3538 oldVersionName, versionName,
3547 oldVersionName = versionName;
3567 switch (
stmt->objtype)
3578 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3579 errmsg(
"cannot add an object of this type to an extension")));
3612 Assert(
object.objectSubId == 0);
3618 stmt->object, relation);
3632 if (relation != NULL)
3657 if (
stmt->action > 0)
3664 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3665 errmsg(
"%s is already a member of extension \"%s\"",
3673 if (
object.classId == NamespaceRelationId &&
3676 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3677 errmsg(
"cannot add schema \"%s\" to extension \"%s\" "
3678 "because the schema contains the extension",
3702 if (oldExtension != extension.
objectId)
3704 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3705 errmsg(
"%s is not a member of extension \"%s\"",
3713 ExtensionRelationId,
3715 elog(
ERROR,
"unexpected number of extension dependency records");
3721 if (
object.classId == RelationRelationId)
3740 if (
object.classId == TypeRelationId)
3744 depobject.
classId = TypeRelationId;
3758 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3759 errmsg(
"could not find multirange type for data type %s",
3764 if (
object.classId == RelationRelationId)
3768 depobject.
classId = TypeRelationId;
3790 size_t bytes_to_read;
3800 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3802 bytes_to_read = (size_t) fst.
st_size;
3807 errmsg(
"could not open file \"%s\" for reading: %m",
3810 buf = (
char *)
palloc(bytes_to_read + 1);
3812 bytes_to_read = fread(
buf, 1, bytes_to_read, file);
3821 buf[bytes_to_read] =
'\0';
3836 for (s = d =
buf; *s; s++)
3838 if (!(*s ==
'\r' && s[1] ==
'\n'))
3842 bytes_to_read = d -
buf;
3846 *length = bytes_to_read;
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 * 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)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
bool parse_bool(const char *value, bool *result)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
#define CONF_FILE_START_DEPTH
char * defGetString(DefElem *def)
bool defGetBoolean(DefElem *def)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
void free_object_addresses(ObjectAddresses *addrs)
DestReceiver * CreateDestReceiver(CommandDest dest)
char * find_in_path(const char *basename, const char *path, const char *path_param, const char *macro, const char *macro_val)
DynamicFileList * get_next_loaded_module(DynamicFileList *dfptr)
DynamicFileList * get_first_loaded_module(void)
void get_loaded_module_details(DynamicFileList *dfptr, const char **library_path, const char **module_name, const char **module_version)
char * substitute_path_macro(const char *str, const char *macro, const char *value)
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,...)
bool ExecutorStart(QueryDesc *queryDesc, int eflags)
void ExecutorEnd(QueryDesc *queryDesc)
void ExecutorFinish(QueryDesc *queryDesc)
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count)
static char * get_extension_aux_control_filename(ExtensionControlFile *control, const char *version)
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 ExtensionVersionInfo * get_nearest_unprocessed_vertex(List *evi_list)
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)
Datum pg_get_loaded_modules(PG_FUNCTION_ARGS)
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 ExtensionControlFile * read_extension_aux_control_file(const ExtensionControlFile *pcontrol, const char *version)
char * Extension_control_path
static void parse_extension_control_file(ExtensionControlFile *control, const char *version)
static List * get_extension_control_directories(void)
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 char * get_extension_script_directory(ExtensionControlFile *control)
static char * find_extension_control_filename(ExtensionControlFile *control)
ObjectAddress AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *oldschema)
static ExtensionVersionInfo * find_install_path(List *evi_list, ExtensionVersionInfo *evi_target, List **best_path)
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 char * read_extension_script_file(const ExtensionControlFile *control, const char *filename)
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)
static ExtensionControlFile * new_ExtensionControlFile(const char *extname)
Datum pg_extension_config_dump(PG_FUNCTION_ARGS)
static Datum convert_requires_to_datum(List *requires)
static List * identify_update_path(ExtensionControlFile *control, const char *oldVersion, const char *newVersion)
static ExtensionVersionInfo * get_ext_ver_info(const char *versionname, List **evi_list)
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 * get_ext_ver_list(ExtensionControlFile *control)
static List * find_update_path(List *evi_list, ExtensionVersionInfo *evi_start, ExtensionVersionInfo *evi_target, bool reject_indirect, bool reinitialize)
static char * get_extension_script_filename(ExtensionControlFile *control, const char *from_version, const char *version)
static void execute_extension_script(Oid extensionOid, ExtensionControlFile *control, const char *from_version, const char *version, List *requiredSchemas, const char *schemaName)
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)
DIR * AllocateDir(const char *dirname)
struct dirent * ReadDir(DIR *dir, const char *dirname)
FILE * AllocateFile(const char *name, const char *mode)
#define palloc0_object(type)
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]
void FreeConfigVariables(ConfigVariable *list)
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
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)
bool check_function_bodies
Assert(PointerIsAligned(start, uint64))
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)
static void * GETSTRUCT(const HeapTupleData *tuple)
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 * list_copy(const List *oldlist)
List * lappend_oid(List *list, Oid datum)
List * lcons(void *datum, List *list)
void list_free(List *list)
#define ShareUpdateExclusiveLock
char * get_rel_name(Oid relid)
bool type_is_range(Oid typid)
Oid get_rel_type_id(Oid relid)
Oid get_range_multirange(Oid rangeOid)
char * get_namespace_name(Oid nspid)
Oid get_array_type(Oid typid)
int GetDatabaseEncoding(void)
char * pg_any_to_server(const char *s, int len, int encoding)
bool pg_verify_mbstr(int encoding, const char *mbstr, int len, bool noError)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
char * pnstrdup(const char *in, Size len)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define SECURITY_LOCAL_USERID_CHANGE
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
char * GetUserNameFromId(Oid roleid, bool noerr)
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)
void check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
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)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#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)
#define foreach_ptr(type, var, lst)
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 * last_dir_separator(const char *filename)
char * first_path_var_separator(const char *pathlist)
void canonicalize_path(char *path)
char * first_dir_separator(const char *filename)
size_t strlcpy(char *dst, const char *src, size_t siz)
List * pg_parse_query(const char *query_string)
List * pg_plan_queries(List *querytrees, const char *query_string, int cursorOptions, ParamListInfo boundParams)
List * pg_analyze_and_rewrite_fixedparams(RawStmt *parsetree, const char *query_string, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
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, CachedPlan *cplan, 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)
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)
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
char * text_to_cstring(const text *t)
Datum replace_text(PG_FUNCTION_ARGS)
void CommandCounterIncrement(void)
#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE