96 #include "utils/fmgroids.h"
145 #define AT_PASS_UNSET -1
146 #define AT_PASS_DROP 0
147 #define AT_PASS_ALTER_TYPE 1
148 #define AT_PASS_OLD_INDEX 2
149 #define AT_PASS_OLD_CONSTR 3
151 #define AT_PASS_ADD_COL 4
152 #define AT_PASS_ADD_CONSTR 5
153 #define AT_PASS_COL_ATTRS 6
154 #define AT_PASS_ADD_INDEXCONSTR 7
155 #define AT_PASS_ADD_INDEX 8
156 #define AT_PASS_ADD_OTHERCONSTR 9
157 #define AT_PASS_MISC 10
158 #define AT_NUM_PASSES 11
254 gettext_noop(
"sequence \"%s\" does not exist, skipping"),
256 gettext_noop(
"Use DROP SEQUENCE to remove a sequence.")},
265 gettext_noop(
"materialized view \"%s\" does not exist"),
266 gettext_noop(
"materialized view \"%s\" does not exist, skipping"),
268 gettext_noop(
"Use DROP MATERIALIZED VIEW to remove a materialized view.")},
270 ERRCODE_UNDEFINED_OBJECT,
275 {RELKIND_COMPOSITE_TYPE,
276 ERRCODE_UNDEFINED_OBJECT,
281 {RELKIND_FOREIGN_TABLE,
282 ERRCODE_UNDEFINED_OBJECT,
284 gettext_noop(
"foreign table \"%s\" does not exist, skipping"),
286 gettext_noop(
"Use DROP FOREIGN TABLE to remove a foreign table.")},
287 {RELKIND_PARTITIONED_TABLE,
293 {RELKIND_PARTITIONED_INDEX,
294 ERRCODE_UNDEFINED_OBJECT,
299 {
'\0', 0, NULL, NULL, NULL, NULL}
317 #define ATT_TABLE 0x0001
318 #define ATT_VIEW 0x0002
319 #define ATT_MATVIEW 0x0004
320 #define ATT_INDEX 0x0008
321 #define ATT_COMPOSITE_TYPE 0x0010
322 #define ATT_FOREIGN_TABLE 0x0020
323 #define ATT_PARTITIONED_INDEX 0x0040
324 #define ATT_SEQUENCE 0x0080
345 #define child_dependency_type(child_is_partition) \
346 ((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
354 bool is_partition,
List **supconstr,
360 bool child_is_partition);
363 bool child_is_partition);
371 bool recurse,
bool recursing,
LOCKMODE lockmode);
377 bool recurse,
bool recursing,
LOCKMODE lockmode);
385 int numattrs,
int16 *attnums,
392 Oid pkindOid,
Oid constraintOid);
397 bool recurse,
bool recursing,
LOCKMODE lockmode,
429 bool recurse,
bool recursing,
441 char *constrname,
char *colName,
442 bool recurse,
bool recursing,
445 const char *colName,
LOCKMODE lockmode);
448 List *testConstraint,
List *provenConstraint);
471 bool recurse,
bool recursing,
482 Constraint *newConstraint,
bool recurse,
bool is_readd,
490 bool recurse,
bool recursing,
bool is_readd,
494 bool recurse,
bool recursing,
499 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
500 int numfkdelsetcols,
int16 *fkdelsetcols,
502 Oid parentDelTrigger,
Oid parentUpdTrigger);
504 int numfksetcols,
const int16 *fksetcolsattnums,
509 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
510 int numfkdelsetcols,
int16 *fkdelsetcols,
511 bool old_check_ok,
LOCKMODE lockmode,
512 Oid parentInsTrigger,
Oid parentUpdTrigger);
521 Oid parentInsTrigger,
Oid parentUpdTrigger,
522 Oid *insertTrigOid,
Oid *updateTrigOid);
526 Oid parentDelTrigger,
Oid parentUpdTrigger,
527 Oid *deleteTrigOid,
Oid *updateTrigOid);
530 Oid parentConstrOid,
int numfks,
533 Oid parentInsTrigger,
534 Oid parentUpdTrigger,
538 Oid *deleteTriggerOid,
539 Oid *updateTriggerOid);
542 Oid *insertTriggerOid,
543 Oid *updateTriggerOid);
546 bool missing_ok,
LOCKMODE lockmode);
549 bool recurse,
bool recursing,
550 bool missing_ok,
List **readyRels,
554 bool recurse,
bool recursing,
570 const char *conname);
576 Oid oldOwnerId,
Oid newOwnerId);
585 const char *tablespacename,
LOCKMODE lockmode);
592 char fires_when,
bool skip_system,
bool recurse,
595 char fires_when,
LOCKMODE lockmode);
614 Oid oldRelOid,
void *
arg);
619 List **partexprs,
Oid *partopclass,
Oid *partcollation,
623 bool expect_detached);
631 List *partConstraint,
632 bool validate_default);
640 bool concurrent,
Oid defaultPartOid);
684 List *old_constraints;
687 List *cookedDefaults;
697 const char *accessMethod = NULL;
710 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
712 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
713 errmsg(
"ON COMMIT can only be used on temporary tables")));
715 if (
stmt->partspec != NULL)
717 if (relkind != RELKIND_RELATION)
718 elog(
ERROR,
"unexpected relkind: %d", (
int) relkind);
720 relkind = RELKIND_PARTITIONED_TABLE;
740 if (
stmt->relation->relpersistence == RELPERSISTENCE_TEMP
743 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
744 errmsg(
"cannot create temporary table within security-restricted operation")));
767 foreach(listptr,
stmt->inhRelations)
779 (
errcode(ERRCODE_DUPLICATE_TABLE),
780 errmsg(
"relation \"%s\" would be inherited from more than once",
790 if (
stmt->tablespacename)
796 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
797 errmsg(
"cannot specify default tablespace for partitioned relations")));
799 else if (
stmt->partbound)
829 if (tablespaceId == GLOBALTABLESPACE_OID)
831 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
832 errmsg(
"only shared relations can be placed in pg_global tablespace")));
849 case RELKIND_PARTITIONED_TABLE:
856 if (
stmt->ofTypename)
876 stmt->relation->relpersistence,
877 stmt->partbound != NULL,
878 &old_constraints, &old_notnulls);
901 cookedDefaults =
NIL;
904 foreach(listptr,
stmt->tableElts)
923 rawDefaults =
lappend(rawDefaults, rawEnt);
924 attr->atthasdef =
true;
940 cookedDefaults =
lappend(cookedDefaults, cooked);
941 attr->atthasdef =
true;
944 attr->attidentity = colDef->
identity;
955 if (
stmt->accessMethod != NULL)
957 accessMethod =
stmt->accessMethod;
961 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
962 errmsg(
"specifying a table access method is not supported on a partitioned table")));
964 else if (RELKIND_HAS_TABLE_AM(relkind))
968 if (accessMethod != NULL)
988 stmt->relation->relpersistence,
1027 true,
true,
false, queryString);
1035 if (
stmt->partbound)
1052 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1054 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1055 errmsg(
"\"%s\" is not partitioned",
1093 NULL,
false,
false);
1148 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1149 errmsg(
"cannot partition using more than %d columns",
1161 partattrs, &partexprs, partopclass,
1162 partcollation,
stmt->partspec->strategy);
1166 partopclass, partcollation);
1179 if (
stmt->partbound)
1193 foreach(cell, idxlist)
1200 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1204 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1205 errmsg(
"cannot create foreign partition of partitioned table \"%s\"",
1207 errdetail(
"Table \"%s\" contains indexes that are unique.",
1221 attmap, &constraintOid);
1228 false,
false,
false,
false,
false);
1256 if (
stmt->constraints)
1258 true,
true,
false, queryString);
1268 foreach(listptr, nncols)
1297 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1303 (
errmsg(
"schema \"%s\" does not exist, skipping",
1311 if (rentry->
kind == rightkind)
1341 if (rentry->
kind == rightkind)
1346 if (wentry->
kind == wrongkind)
1351 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1382 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1383 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1386 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1387 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1400 relkind = RELKIND_RELATION;
1404 relkind = RELKIND_INDEX;
1408 relkind = RELKIND_SEQUENCE;
1412 relkind = RELKIND_VIEW;
1416 relkind = RELKIND_MATVIEW;
1420 relkind = RELKIND_FOREIGN_TABLE;
1424 elog(
ERROR,
"unrecognized drop object type: %d",
1453 state.expected_relkind = relkind;
1476 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1488 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1490 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1491 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1501 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1503 state.heap_lockmode,
1507 obj.
classId = RelationRelationId;
1535 bool invalid_system_index =
false;
1570 is_partition = classform->relispartition;
1573 state->actual_relkind = classform->relkind;
1574 state->actual_relpersistence = classform->relpersistence;
1584 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1586 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1593 state->expected_relkind);
1608 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1622 indisvalid = indexform->indisvalid;
1627 invalid_system_index =
true;
1633 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1634 errmsg(
"permission denied: \"%s\" is a system catalog",
1648 relOid != oldRelOid)
1661 if (is_partition && relOid != oldRelOid)
1695 foreach(cell,
stmt->relations)
1699 bool recurse = rv->
inh;
1725 relids_logged =
lappend_oid(relids_logged, myrelid);
1734 foreach(child, children)
1773 relids_logged =
lappend_oid(relids_logged, childrelid);
1776 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1778 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1779 errmsg(
"cannot truncate only a partitioned table"),
1780 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1784 stmt->behavior,
stmt->restart_seqs,
false);
1811 List *relids_logged,
1813 bool run_as_table_owner)
1817 HTAB *ft_htab = NULL;
1843 if (newrelids ==
NIL)
1846 foreach(cell, newrelids)
1853 (
errmsg(
"truncate cascades to table \"%s\"",
1863 relids_logged =
lappend_oid(relids_logged, relid);
1873 #ifdef USE_ASSERT_CHECKING
1894 foreach(seqcell, seqlist)
1928 resultRelInfo = resultRelInfos;
1949 resultRelInfo = resultRelInfos;
1954 if (run_as_table_owner)
1958 if (run_as_table_owner)
1973 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1983 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1994 memset(&hctl, 0,
sizeof(
HASHCTL));
1999 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2062 toast_relid = rel->
rd_rel->reltoastrelid;
2069 toastrel->
rd_rel->relpersistence);
2115 foreach(cell, seq_relids)
2129 if (relids_logged !=
NIL)
2138 foreach(cell, relids_logged)
2161 resultRelInfo = resultRelInfos;
2166 if (run_as_table_owner)
2170 if (run_as_table_owner)
2209 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2216 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2217 errmsg(
"cannot truncate foreign table \"%s\"",
2220 else if (reltuple->relkind != RELKIND_RELATION &&
2221 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2223 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2236 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2237 errmsg(
"permission denied: \"%s\" is a system catalog",
2273 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2274 errmsg(
"cannot truncate temporary tables of other sessions")));
2292 case TYPSTORAGE_PLAIN:
2294 case TYPSTORAGE_EXTERNAL:
2296 case TYPSTORAGE_EXTENDED:
2298 case TYPSTORAGE_MAIN:
2373 bool is_partition,
List **supconstr,
List **supnotnulls)
2378 bool have_bogus_defaults =
false;
2380 static Node bogus_marker = {0};
2397 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2398 errmsg(
"tables can have at most %d columns",
2415 for (
int coldefpos = 0; coldefpos <
list_length(schema); coldefpos++)
2419 if (!is_partition && coldef->
typeName == NULL)
2428 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2429 errmsg(
"column \"%s\" does not exist",
2434 for (
int restpos = coldefpos + 1; restpos <
list_length(schema);)
2454 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2455 errmsg(
"column \"%s\" specified more than once",
2470 saved_schema = schema;
2479 foreach(entry, supers)
2486 List *inherited_defaults;
2487 List *cols_with_defaults;
2510 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
2513 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2514 errmsg(
"cannot inherit from partitioned table \"%s\"",
2516 if (relation->
rd_rel->relispartition && !is_partition)
2518 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2519 errmsg(
"cannot inherit from partition \"%s\"",
2522 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2523 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2524 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2526 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2527 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2535 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2536 relpersistence == RELPERSISTENCE_TEMP)
2538 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2539 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2543 if (relpersistence != RELPERSISTENCE_TEMP &&
2544 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2546 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2548 ?
"cannot inherit from temporary relation \"%s\""
2549 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2553 if (relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
2556 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2558 ?
"cannot inherit from temporary relation of another session"
2559 :
"cannot create as partition of temporary relation of another session")));
2570 constr = tupleDesc->
constr;
2580 inherited_defaults = cols_with_defaults =
NIL;
2592 foreach(lc1, nnconstrs)
2596 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
2601 char *attributeName =
NameStr(attribute->attname);
2608 if (attribute->attisdropped)
2615 if (exist_attno > 0)
2625 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
2633 if (defTypeId != attribute->atttypid ||
2634 deftypmod != attribute->atttypmod)
2636 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2637 errmsg(
"inherited column \"%s\" has a type conflict",
2643 attribute->atttypmod))));
2649 if (defCollId != attribute->attcollation)
2651 (
errcode(ERRCODE_COLLATION_MISMATCH),
2652 errmsg(
"inherited column \"%s\" has a collation conflict",
2662 def->
storage = attribute->attstorage;
2663 else if (def->
storage != attribute->attstorage)
2665 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2666 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
2677 const char *compression =
2682 else if (strcmp(def->
compression, compression) != 0)
2684 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2685 errmsg(
"column \"%s\" has a compression method conflict",
2696 if (!is_partition &&
2706 nn->
attnum = exist_attno;
2713 nnconstraints =
lappend(nnconstraints, nn);
2727 if (def->
generated != attribute->attgenerated)
2729 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2730 errmsg(
"inherited column \"%s\" has a generation conflict",
2740 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2741 errmsg(
"too many inheritance parents"));
2743 newattmap->
attnums[parent_attno - 1] = exist_attno;
2751 attribute->atttypmod, attribute->attcollation);
2759 def->
storage = attribute->attstorage;
2760 def->
generated = attribute->attgenerated;
2764 inhSchema =
lappend(inhSchema, def);
2765 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2773 if (!is_partition &&
2791 nnconstraints =
lappend(nnconstraints, nn);
2798 if (attribute->atthasdef)
2800 Node *this_default = NULL;
2809 if (attrdef[
i].adnum == parent_attno)
2816 if (this_default == NULL)
2817 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2826 inherited_defaults =
lappend(inherited_defaults, this_default);
2827 cols_with_defaults =
lappend(cols_with_defaults, def);
2835 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2839 bool found_whole_row;
2853 if (found_whole_row)
2855 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2856 errmsg(
"cannot convert whole-row table reference"),
2857 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2873 have_bogus_defaults =
true;
2891 bool found_whole_row;
2894 if (check[
i].ccnoinherit)
2908 if (found_whole_row)
2910 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2911 errmsg(
"cannot convert whole-row table reference"),
2912 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2927 cooked->
expr = expr;
2932 constraints =
lappend(constraints, cooked);
2941 foreach(lc1, nnconstrs)
2951 nnconstraints =
lappend(nnconstraints, nn);
2970 if (inhSchema !=
NIL)
2972 int schema_attno = 0;
2974 foreach(entry, schema)
2977 char *attributeName = newdef->
colname;
2986 if (exist_attno > 0)
3005 if (exist_attno == schema_attno)
3007 (
errmsg(
"merging column \"%s\" with inherited definition",
3011 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
3012 errdetail(
"User-specified column moved to the position of the inherited column.")));
3020 if (defTypeId != newTypeId || deftypmod != newtypmod)
3022 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3023 errmsg(
"column \"%s\" has a type conflict",
3036 if (defcollid != newcollid)
3038 (
errcode(ERRCODE_COLLATION_MISMATCH),
3039 errmsg(
"column \"%s\" has a collation conflict",
3058 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3059 errmsg(
"column \"%s\" has a storage parameter conflict",
3074 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3075 errmsg(
"column \"%s\" has a compression method conflict",
3104 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3105 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3109 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3110 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3117 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3118 errmsg(
"child column \"%s\" specifies generation expression",
3120 errhint(
"A child table column cannot be generated unless its parent column is.")));
3140 inhSchema =
lappend(inhSchema, newdef);
3152 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
3153 errmsg(
"tables can have at most %d columns",
3164 foreach(entry, saved_schema)
3189 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3190 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3194 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3195 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3202 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3203 errmsg(
"child column \"%s\" specifies generation expression",
3205 errhint(
"A child table column cannot be generated unless its parent column is.")));
3230 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3231 errmsg(
"column \"%s\" does not exist",
3240 if (have_bogus_defaults)
3242 foreach(entry, schema)
3250 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3251 errmsg(
"column \"%s\" inherits conflicting generation expressions",
3253 errhint(
"To resolve the conflict, specify a generation expression explicitly.")));
3256 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3257 errmsg(
"column \"%s\" inherits conflicting default values",
3259 errhint(
"To resolve the conflict, specify a default explicitly.")));
3264 *supconstr = constraints;
3265 *supnotnulls = nnconstraints;
3288 foreach(lc, constraints)
3304 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3305 errmsg(
"too many inheritance parents"));
3311 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3327 bool child_is_partition)
3353 foreach(entry, supers)
3358 child_is_partition);
3372 bool child_is_partition)
3383 parentobject.
classId = RelationRelationId;
3386 childobject.
classId = RelationRelationId;
3424 if (strcmp(attributeName, def->
colname) == 0)
3459 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3462 if (classtuple->relhassubclass != relhassubclass)
3464 classtuple->relhassubclass = relhassubclass;
3490 Oid oldTableSpaceId;
3496 oldTableSpaceId = rel->
rd_rel->reltablespace;
3497 if (newTableSpaceId == oldTableSpaceId ||
3507 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3508 errmsg(
"cannot move system relation \"%s\"",
3512 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3514 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3515 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3523 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3524 errmsg(
"cannot move temporary tables of other sessions")));
3546 Oid newTableSpaceId,
3561 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3568 rd_rel->relfilenode = newRelFilenumber;
3575 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3577 rd_rel->reltablespace);
3589 char relkind = classform->relkind;
3591 if (classform->reloftype && !recursing)
3593 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3594 errmsg(
"cannot rename column of typed table")));
3603 if (relkind != RELKIND_RELATION &&
3604 relkind != RELKIND_VIEW &&
3605 relkind != RELKIND_MATVIEW &&
3606 relkind != RELKIND_COMPOSITE_TYPE &&
3607 relkind != RELKIND_INDEX &&
3608 relkind != RELKIND_PARTITIONED_INDEX &&
3609 relkind != RELKIND_FOREIGN_TABLE &&
3610 relkind != RELKIND_PARTITIONED_TABLE)
3612 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3613 errmsg(
"cannot rename columns of relation \"%s\"",
3625 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3626 errmsg(
"permission denied: \"%s\" is a system catalog",
3627 NameStr(classform->relname))));
3637 const char *oldattname,
3638 const char *newattname,
3641 int expected_parents,
3685 forboth(lo, child_oids, li, child_numparents)
3690 if (childrelid == myrelid)
3693 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3704 if (expected_parents == 0 &&
3707 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3708 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3713 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3722 foreach(lo, child_oids)
3731 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3732 errmsg(
"column \"%s\" does not exist",
3736 attnum = attform->attnum;
3739 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3740 errmsg(
"cannot rename system column \"%s\"",
3752 if (attform->attinhcount > expected_parents)
3754 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3755 errmsg(
"cannot rename inherited column \"%s\"",
3816 (
errmsg(
"relation \"%s\" does not exist, skipping",
3817 stmt->relation->relname)));
3825 stmt->relation->inh,
3841 const char *oldconname,
3842 const char *newconname,
3845 int expected_parents)
3853 Assert(!myrelid || !mytypid);
3874 elog(
ERROR,
"cache lookup failed for constraint %u",
3879 (con->contype == CONSTRAINT_CHECK ||
3880 con->contype == CONSTRAINT_NOTNULL) &&
3893 forboth(lo, child_oids, li, child_numparents)
3898 if (childrelid == myrelid)
3906 if (expected_parents == 0 &&
3909 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3910 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
3914 if (con->coninhcount > expected_parents)
3916 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3917 errmsg(
"cannot rename inherited constraint \"%s\"",
3922 && (con->contype == CONSTRAINT_PRIMARY
3923 || con->contype == CONSTRAINT_UNIQUE
3924 || con->contype == CONSTRAINT_EXCLUSION))
3962 elog(
ERROR,
"cache lookup failed for type %u", typid);
3977 (
errmsg(
"relation \"%s\" does not exist, skipping",
3978 stmt->relation->relname)));
3988 stmt->relation->inh),
4029 (
errmsg(
"relation \"%s\" does not exist, skipping",
4030 stmt->relation->relname)));
4041 obj_is_index = (relkind == RELKIND_INDEX ||
4042 relkind == RELKIND_PARTITIONED_INDEX);
4043 if (obj_is_index || is_index_stmt == obj_is_index)
4047 is_index_stmt = obj_is_index;
4090 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4095 (
errcode(ERRCODE_DUPLICATE_TABLE),
4096 errmsg(
"relation \"%s\" already exists",
4106 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4107 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
4128 newrelname, namespaceId);
4133 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4134 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
4165 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4207 int expected_refcnt;
4212 (
errcode(ERRCODE_OBJECT_IN_USE),
4214 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4217 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4218 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4221 (
errcode(ERRCODE_OBJECT_IN_USE),
4223 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4330 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4606 elog(
ERROR,
"unrecognized alter table type: %d",
4614 if (cmd_lockmode > lockmode)
4615 lockmode = cmd_lockmode;
4640 ATPrepCmd(&wqueue, rel, cmd, recurse,
false, lockmode, context);
4664 bool recurse,
bool recursing,
LOCKMODE lockmode,
4677 if (rel->
rd_rel->relispartition &&
4681 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4682 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4684 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
4876 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4877 errmsg(
"cannot change persistence setting twice")));
4891 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4892 errmsg(
"cannot change persistence setting twice")));
4910 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
4912 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
4913 errmsg(
"cannot change access method of a partitioned table")));
4918 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4919 errmsg(
"cannot have multiple SET ACCESS METHOD subcommands")));
5020 elog(
ERROR,
"unrecognized alter table type: %d",
5055 foreach(ltab, *wqueue)
5071 foreach(lcmd, subcmds)
5074 lockmode, pass, context);
5093 foreach(ltab, *wqueue)
5102 if (((tab->
relkind == RELKIND_RELATION ||
5103 tab->
relkind == RELKIND_PARTITIONED_TABLE) &&
5105 tab->
relkind == RELKIND_MATVIEW)
5127 lockmode, cur_pass, context);
5155 cmd->
recurse,
false, NULL, lockmode);
5208 cmd->
recurse,
false, lockmode);
5213 true,
true, lockmode);