94 #include "utils/fmgroids.h"
142 #define AT_PASS_UNSET -1
143 #define AT_PASS_DROP 0
144 #define AT_PASS_ALTER_TYPE 1
145 #define AT_PASS_OLD_INDEX 2
146 #define AT_PASS_OLD_CONSTR 3
148 #define AT_PASS_ADD_COL 4
149 #define AT_PASS_ADD_CONSTR 5
150 #define AT_PASS_COL_ATTRS 6
151 #define AT_PASS_ADD_INDEXCONSTR 7
152 #define AT_PASS_ADD_INDEX 8
153 #define AT_PASS_ADD_OTHERCONSTR 9
154 #define AT_PASS_MISC 10
155 #define AT_NUM_PASSES 11
251 gettext_noop(
"sequence \"%s\" does not exist, skipping"),
253 gettext_noop(
"Use DROP SEQUENCE to remove a sequence.")},
262 gettext_noop(
"materialized view \"%s\" does not exist"),
263 gettext_noop(
"materialized view \"%s\" does not exist, skipping"),
265 gettext_noop(
"Use DROP MATERIALIZED VIEW to remove a materialized view.")},
267 ERRCODE_UNDEFINED_OBJECT,
272 {RELKIND_COMPOSITE_TYPE,
273 ERRCODE_UNDEFINED_OBJECT,
278 {RELKIND_FOREIGN_TABLE,
279 ERRCODE_UNDEFINED_OBJECT,
281 gettext_noop(
"foreign table \"%s\" does not exist, skipping"),
283 gettext_noop(
"Use DROP FOREIGN TABLE to remove a foreign table.")},
284 {RELKIND_PARTITIONED_TABLE,
290 {RELKIND_PARTITIONED_INDEX,
291 ERRCODE_UNDEFINED_OBJECT,
296 {
'\0', 0, NULL, NULL, NULL, NULL}
314 #define ATT_TABLE 0x0001
315 #define ATT_VIEW 0x0002
316 #define ATT_MATVIEW 0x0004
317 #define ATT_INDEX 0x0008
318 #define ATT_COMPOSITE_TYPE 0x0010
319 #define ATT_FOREIGN_TABLE 0x0020
320 #define ATT_PARTITIONED_INDEX 0x0040
321 #define ATT_SEQUENCE 0x0080
342 #define child_dependency_type(child_is_partition) \
343 ((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
351 bool is_partition,
List **supconstr);
356 bool child_is_partition);
359 bool child_is_partition);
367 bool recurse,
bool recursing,
LOCKMODE lockmode);
373 bool recurse,
bool recursing,
LOCKMODE lockmode);
381 int numattrs,
int16 *attnums,
388 Oid pkindOid,
Oid constraintOid);
393 bool recurse,
bool recursing,
LOCKMODE lockmode,
425 bool recurse,
bool recursing,
439 const char *colName,
LOCKMODE lockmode);
441 const char *colName,
LOCKMODE lockmode);
444 List *testConstraint,
List *provenConstraint);
467 bool recurse,
bool recursing,
476 Constraint *newConstraint,
bool recurse,
bool is_readd,
484 bool recurse,
bool recursing,
bool is_readd,
488 bool recurse,
bool recursing,
493 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
494 int numfkdelsetcols,
int16 *fkdelsetcols,
496 Oid parentDelTrigger,
Oid parentUpdTrigger);
498 int numfksetcols,
const int16 *fksetcolsattnums,
503 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
504 int numfkdelsetcols,
int16 *fkdelsetcols,
505 bool old_check_ok,
LOCKMODE lockmode,
506 Oid parentInsTrigger,
Oid parentUpdTrigger);
515 Oid parentInsTrigger,
Oid parentUpdTrigger,
516 Oid *insertTrigOid,
Oid *updateTrigOid);
520 Oid parentDelTrigger,
Oid parentUpdTrigger,
521 Oid *deleteTrigOid,
Oid *updateTrigOid);
524 Oid parentConstrOid,
int numfks,
527 Oid parentInsTrigger,
528 Oid parentUpdTrigger,
532 Oid *deleteTriggerOid,
533 Oid *updateTriggerOid);
536 Oid *insertTriggerOid,
537 Oid *updateTriggerOid);
540 bool recurse,
bool recursing,
541 bool missing_ok,
LOCKMODE lockmode);
544 bool recurse,
bool recursing,
560 const char *conname);
566 Oid oldOwnerId,
Oid newOwnerId);
575 const char *tablespacename,
LOCKMODE lockmode);
582 char fires_when,
bool skip_system,
LOCKMODE lockmode);
584 char fires_when,
LOCKMODE lockmode);
603 Oid oldRelOid,
void *
arg);
608 List **partexprs,
Oid *partopclass,
Oid *partcollation,
char strategy);
611 bool allow_detached);
617 List *partConstraint,
618 bool validate_default);
626 bool concurrent,
Oid defaultPartOid);
668 List *old_constraints;
670 List *cookedDefaults;
679 const char *accessMethod = NULL;
694 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
695 errmsg(
"ON COMMIT can only be used on temporary tables")));
699 if (relkind != RELKIND_RELATION)
700 elog(
ERROR,
"unexpected relkind: %d", (
int) relkind);
702 relkind = RELKIND_PARTITIONED_TABLE;
725 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
726 errmsg(
"cannot create temporary table within security-restricted operation")));
761 (
errcode(ERRCODE_DUPLICATE_TABLE),
762 errmsg(
"relation \"%s\" would be inherited from more than once",
778 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
779 errmsg(
"cannot specify default tablespace for partitioned relations")));
811 if (tablespaceId == GLOBALTABLESPACE_OID)
813 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
814 errmsg(
"only shared relations can be placed in pg_global tablespace")));
831 case RELKIND_PARTITIONED_TABLE:
882 cookedDefaults =
NIL;
904 rawDefaults =
lappend(rawDefaults, rawEnt);
905 attr->atthasdef =
true;
921 cookedDefaults =
lappend(cookedDefaults, cooked);
922 attr->atthasdef =
true;
926 attr->attidentity = colDef->
identity;
946 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
947 errmsg(
"specifying a table access method is not supported on a partitioned table")));
949 else if (RELKIND_HAS_TABLE_AM(relkind))
953 if (accessMethod != NULL)
1012 true,
true,
false, queryString);
1037 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1039 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1040 errmsg(
"\"%s\" is not partitioned",
1078 NULL,
false,
false);
1134 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1135 errmsg(
"cannot partition using more than %d columns",
1148 partattrs, &partexprs, partopclass,
1149 partcollation, strategy);
1152 partopclass, partcollation);
1179 foreach(cell, idxlist)
1186 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1190 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1191 errmsg(
"cannot create foreign partition of partitioned table \"%s\"",
1193 errdetail(
"Table \"%s\" contains indexes that are unique.",
1206 attmap, &constraintOid);
1212 false,
false,
false,
false,
false);
1242 true,
true,
false, queryString);
1270 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1276 (
errmsg(
"schema \"%s\" does not exist, skipping",
1284 if (rentry->
kind == rightkind)
1314 if (rentry->
kind == rightkind)
1319 if (wentry->
kind == wrongkind)
1324 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1355 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1356 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1359 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1360 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1373 relkind = RELKIND_RELATION;
1377 relkind = RELKIND_INDEX;
1381 relkind = RELKIND_SEQUENCE;
1385 relkind = RELKIND_VIEW;
1389 relkind = RELKIND_MATVIEW;
1393 relkind = RELKIND_FOREIGN_TABLE;
1397 elog(
ERROR,
"unrecognized drop object type: %d",
1426 state.expected_relkind = relkind;
1449 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1461 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1463 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1464 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1474 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1476 state.heap_lockmode,
1480 obj.
classId = RelationRelationId;
1508 bool invalid_system_index =
false;
1543 is_partition = classform->relispartition;
1546 state->actual_relkind = classform->relkind;
1547 state->actual_relpersistence = classform->relpersistence;
1557 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1559 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1566 state->expected_relkind);
1581 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1595 indisvalid = indexform->indisvalid;
1600 invalid_system_index =
true;
1606 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1607 errmsg(
"permission denied: \"%s\" is a system catalog",
1621 relOid != oldRelOid)
1634 if (is_partition && relOid != oldRelOid)
1672 bool recurse = rv->
inh;
1698 relids_logged =
lappend_oid(relids_logged, myrelid);
1707 foreach(child, children)
1746 relids_logged =
lappend_oid(relids_logged, childrelid);
1749 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1751 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1752 errmsg(
"cannot truncate only a partitioned table"),
1753 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1784 List *relids_logged,
1789 HTAB *ft_htab = NULL;
1815 if (newrelids ==
NIL)
1818 foreach(cell, newrelids)
1825 (
errmsg(
"truncate cascades to table \"%s\"",
1835 relids_logged =
lappend_oid(relids_logged, relid);
1845 #ifdef USE_ASSERT_CHECKING
1866 foreach(seqcell, seqlist)
1900 resultRelInfo = resultRelInfos;
1921 resultRelInfo = resultRelInfos;
1938 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1948 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1959 memset(&hctl, 0,
sizeof(
HASHCTL));
1964 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2027 toast_relid = rel->
rd_rel->reltoastrelid;
2034 toastrel->
rd_rel->relpersistence);
2080 foreach(cell, seq_relids)
2103 foreach(cell, relids_logged)
2126 resultRelInfo = resultRelInfos;
2167 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2174 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2175 errmsg(
"cannot truncate foreign table \"%s\"",
2178 else if (reltuple->relkind != RELKIND_RELATION &&
2179 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2181 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2186 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2187 errmsg(
"permission denied: \"%s\" is a system catalog",
2223 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2224 errmsg(
"cannot truncate temporary tables of other sessions")));
2242 case TYPSTORAGE_PLAIN:
2244 case TYPSTORAGE_EXTERNAL:
2246 case TYPSTORAGE_EXTENDED:
2248 case TYPSTORAGE_MAIN:
2314 bool is_partition,
List **supconstr)
2318 bool have_bogus_defaults =
false;
2320 static Node bogus_marker = {0};
2337 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2338 errmsg(
"tables can have at most %d columns",
2355 for (
int coldefpos = 0; coldefpos <
list_length(schema); coldefpos++)
2359 if (!is_partition && coldef->
typeName == NULL)
2368 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2369 errmsg(
"column \"%s\" does not exist",
2374 for (
int restpos = coldefpos + 1; restpos <
list_length(schema);)
2394 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2395 errmsg(
"column \"%s\" specified more than once",
2410 saved_schema = schema;
2420 foreach(entry, supers)
2427 List *inherited_defaults;
2428 List *cols_with_defaults;
2448 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
2451 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2452 errmsg(
"cannot inherit from partitioned table \"%s\"",
2454 if (relation->
rd_rel->relispartition && !is_partition)
2456 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2457 errmsg(
"cannot inherit from partition \"%s\"",
2460 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2461 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2462 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2464 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2465 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2473 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2474 relpersistence == RELPERSISTENCE_TEMP)
2476 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2477 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2481 if (relpersistence != RELPERSISTENCE_TEMP &&
2482 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2484 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2486 ?
"cannot inherit from temporary relation \"%s\""
2487 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2491 if (relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
2494 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2496 ?
"cannot inherit from temporary relation of another session"
2497 :
"cannot create as partition of temporary relation of another session")));
2508 constr = tupleDesc->
constr;
2518 inherited_defaults = cols_with_defaults =
NIL;
2520 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
2525 char *attributeName =
NameStr(attribute->attname);
2532 if (attribute->attisdropped)
2539 if (exist_attno > 0)
2550 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
2554 if (defTypeId != attribute->atttypid ||
2555 deftypmod != attribute->atttypmod)
2557 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2558 errmsg(
"inherited column \"%s\" has a type conflict",
2564 attribute->atttypmod))));
2566 if (defCollId != attribute->attcollation)
2568 (
errcode(ERRCODE_COLLATION_MISMATCH),
2569 errmsg(
"inherited column \"%s\" has a collation conflict",
2577 def->
storage = attribute->attstorage;
2578 else if (def->
storage != attribute->attstorage)
2580 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2581 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
2590 const char *compression =
2595 else if (strcmp(def->
compression, compression) != 0)
2597 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2598 errmsg(
"column \"%s\" has a compression method conflict",
2607 newattmap->
attnums[parent_attno - 1] = exist_attno;
2610 if (def->
generated != attribute->attgenerated)
2612 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2613 errmsg(
"inherited column \"%s\" has a generation conflict",
2624 attribute->atttypmod);
2629 def->
storage = attribute->attstorage;
2632 def->
generated = attribute->attgenerated;
2634 def->
collOid = attribute->attcollation;
2642 inhSchema =
lappend(inhSchema, def);
2643 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2649 if (attribute->atthasdef)
2651 Node *this_default = NULL;
2660 if (attrdef[
i].adnum == parent_attno)
2667 if (this_default == NULL)
2668 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2677 inherited_defaults =
lappend(inherited_defaults, this_default);
2678 cols_with_defaults =
lappend(cols_with_defaults, def);
2686 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2690 bool found_whole_row;
2704 if (found_whole_row)
2706 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2707 errmsg(
"cannot convert whole-row table reference"),
2708 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2724 have_bogus_defaults =
true;
2742 bool found_whole_row;
2745 if (check[
i].ccnoinherit)
2759 if (found_whole_row)
2761 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2762 errmsg(
"cannot convert whole-row table reference"),
2763 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2778 cooked->
expr = expr;
2783 constraints =
lappend(constraints, cooked);
2804 if (inhSchema !=
NIL)
2806 int schema_attno = 0;
2808 foreach(entry, schema)
2811 char *attributeName = newdef->
colname;
2820 if (exist_attno > 0)
2840 if (exist_attno == schema_attno)
2842 (
errmsg(
"merging column \"%s\" with inherited definition",
2846 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
2847 errdetail(
"User-specified column moved to the position of the inherited column.")));
2851 if (defTypeId != newTypeId || deftypmod != newtypmod)
2853 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2854 errmsg(
"column \"%s\" has a type conflict",
2863 if (defcollid != newcollid)
2865 (
errcode(ERRCODE_COLLATION_MISMATCH),
2866 errmsg(
"column \"%s\" has a collation conflict",
2883 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2884 errmsg(
"column \"%s\" has a storage parameter conflict",
2897 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2898 errmsg(
"column \"%s\" has a compression method conflict",
2924 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2925 errmsg(
"child column \"%s\" specifies generation expression",
2927 errhint(
"Omit the generation expression in the definition of the child table column to inherit the generation expression from the parent table.")));
2930 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2931 errmsg(
"column \"%s\" inherits from generated column but specifies default",
2935 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2936 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
2962 inhSchema =
lappend(inhSchema, newdef);
2974 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2975 errmsg(
"tables can have at most %d columns",
2987 foreach(entry, saved_schema)
3024 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3025 errmsg(
"column \"%s\" does not exist",
3034 if (have_bogus_defaults)
3036 foreach(entry, schema)
3044 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3045 errmsg(
"column \"%s\" inherits conflicting generation expressions",
3049 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3050 errmsg(
"column \"%s\" inherits conflicting default values",
3052 errhint(
"To resolve the conflict, specify a default explicitly.")));
3057 *supconstr = constraints;
3079 foreach(lc, constraints)
3098 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3114 bool child_is_partition)
3140 foreach(entry, supers)
3145 child_is_partition);
3159 bool child_is_partition)
3170 parentobject.
classId = RelationRelationId;
3173 childobject.
classId = RelationRelationId;
3211 if (strcmp(attributeName, def->
colname) == 0)
3246 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3249 if (classtuple->relhassubclass != relhassubclass)
3251 classtuple->relhassubclass = relhassubclass;
3277 Oid oldTableSpaceId;
3283 oldTableSpaceId = rel->
rd_rel->reltablespace;
3284 if (newTableSpaceId == oldTableSpaceId ||
3294 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3295 errmsg(
"cannot move system relation \"%s\"",
3299 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3301 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3302 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3310 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3311 errmsg(
"cannot move temporary tables of other sessions")));
3333 Oid newTableSpaceId,
3348 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3355 rd_rel->relfilenode = newRelFileNode;
3362 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3364 rd_rel->reltablespace);
3376 char relkind = classform->relkind;
3378 if (classform->reloftype && !recursing)
3380 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3381 errmsg(
"cannot rename column of typed table")));
3390 if (relkind != RELKIND_RELATION &&
3391 relkind != RELKIND_VIEW &&
3392 relkind != RELKIND_MATVIEW &&
3393 relkind != RELKIND_COMPOSITE_TYPE &&
3394 relkind != RELKIND_INDEX &&
3395 relkind != RELKIND_PARTITIONED_INDEX &&
3396 relkind != RELKIND_FOREIGN_TABLE &&
3397 relkind != RELKIND_PARTITIONED_TABLE)
3399 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3400 errmsg(
"cannot rename columns of relation \"%s\"",
3412 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3413 errmsg(
"permission denied: \"%s\" is a system catalog",
3414 NameStr(classform->relname))));
3424 const char *oldattname,
3425 const char *newattname,
3428 int expected_parents,
3472 forboth(lo, child_oids, li, child_numparents)
3477 if (childrelid == myrelid)
3480 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3491 if (expected_parents == 0 &&
3494 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3495 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3500 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3509 foreach(lo, child_oids)
3518 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3519 errmsg(
"column \"%s\" does not exist",
3523 attnum = attform->attnum;
3526 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3527 errmsg(
"cannot rename system column \"%s\"",
3539 if (attform->attinhcount > expected_parents)
3541 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3542 errmsg(
"cannot rename inherited column \"%s\"",
3603 (
errmsg(
"relation \"%s\" does not exist, skipping",
3628 const char *oldconname,
3629 const char *newconname,
3632 int expected_parents)
3661 elog(
ERROR,
"cache lookup failed for constraint %u",
3665 if (myrelid && con->contype == CONSTRAINT_CHECK && !con->connoinherit)
3677 forboth(lo, child_oids, li, child_numparents)
3682 if (childrelid == myrelid)
3690 if (expected_parents == 0 &&
3693 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3694 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
3698 if (con->coninhcount > expected_parents)
3700 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3701 errmsg(
"cannot rename inherited constraint \"%s\"",
3706 && (con->contype == CONSTRAINT_PRIMARY
3707 || con->contype == CONSTRAINT_UNIQUE
3708 || con->contype == CONSTRAINT_EXCLUSION))
3746 elog(
ERROR,
"cache lookup failed for type %u", typid);
3761 (
errmsg(
"relation \"%s\" does not exist, skipping",
3813 (
errmsg(
"relation \"%s\" does not exist, skipping",
3814 stmt->relation->relname)));
3825 obj_is_index = (relkind == RELKIND_INDEX ||
3826 relkind == RELKIND_PARTITIONED_INDEX);
3827 if (obj_is_index || is_index_stmt == obj_is_index)
3831 is_index_stmt = obj_is_index;
3874 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
3879 (
errcode(ERRCODE_DUPLICATE_TABLE),
3880 errmsg(
"relation \"%s\" already exists",
3890 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
3891 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
3912 newrelname, namespaceId);
3917 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
3918 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
3949 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
3991 int expected_refcnt;
3996 (
errcode(ERRCODE_OBJECT_IN_USE),
3998 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4001 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4002 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4005 (
errcode(ERRCODE_OBJECT_IN_USE),
4007 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4111 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4396 elog(
ERROR,
"unrecognized alter table type: %d",
4404 if (cmd_lockmode > lockmode)
4405 lockmode = cmd_lockmode;
4430 ATPrepCmd(&wqueue, rel, cmd, recurse,
false, lockmode, context);
4454 bool recurse,
bool recursing,
LOCKMODE lockmode,
4467 if (rel->
rd_rel->relispartition &&
4471 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4472 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4474 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
4664 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4665 errmsg(
"cannot change persistence setting twice")));
4679 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4680 errmsg(
"cannot change persistence setting twice")));
4698 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
4700 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
4701 errmsg(
"cannot change access method of a partitioned table")));
4706 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4707 errmsg(
"cannot have multiple SET ACCESS METHOD subcommands")));
4767 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
4807 elog(
ERROR,
"unrecognized alter table type: %d",
4842 foreach(ltab, *wqueue)
4858 foreach(lcmd, subcmds)
4861 lockmode, pass, context);
4880 foreach(ltab, *wqueue)
4889 if (((tab->
relkind == RELKIND_RELATION ||
4890 tab->
relkind == RELKIND_PARTITIONED_TABLE) &&
4892 tab->
relkind == RELKIND_MATVIEW)
4914 lockmode, cur_pass, context);
4919 lockmode, cur_pass, context);
5005 false,
false, lockmode);
5018 true,
false, lockmode);
5023 true,
true, lockmode);
5097 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
5098 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
5191 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
5203 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5212 elog(
ERROR,
"unrecognized alter table type: %d",