95 #include "utils/fmgroids.h"
143 #define AT_PASS_UNSET -1
144 #define AT_PASS_DROP 0
145 #define AT_PASS_ALTER_TYPE 1
146 #define AT_PASS_OLD_INDEX 2
147 #define AT_PASS_OLD_CONSTR 3
149 #define AT_PASS_ADD_COL 4
150 #define AT_PASS_ADD_CONSTR 5
151 #define AT_PASS_COL_ATTRS 6
152 #define AT_PASS_ADD_INDEXCONSTR 7
153 #define AT_PASS_ADD_INDEX 8
154 #define AT_PASS_ADD_OTHERCONSTR 9
155 #define AT_PASS_MISC 10
156 #define AT_NUM_PASSES 11
252 gettext_noop(
"sequence \"%s\" does not exist, skipping"),
254 gettext_noop(
"Use DROP SEQUENCE to remove a sequence.")},
263 gettext_noop(
"materialized view \"%s\" does not exist"),
264 gettext_noop(
"materialized view \"%s\" does not exist, skipping"),
266 gettext_noop(
"Use DROP MATERIALIZED VIEW to remove a materialized view.")},
268 ERRCODE_UNDEFINED_OBJECT,
273 {RELKIND_COMPOSITE_TYPE,
274 ERRCODE_UNDEFINED_OBJECT,
279 {RELKIND_FOREIGN_TABLE,
280 ERRCODE_UNDEFINED_OBJECT,
282 gettext_noop(
"foreign table \"%s\" does not exist, skipping"),
284 gettext_noop(
"Use DROP FOREIGN TABLE to remove a foreign table.")},
285 {RELKIND_PARTITIONED_TABLE,
291 {RELKIND_PARTITIONED_INDEX,
292 ERRCODE_UNDEFINED_OBJECT,
297 {
'\0', 0, NULL, NULL, NULL, NULL}
315 #define ATT_TABLE 0x0001
316 #define ATT_VIEW 0x0002
317 #define ATT_MATVIEW 0x0004
318 #define ATT_INDEX 0x0008
319 #define ATT_COMPOSITE_TYPE 0x0010
320 #define ATT_FOREIGN_TABLE 0x0020
321 #define ATT_PARTITIONED_INDEX 0x0040
322 #define ATT_SEQUENCE 0x0080
343 #define child_dependency_type(child_is_partition) \
344 ((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
352 bool is_partition,
List **supconstr);
357 bool child_is_partition);
360 bool child_is_partition);
368 bool recurse,
bool recursing,
LOCKMODE lockmode);
374 bool recurse,
bool recursing,
LOCKMODE lockmode);
382 int numattrs,
int16 *attnums,
389 Oid pkindOid,
Oid constraintOid);
394 bool recurse,
bool recursing,
LOCKMODE lockmode,
426 bool recurse,
bool recursing,
440 const char *colName,
LOCKMODE lockmode);
442 const char *colName,
LOCKMODE lockmode);
445 List *testConstraint,
List *provenConstraint);
468 bool recurse,
bool recursing,
477 Constraint *newConstraint,
bool recurse,
bool is_readd,
485 bool recurse,
bool recursing,
bool is_readd,
489 bool recurse,
bool recursing,
494 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
495 int numfkdelsetcols,
int16 *fkdelsetcols,
497 Oid parentDelTrigger,
Oid parentUpdTrigger);
499 int numfksetcols,
const int16 *fksetcolsattnums,
504 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
505 int numfkdelsetcols,
int16 *fkdelsetcols,
506 bool old_check_ok,
LOCKMODE lockmode,
507 Oid parentInsTrigger,
Oid parentUpdTrigger);
516 Oid parentInsTrigger,
Oid parentUpdTrigger,
517 Oid *insertTrigOid,
Oid *updateTrigOid);
521 Oid parentDelTrigger,
Oid parentUpdTrigger,
522 Oid *deleteTrigOid,
Oid *updateTrigOid);
525 Oid parentConstrOid,
int numfks,
528 Oid parentInsTrigger,
529 Oid parentUpdTrigger,
533 Oid *deleteTriggerOid,
534 Oid *updateTriggerOid);
537 Oid *insertTriggerOid,
538 Oid *updateTriggerOid);
541 bool recurse,
bool recursing,
542 bool missing_ok,
LOCKMODE lockmode);
545 bool recurse,
bool recursing,
561 const char *conname);
567 Oid oldOwnerId,
Oid newOwnerId);
576 const char *tablespacename,
LOCKMODE lockmode);
583 char fires_when,
bool skip_system,
bool recurse,
586 char fires_when,
LOCKMODE lockmode);
605 Oid oldRelOid,
void *
arg);
610 List **partexprs,
Oid *partopclass,
Oid *partcollation,
614 bool expect_detached);
620 List *partConstraint,
621 bool validate_default);
629 bool concurrent,
Oid defaultPartOid);
672 List *old_constraints;
674 List *cookedDefaults;
683 const char *accessMethod = NULL;
696 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
698 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
699 errmsg(
"ON COMMIT can only be used on temporary tables")));
701 if (
stmt->partspec != NULL)
703 if (relkind != RELKIND_RELATION)
704 elog(
ERROR,
"unexpected relkind: %d", (
int) relkind);
706 relkind = RELKIND_PARTITIONED_TABLE;
726 if (
stmt->relation->relpersistence == RELPERSISTENCE_TEMP
729 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
730 errmsg(
"cannot create temporary table within security-restricted operation")));
753 foreach(listptr,
stmt->inhRelations)
765 (
errcode(ERRCODE_DUPLICATE_TABLE),
766 errmsg(
"relation \"%s\" would be inherited from more than once",
776 if (
stmt->tablespacename)
782 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
783 errmsg(
"cannot specify default tablespace for partitioned relations")));
785 else if (
stmt->partbound)
815 if (tablespaceId == GLOBALTABLESPACE_OID)
817 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
818 errmsg(
"only shared relations can be placed in pg_global tablespace")));
835 case RELKIND_PARTITIONED_TABLE:
842 if (
stmt->ofTypename)
862 stmt->relation->relpersistence,
863 stmt->partbound != NULL,
886 cookedDefaults =
NIL;
889 foreach(listptr,
stmt->tableElts)
908 rawDefaults =
lappend(rawDefaults, rawEnt);
909 attr->atthasdef =
true;
925 cookedDefaults =
lappend(cookedDefaults, cooked);
926 attr->atthasdef =
true;
930 attr->attidentity = colDef->
identity;
947 if (
stmt->accessMethod != NULL)
949 accessMethod =
stmt->accessMethod;
953 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
954 errmsg(
"specifying a table access method is not supported on a partitioned table")));
956 else if (RELKIND_HAS_TABLE_AM(relkind))
960 if (accessMethod != NULL)
980 stmt->relation->relpersistence,
1019 true,
true,
false, queryString);
1027 if (
stmt->partbound)
1044 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1046 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1047 errmsg(
"\"%s\" is not partitioned",
1085 NULL,
false,
false);
1140 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1141 errmsg(
"cannot partition using more than %d columns",
1153 partattrs, &partexprs, partopclass,
1154 partcollation,
stmt->partspec->strategy);
1158 partopclass, partcollation);
1171 if (
stmt->partbound)
1185 foreach(cell, idxlist)
1192 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1196 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1197 errmsg(
"cannot create foreign partition of partitioned table \"%s\"",
1199 errdetail(
"Table \"%s\" contains indexes that are unique.",
1213 attmap, &constraintOid);
1219 false,
false,
false,
false,
false);
1247 if (
stmt->constraints)
1249 true,
true,
false, queryString);
1277 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1283 (
errmsg(
"schema \"%s\" does not exist, skipping",
1291 if (rentry->
kind == rightkind)
1321 if (rentry->
kind == rightkind)
1326 if (wentry->
kind == wrongkind)
1331 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1362 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1363 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1366 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1367 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1380 relkind = RELKIND_RELATION;
1384 relkind = RELKIND_INDEX;
1388 relkind = RELKIND_SEQUENCE;
1392 relkind = RELKIND_VIEW;
1396 relkind = RELKIND_MATVIEW;
1400 relkind = RELKIND_FOREIGN_TABLE;
1404 elog(
ERROR,
"unrecognized drop object type: %d",
1433 state.expected_relkind = relkind;
1456 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1468 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1470 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1471 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1481 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1483 state.heap_lockmode,
1487 obj.
classId = RelationRelationId;
1515 bool invalid_system_index =
false;
1550 is_partition = classform->relispartition;
1553 state->actual_relkind = classform->relkind;
1554 state->actual_relpersistence = classform->relpersistence;
1564 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1566 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1573 state->expected_relkind);
1588 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1602 indisvalid = indexform->indisvalid;
1607 invalid_system_index =
true;
1613 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1614 errmsg(
"permission denied: \"%s\" is a system catalog",
1628 relOid != oldRelOid)
1641 if (is_partition && relOid != oldRelOid)
1675 foreach(cell,
stmt->relations)
1679 bool recurse = rv->
inh;
1705 relids_logged =
lappend_oid(relids_logged, myrelid);
1714 foreach(child, children)
1753 relids_logged =
lappend_oid(relids_logged, childrelid);
1756 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1758 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1759 errmsg(
"cannot truncate only a partitioned table"),
1760 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1764 stmt->behavior,
stmt->restart_seqs);
1791 List *relids_logged,
1796 HTAB *ft_htab = NULL;
1822 if (newrelids ==
NIL)
1825 foreach(cell, newrelids)
1832 (
errmsg(
"truncate cascades to table \"%s\"",
1842 relids_logged =
lappend_oid(relids_logged, relid);
1852 #ifdef USE_ASSERT_CHECKING
1873 foreach(seqcell, seqlist)
1907 resultRelInfo = resultRelInfos;
1928 resultRelInfo = resultRelInfos;
1945 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1955 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1966 memset(&hctl, 0,
sizeof(
HASHCTL));
1971 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2034 toast_relid = rel->
rd_rel->reltoastrelid;
2041 toastrel->
rd_rel->relpersistence);
2087 foreach(cell, seq_relids)
2101 if (relids_logged !=
NIL)
2110 foreach(cell, relids_logged)
2133 resultRelInfo = resultRelInfos;
2174 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2181 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2182 errmsg(
"cannot truncate foreign table \"%s\"",
2185 else if (reltuple->relkind != RELKIND_RELATION &&
2186 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2188 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2201 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2202 errmsg(
"permission denied: \"%s\" is a system catalog",
2238 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2239 errmsg(
"cannot truncate temporary tables of other sessions")));
2257 case TYPSTORAGE_PLAIN:
2259 case TYPSTORAGE_EXTERNAL:
2261 case TYPSTORAGE_EXTENDED:
2263 case TYPSTORAGE_MAIN:
2333 bool is_partition,
List **supconstr)
2337 bool have_bogus_defaults =
false;
2339 static Node bogus_marker = {0};
2356 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2357 errmsg(
"tables can have at most %d columns",
2374 for (
int coldefpos = 0; coldefpos <
list_length(schema); coldefpos++)
2378 if (!is_partition && coldef->
typeName == NULL)
2387 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2388 errmsg(
"column \"%s\" does not exist",
2393 for (
int restpos = coldefpos + 1; restpos <
list_length(schema);)
2413 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2414 errmsg(
"column \"%s\" specified more than once",
2429 saved_schema = schema;
2439 foreach(entry, supers)
2446 List *inherited_defaults;
2447 List *cols_with_defaults;
2467 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
2470 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2471 errmsg(
"cannot inherit from partitioned table \"%s\"",
2473 if (relation->
rd_rel->relispartition && !is_partition)
2475 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2476 errmsg(
"cannot inherit from partition \"%s\"",
2479 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2480 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2481 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2483 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2484 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2492 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2493 relpersistence == RELPERSISTENCE_TEMP)
2495 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2496 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2500 if (relpersistence != RELPERSISTENCE_TEMP &&
2501 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2503 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2505 ?
"cannot inherit from temporary relation \"%s\""
2506 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2510 if (relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
2513 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2515 ?
"cannot inherit from temporary relation of another session"
2516 :
"cannot create as partition of temporary relation of another session")));
2527 constr = tupleDesc->
constr;
2537 inherited_defaults = cols_with_defaults =
NIL;
2539 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
2544 char *attributeName =
NameStr(attribute->attname);
2551 if (attribute->attisdropped)
2558 if (exist_attno > 0)
2568 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
2576 if (defTypeId != attribute->atttypid ||
2577 deftypmod != attribute->atttypmod)
2579 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2580 errmsg(
"inherited column \"%s\" has a type conflict",
2586 attribute->atttypmod))));
2592 if (defCollId != attribute->attcollation)
2594 (
errcode(ERRCODE_COLLATION_MISMATCH),
2595 errmsg(
"inherited column \"%s\" has a collation conflict",
2605 def->
storage = attribute->attstorage;
2606 else if (def->
storage != attribute->attstorage)
2608 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2609 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
2620 const char *compression =
2625 else if (strcmp(def->
compression, compression) != 0)
2627 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2628 errmsg(
"column \"%s\" has a compression method conflict",
2641 if (def->
generated != attribute->attgenerated)
2643 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2644 errmsg(
"inherited column \"%s\" has a generation conflict",
2653 newattmap->
attnums[parent_attno - 1] = exist_attno;
2663 attribute->atttypmod);
2668 def->
storage = attribute->attstorage;
2671 def->
generated = attribute->attgenerated;
2673 def->
collOid = attribute->attcollation;
2681 inhSchema =
lappend(inhSchema, def);
2682 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2688 if (attribute->atthasdef)
2690 Node *this_default = NULL;
2699 if (attrdef[
i].adnum == parent_attno)
2706 if (this_default == NULL)
2707 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2716 inherited_defaults =
lappend(inherited_defaults, this_default);
2717 cols_with_defaults =
lappend(cols_with_defaults, def);
2725 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2729 bool found_whole_row;
2743 if (found_whole_row)
2745 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2746 errmsg(
"cannot convert whole-row table reference"),
2747 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2763 have_bogus_defaults =
true;
2781 bool found_whole_row;
2784 if (check[
i].ccnoinherit)
2798 if (found_whole_row)
2800 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2801 errmsg(
"cannot convert whole-row table reference"),
2802 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2817 cooked->
expr = expr;
2822 constraints =
lappend(constraints, cooked);
2843 if (inhSchema !=
NIL)
2845 int schema_attno = 0;
2847 foreach(entry, schema)
2850 char *attributeName = newdef->
colname;
2859 if (exist_attno > 0)
2878 if (exist_attno == schema_attno)
2880 (
errmsg(
"merging column \"%s\" with inherited definition",
2884 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
2885 errdetail(
"User-specified column moved to the position of the inherited column.")));
2893 if (defTypeId != newTypeId || deftypmod != newtypmod)
2895 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2896 errmsg(
"column \"%s\" has a type conflict",
2909 if (defcollid != newcollid)
2911 (
errcode(ERRCODE_COLLATION_MISMATCH),
2912 errmsg(
"column \"%s\" has a collation conflict",
2931 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2932 errmsg(
"column \"%s\" has a storage parameter conflict",
2947 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2948 errmsg(
"column \"%s\" has a compression method conflict",
2977 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2978 errmsg(
"column \"%s\" inherits from generated column but specifies default",
2982 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2983 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
2990 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2991 errmsg(
"child column \"%s\" specifies generation expression",
2993 errhint(
"A child table column cannot be generated unless its parent column is.")));
3013 inhSchema =
lappend(inhSchema, newdef);
3025 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
3026 errmsg(
"tables can have at most %d columns",
3038 foreach(entry, saved_schema)
3064 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3065 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3069 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3070 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3077 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3078 errmsg(
"child column \"%s\" specifies generation expression",
3080 errhint(
"A child table column cannot be generated unless its parent column is.")));
3105 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3106 errmsg(
"column \"%s\" does not exist",
3115 if (have_bogus_defaults)
3117 foreach(entry, schema)
3125 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3126 errmsg(
"column \"%s\" inherits conflicting generation expressions",
3128 errhint(
"To resolve the conflict, specify a generation expression explicitly.")));
3131 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3132 errmsg(
"column \"%s\" inherits conflicting default values",
3134 errhint(
"To resolve the conflict, specify a default explicitly.")));
3139 *supconstr = constraints;
3161 foreach(lc, constraints)
3180 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3196 bool child_is_partition)
3222 foreach(entry, supers)
3227 child_is_partition);
3241 bool child_is_partition)
3252 parentobject.
classId = RelationRelationId;
3255 childobject.
classId = RelationRelationId;
3293 if (strcmp(attributeName, def->
colname) == 0)
3328 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3331 if (classtuple->relhassubclass != relhassubclass)
3333 classtuple->relhassubclass = relhassubclass;
3359 Oid oldTableSpaceId;
3365 oldTableSpaceId = rel->
rd_rel->reltablespace;
3366 if (newTableSpaceId == oldTableSpaceId ||
3376 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3377 errmsg(
"cannot move system relation \"%s\"",
3381 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3383 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3384 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3392 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3393 errmsg(
"cannot move temporary tables of other sessions")));
3415 Oid newTableSpaceId,
3430 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3437 rd_rel->relfilenode = newRelFilenumber;
3444 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3446 rd_rel->reltablespace);
3458 char relkind = classform->relkind;
3460 if (classform->reloftype && !recursing)
3462 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3463 errmsg(
"cannot rename column of typed table")));
3472 if (relkind != RELKIND_RELATION &&
3473 relkind != RELKIND_VIEW &&
3474 relkind != RELKIND_MATVIEW &&
3475 relkind != RELKIND_COMPOSITE_TYPE &&
3476 relkind != RELKIND_INDEX &&
3477 relkind != RELKIND_PARTITIONED_INDEX &&
3478 relkind != RELKIND_FOREIGN_TABLE &&
3479 relkind != RELKIND_PARTITIONED_TABLE)
3481 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3482 errmsg(
"cannot rename columns of relation \"%s\"",
3494 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3495 errmsg(
"permission denied: \"%s\" is a system catalog",
3496 NameStr(classform->relname))));
3506 const char *oldattname,
3507 const char *newattname,
3510 int expected_parents,
3554 forboth(lo, child_oids, li, child_numparents)
3559 if (childrelid == myrelid)
3562 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3573 if (expected_parents == 0 &&
3576 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3577 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3582 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3591 foreach(lo, child_oids)
3600 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3601 errmsg(
"column \"%s\" does not exist",
3605 attnum = attform->attnum;
3608 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3609 errmsg(
"cannot rename system column \"%s\"",
3621 if (attform->attinhcount > expected_parents)
3623 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3624 errmsg(
"cannot rename inherited column \"%s\"",
3685 (
errmsg(
"relation \"%s\" does not exist, skipping",
3686 stmt->relation->relname)));
3694 stmt->relation->inh,
3710 const char *oldconname,
3711 const char *newconname,
3714 int expected_parents)
3722 Assert(!myrelid || !mytypid);
3743 elog(
ERROR,
"cache lookup failed for constraint %u",
3747 if (myrelid && con->contype == CONSTRAINT_CHECK && !con->connoinherit)
3759 forboth(lo, child_oids, li, child_numparents)
3764 if (childrelid == myrelid)
3772 if (expected_parents == 0 &&
3775 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3776 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
3780 if (con->coninhcount > expected_parents)
3782 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3783 errmsg(
"cannot rename inherited constraint \"%s\"",
3788 && (con->contype == CONSTRAINT_PRIMARY
3789 || con->contype == CONSTRAINT_UNIQUE
3790 || con->contype == CONSTRAINT_EXCLUSION))
3828 elog(
ERROR,
"cache lookup failed for type %u", typid);
3843 (
errmsg(
"relation \"%s\" does not exist, skipping",
3844 stmt->relation->relname)));
3854 stmt->relation->inh),
3895 (
errmsg(
"relation \"%s\" does not exist, skipping",
3896 stmt->relation->relname)));
3907 obj_is_index = (relkind == RELKIND_INDEX ||
3908 relkind == RELKIND_PARTITIONED_INDEX);
3909 if (obj_is_index || is_index_stmt == obj_is_index)
3913 is_index_stmt = obj_is_index;
3956 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
3961 (
errcode(ERRCODE_DUPLICATE_TABLE),
3962 errmsg(
"relation \"%s\" already exists",
3972 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
3973 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
3994 newrelname, namespaceId);
3999 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4000 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
4031 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4073 int expected_refcnt;
4078 (
errcode(ERRCODE_OBJECT_IN_USE),
4080 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4083 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4084 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4087 (
errcode(ERRCODE_OBJECT_IN_USE),
4089 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4196 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4480 elog(
ERROR,
"unrecognized alter table type: %d",
4488 if (cmd_lockmode > lockmode)
4489 lockmode = cmd_lockmode;
4514 ATPrepCmd(&wqueue, rel, cmd, recurse,
false, lockmode, context);
4538 bool recurse,
bool recursing,
LOCKMODE lockmode,
4551 if (rel->
rd_rel->relispartition &&
4555 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4556 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4558 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
4748 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4749 errmsg(
"cannot change persistence setting twice")));
4763 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4764 errmsg(
"cannot change persistence setting twice")));
4782 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
4784 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
4785 errmsg(
"cannot change access method of a partitioned table")));
4790 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4791 errmsg(
"cannot have multiple SET ACCESS METHOD subcommands")));
4892 elog(
ERROR,
"unrecognized alter table type: %d",
4927 foreach(ltab, *wqueue)
4943 foreach(lcmd, subcmds)
4946 lockmode, pass, context);
4965 foreach(ltab, *wqueue)
4974 if (((tab->
relkind == RELKIND_RELATION ||
4975 tab->
relkind == RELKIND_PARTITIONED_TABLE) &&
4977 tab->
relkind == RELKIND_MATVIEW)
4999 lockmode, cur_pass, context);
5079 cmd->
recurse,
false, lockmode);
5084 true,
true, lockmode);
5148 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
5149 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
5258 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)