99#include "utils/fmgroids.h"
166#define AT_NUM_PASSES (AT_PASS_MISC + 1)
265 gettext_noop(
"sequence \"%s\" does not exist, skipping"),
267 gettext_noop(
"Use DROP SEQUENCE to remove a sequence.")},
276 gettext_noop(
"materialized view \"%s\" does not exist"),
277 gettext_noop(
"materialized view \"%s\" does not exist, skipping"),
279 gettext_noop(
"Use DROP MATERIALIZED VIEW to remove a materialized view.")},
281 ERRCODE_UNDEFINED_OBJECT,
286 {RELKIND_COMPOSITE_TYPE,
287 ERRCODE_UNDEFINED_OBJECT,
292 {RELKIND_FOREIGN_TABLE,
293 ERRCODE_UNDEFINED_OBJECT,
295 gettext_noop(
"foreign table \"%s\" does not exist, skipping"),
297 gettext_noop(
"Use DROP FOREIGN TABLE to remove a foreign table.")},
298 {RELKIND_PARTITIONED_TABLE,
304 {RELKIND_PARTITIONED_INDEX,
305 ERRCODE_UNDEFINED_OBJECT,
310 {
'\0', 0, NULL, NULL, NULL, NULL}
328#define ATT_TABLE 0x0001
329#define ATT_VIEW 0x0002
330#define ATT_MATVIEW 0x0004
331#define ATT_INDEX 0x0008
332#define ATT_COMPOSITE_TYPE 0x0010
333#define ATT_FOREIGN_TABLE 0x0020
334#define ATT_PARTITIONED_INDEX 0x0040
335#define ATT_SEQUENCE 0x0080
336#define ATT_PARTITIONED_TABLE 0x0100
365#define child_dependency_type(child_is_partition) \
366 ((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
374 bool is_partition,
List **supconstr,
382 bool child_is_partition);
385 bool child_is_partition);
393 bool recurse,
bool recursing,
LOCKMODE lockmode);
398 bool deferrable,
bool initdeferred,
405 bool recurse,
bool recursing,
LOCKMODE lockmode);
410 bool recurse,
bool recursing,
LOCKMODE lockmode);
416 Oid *opclasses,
bool *pk_has_without_overlaps);
418 int numattrs,
int16 *attnums,
419 bool with_period,
Oid *opclasses,
420 bool *pk_has_without_overlaps);
426 Oid pkindOid,
Oid constraintOid,
bool hasperiod);
432 bool recurse,
bool recursing,
LOCKMODE lockmode,
464 bool recurse,
bool recursing,
476 char *constrname,
char *colName,
477 bool recurse,
bool recursing,
481 List *testConstraint,
List *provenConstraint);
487 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
489 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
491 bool recurse,
bool recursing);
507 bool recurse,
bool recursing,
519 Constraint *newConstraint,
bool recurse,
bool is_readd,
527 bool recurse,
bool recursing,
bool is_readd,
531 bool recurse,
bool recursing,
534 int numfksetcols,
const int16 *fksetcolsattnums,
537 char *constraintname,
542 Oid *pfeqoperators,
Oid *ppeqoperators,
543 Oid *ffeqoperators,
int numfkdelsetcols,
544 int16 *fkdelsetcols,
bool is_internal,
549 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
550 int numfkdelsetcols,
int16 *fkdelsetcols,
552 Oid parentDelTrigger,
Oid parentUpdTrigger,
557 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
558 int numfkdelsetcols,
int16 *fkdelsetcols,
559 bool old_check_ok,
LOCKMODE lockmode,
560 Oid parentInsTrigger,
Oid parentUpdTrigger,
570 Oid parentInsTrigger,
Oid parentUpdTrigger,
571 Oid *insertTrigOid,
Oid *updateTrigOid);
575 Oid parentDelTrigger,
Oid parentUpdTrigger,
576 Oid *deleteTrigOid,
Oid *updateTrigOid);
580 Oid parentConstrOid,
int numfks,
583 Oid parentInsTrigger,
584 Oid parentUpdTrigger,
588 Oid *deleteTriggerOid,
589 Oid *updateTriggerOid);
592 Oid *insertTriggerOid,
593 Oid *updateTriggerOid);
596 bool missing_ok,
LOCKMODE lockmode);
599 bool recurse,
bool recursing,
600 bool missing_ok,
LOCKMODE lockmode);
603 bool recurse,
bool recursing,
621 const char *conname);
627 Oid oldOwnerId,
Oid newOwnerId);
638 const char *tablespacename,
LOCKMODE lockmode);
645 char fires_when,
bool skip_system,
bool recurse,
648 char fires_when,
LOCKMODE lockmode);
667 Oid oldRelOid,
void *
arg);
672 List **partexprs,
Oid *partopclass,
Oid *partcollation,
676 bool expect_detached);
682 List *partConstraint,
683 bool validate_default);
691 bool concurrent,
Oid defaultPartOid);
735 List *old_constraints;
738 List *cookedDefaults;
760 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
762 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
763 errmsg(
"ON COMMIT can only be used on temporary tables")));
765 if (
stmt->partspec != NULL)
767 if (relkind != RELKIND_RELATION)
768 elog(
ERROR,
"unexpected relkind: %d", (
int) relkind);
770 relkind = RELKIND_PARTITIONED_TABLE;
776 if (relkind == RELKIND_PARTITIONED_TABLE &&
777 stmt->relation->relpersistence == RELPERSISTENCE_UNLOGGED)
779 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
780 errmsg(
"partitioned tables cannot be unlogged")));
796 if (
stmt->relation->relpersistence == RELPERSISTENCE_TEMP
799 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
800 errmsg(
"cannot create temporary table within security-restricted operation")));
823 foreach(listptr,
stmt->inhRelations)
835 (
errcode(ERRCODE_DUPLICATE_TABLE),
836 errmsg(
"relation \"%s\" would be inherited from more than once",
846 if (
stmt->tablespacename)
852 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
853 errmsg(
"cannot specify default tablespace for partitioned relations")));
855 else if (
stmt->partbound)
881 if (tablespaceId == GLOBALTABLESPACE_OID)
883 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
884 errmsg(
"only shared relations can be placed in pg_global tablespace")));
901 case RELKIND_PARTITIONED_TABLE:
908 if (
stmt->ofTypename)
928 stmt->relation->relpersistence,
929 stmt->partbound != NULL,
930 &old_constraints, &old_notnulls);
953 cookedDefaults =
NIL;
956 foreach(listptr,
stmt->tableElts)
975 rawDefaults =
lappend(rawDefaults, rawEnt);
976 attr->atthasdef =
true;
993 cookedDefaults =
lappend(cookedDefaults, cooked);
994 attr->atthasdef =
true;
1005 if (
stmt->accessMethod != NULL)
1007 Assert(RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE);
1010 else if (RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE)
1012 if (
stmt->partbound)
1018 if (RELKIND_HAS_TABLE_AM(relkind) && !
OidIsValid(accessMethodId))
1039 stmt->relation->relpersistence,
1078 true,
true,
false, queryString);
1086 if (
stmt->partbound)
1103 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1105 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1106 errmsg(
"\"%s\" is not partitioned",
1144 NULL,
false,
false);
1199 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1200 errmsg(
"cannot partition using more than %d columns",
1212 partattrs, &partexprs, partopclass,
1213 partcollation,
stmt->partspec->strategy);
1217 partopclass, partcollation);
1230 if (
stmt->partbound)
1244 foreach(cell, idxlist)
1251 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1255 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1256 errmsg(
"cannot create foreign partition of partitioned table \"%s\"",
1258 errdetail(
"Table \"%s\" contains indexes that are unique.",
1272 attmap, &constraintOid);
1279 false,
false,
false,
false,
false);
1307 if (
stmt->constraints)
1309 true,
true,
false, queryString);
1387 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1388 errmsg(
"too many array dimensions"));
1392 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1393 errmsg(
"column \"%s\" cannot be declared SETOF",
1397 atttypid, atttypmod, attdim);
1406 att->attinhcount = entry->
inhcount;
1407 att->attidentity = entry->
identity;
1411 att->attstorage = entry->
storage;
1436 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1442 (
errmsg(
"schema \"%s\" does not exist, skipping",
1450 if (rentry->
kind == rightkind)
1480 if (rentry->
kind == rightkind)
1485 if (wentry->
kind == wrongkind)
1490 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1521 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1522 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1525 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1526 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1539 relkind = RELKIND_RELATION;
1543 relkind = RELKIND_INDEX;
1547 relkind = RELKIND_SEQUENCE;
1551 relkind = RELKIND_VIEW;
1555 relkind = RELKIND_MATVIEW;
1559 relkind = RELKIND_FOREIGN_TABLE;
1563 elog(
ERROR,
"unrecognized drop object type: %d",
1592 state.expected_relkind = relkind;
1615 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1627 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1629 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1630 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1640 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1642 state.heap_lockmode,
1646 obj.
classId = RelationRelationId;
1674 bool invalid_system_index =
false;
1709 is_partition = classform->relispartition;
1712 state->actual_relkind = classform->relkind;
1713 state->actual_relpersistence = classform->relpersistence;
1723 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1725 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1732 state->expected_relkind);
1747 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1761 indisvalid = indexform->indisvalid;
1766 invalid_system_index =
true;
1772 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1773 errmsg(
"permission denied: \"%s\" is a system catalog",
1787 relOid != oldRelOid)
1800 if (is_partition && relOid != oldRelOid)
1834 foreach(cell,
stmt->relations)
1838 bool recurse = rv->
inh;
1864 relids_logged =
lappend_oid(relids_logged, myrelid);
1873 foreach(child, children)
1912 relids_logged =
lappend_oid(relids_logged, childrelid);
1915 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1917 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1918 errmsg(
"cannot truncate only a partitioned table"),
1919 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1923 stmt->behavior,
stmt->restart_seqs,
false);
1950 List *relids_logged,
1952 bool run_as_table_owner)
1956 HTAB *ft_htab = NULL;
1982 if (newrelids ==
NIL)
1985 foreach(cell, newrelids)
1992 (
errmsg(
"truncate cascades to table \"%s\"",
2002 relids_logged =
lappend_oid(relids_logged, relid);
2012#ifdef USE_ASSERT_CHECKING
2033 foreach(seqcell, seqlist)
2067 resultRelInfo = resultRelInfos;
2088 resultRelInfo = resultRelInfos;
2093 if (run_as_table_owner)
2097 if (run_as_table_owner)
2112 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2122 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2133 memset(&hctl, 0,
sizeof(
HASHCTL));
2138 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2198 toast_relid = rel->
rd_rel->reltoastrelid;
2205 toastrel->
rd_rel->relpersistence);
2251 foreach(cell, seq_relids)
2265 if (relids_logged !=
NIL)
2274 foreach(cell, relids_logged)
2297 resultRelInfo = resultRelInfos;
2302 if (run_as_table_owner)
2306 if (run_as_table_owner)
2345 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2352 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2353 errmsg(
"cannot truncate foreign table \"%s\"",
2356 else if (reltuple->relkind != RELKIND_RELATION &&
2357 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2359 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2372 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2373 errmsg(
"permission denied: \"%s\" is a system catalog",
2409 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2410 errmsg(
"cannot truncate temporary tables of other sessions")));
2428 case TYPSTORAGE_PLAIN:
2430 case TYPSTORAGE_EXTERNAL:
2432 case TYPSTORAGE_EXTENDED:
2434 case TYPSTORAGE_MAIN:
2510 bool is_partition,
List **supconstr,
List **supnotnulls)
2515 bool have_bogus_defaults =
false;
2517 static Node bogus_marker = {0};
2534 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2535 errmsg(
"tables can have at most %d columns",
2552 for (
int coldefpos = 0; coldefpos <
list_length(columns); coldefpos++)
2556 if (!is_partition && coldef->
typeName == NULL)
2565 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2566 errmsg(
"column \"%s\" does not exist",
2571 for (
int restpos = coldefpos + 1; restpos <
list_length(columns);)
2591 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2592 errmsg(
"column \"%s\" specified more than once",
2607 saved_columns = columns;
2623 List *inherited_defaults;
2624 List *cols_with_defaults;
2645 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !is_partition)
2647 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2648 errmsg(
"cannot inherit from partitioned table \"%s\"",
2650 if (relation->
rd_rel->relispartition && !is_partition)
2652 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2653 errmsg(
"cannot inherit from partition \"%s\"",
2656 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2657 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2658 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2660 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2661 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2669 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2670 relpersistence == RELPERSISTENCE_TEMP)
2672 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2673 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2677 if (relpersistence != RELPERSISTENCE_TEMP &&
2678 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2680 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2682 ?
"cannot inherit from temporary relation \"%s\""
2683 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2687 if (relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
2690 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2692 ?
"cannot inherit from temporary relation of another session"
2693 :
"cannot create as partition of temporary relation of another session")));
2704 constr = tupleDesc->
constr;
2714 inherited_defaults = cols_with_defaults =
NIL;
2730 char *attributeName =
NameStr(attribute->attname);
2738 if (attribute->attisdropped)
2745 attribute->atttypmod, attribute->attcollation);
2746 newdef->
storage = attribute->attstorage;
2747 newdef->
generated = attribute->attgenerated;
2758 newdef->
identity = attribute->attidentity;
2765 if (exist_attno > 0)
2772 newattmap->
attnums[parent_attno - 1] = exist_attno;
2787 inh_columns =
lappend(inh_columns, newdef);
2789 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2802 if (attribute->atthasdef)
2807 if (this_default == NULL)
2808 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2817 inherited_defaults =
lappend(inherited_defaults, this_default);
2818 cols_with_defaults =
lappend(cols_with_defaults, mergeddef);
2826 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2830 bool found_whole_row;
2844 if (found_whole_row)
2846 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2847 errmsg(
"cannot convert whole-row table reference"),
2848 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2864 have_bogus_defaults =
true;
2881 bool found_whole_row;
2884 if (check[
i].ccnoinherit)
2898 if (found_whole_row)
2900 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2901 errmsg(
"cannot convert whole-row table reference"),
2902 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2907 check[
i].ccenforced);
2919 nn->attnum = newattmap->
attnums[nn->attnum - 1];
2921 nnconstraints =
lappend(nnconstraints, nn);
2940 if (inh_columns !=
NIL)
2942 int newcol_attno = 0;
2944 foreach(lc, columns)
2947 char *attributeName = newdef->
colname;
2962 if (exist_attno > 0)
2974 inh_columns =
lappend(inh_columns, newdef);
2978 columns = inh_columns;
2986 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2987 errmsg(
"tables can have at most %d columns",
2998 foreach(lc, saved_columns)
3023 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3024 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3028 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3029 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3036 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3037 errmsg(
"child column \"%s\" specifies generation expression",
3039 errhint(
"A child table column cannot be generated unless its parent column is.")));
3064 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3065 errmsg(
"column \"%s\" does not exist",
3074 if (have_bogus_defaults)
3076 foreach(lc, columns)
3084 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3085 errmsg(
"column \"%s\" inherits conflicting generation expressions",
3087 errhint(
"To resolve the conflict, specify a generation expression explicitly.")));
3090 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3091 errmsg(
"column \"%s\" inherits conflicting default values",
3093 errhint(
"To resolve the conflict, specify a default explicitly.")));
3098 *supconstr = constraints;
3099 *supnotnulls = nnconstraints;
3126 foreach(lc, constraints)
3142 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3143 errmsg(
"too many inheritance parents"));
3160 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3171 newcon->
expr = expr;
3175 return lappend(constraints, newcon);
3202 char *attributeName = newdef->
colname;
3211 if (exist_attno == newcol_attno)
3213 (
errmsg(
"merging column \"%s\" with inherited definition",
3217 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
3218 errdetail(
"User-specified column moved to the position of the inherited column.")));
3227 if (inhtypeid != newtypeid || inhtypmod != newtypmod)
3229 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3230 errmsg(
"column \"%s\" has a type conflict",
3241 if (inhcollid != newcollid)
3243 (
errcode(ERRCODE_COLLATION_MISMATCH),
3244 errmsg(
"column \"%s\" has a collation conflict",
3263 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3264 errmsg(
"column \"%s\" has a storage parameter conflict",
3279 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3280 errmsg(
"column \"%s\" has a compression method conflict",
3308 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3309 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3313 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3314 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3321 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3322 errmsg(
"child column \"%s\" specifies generation expression",
3324 errhint(
"A child table column cannot be generated unless its parent column is.")));
3365 char *attributeName = newdef->
colname;
3375 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
3384 if (prevtypeid != newtypeid || prevtypmod != newtypmod)
3386 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3387 errmsg(
"inherited column \"%s\" has a type conflict",
3398 if (prevcollid != newcollid)
3400 (
errcode(ERRCODE_COLLATION_MISMATCH),
3401 errmsg(
"inherited column \"%s\" has a collation conflict",
3414 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3415 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
3430 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3431 errmsg(
"column \"%s\" has a compression method conflict",
3442 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3443 errmsg(
"inherited column \"%s\" has a generation conflict",
3453 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3454 errmsg(
"too many inheritance parents"));
3467 bool child_is_partition)
3493 foreach(entry, supers)
3498 child_is_partition);
3512 bool child_is_partition)
3523 parentobject.
classId = RelationRelationId;
3526 childobject.
classId = RelationRelationId;
3560 foreach(lc, columns)
3609 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3612 if (classtuple->relhassubclass != relhassubclass)
3614 classtuple->relhassubclass = relhassubclass;
3640 Oid oldTableSpaceId;
3646 oldTableSpaceId = rel->
rd_rel->reltablespace;
3647 if (newTableSpaceId == oldTableSpaceId ||
3657 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3658 errmsg(
"cannot move system relation \"%s\"",
3662 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3664 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3665 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3673 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3674 errmsg(
"cannot move temporary tables of other sessions")));
3696 Oid newTableSpaceId,
3712 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3720 rd_rel->relfilenode = newRelFilenumber;
3728 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3730 rd_rel->reltablespace);
3742 char relkind = classform->relkind;
3744 if (classform->reloftype && !recursing)
3746 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3747 errmsg(
"cannot rename column of typed table")));
3756 if (relkind != RELKIND_RELATION &&
3757 relkind != RELKIND_VIEW &&
3758 relkind != RELKIND_MATVIEW &&
3759 relkind != RELKIND_COMPOSITE_TYPE &&
3760 relkind != RELKIND_INDEX &&
3761 relkind != RELKIND_PARTITIONED_INDEX &&
3762 relkind != RELKIND_FOREIGN_TABLE &&
3763 relkind != RELKIND_PARTITIONED_TABLE)
3765 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3766 errmsg(
"cannot rename columns of relation \"%s\"",
3778 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3779 errmsg(
"permission denied: \"%s\" is a system catalog",
3780 NameStr(classform->relname))));
3790 const char *oldattname,
3791 const char *newattname,
3794 int expected_parents,
3838 forboth(lo, child_oids, li, child_numparents)
3843 if (childrelid == myrelid)
3846 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3857 if (expected_parents == 0 &&
3860 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3861 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3866 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3875 foreach(lo, child_oids)
3884 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3885 errmsg(
"column \"%s\" does not exist",
3889 attnum = attform->attnum;
3892 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3893 errmsg(
"cannot rename system column \"%s\"",
3905 if (attform->attinhcount > expected_parents)
3907 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3908 errmsg(
"cannot rename inherited column \"%s\"",
3969 (
errmsg(
"relation \"%s\" does not exist, skipping",
3970 stmt->relation->relname)));
3978 stmt->relation->inh,
3994 const char *oldconname,
3995 const char *newconname,
3998 int expected_parents)
4006 Assert(!myrelid || !mytypid);
4027 elog(
ERROR,
"cache lookup failed for constraint %u",
4032 (con->contype == CONSTRAINT_CHECK ||
4033 con->contype == CONSTRAINT_NOTNULL) &&
4046 forboth(lo, child_oids, li, child_numparents)
4051 if (childrelid == myrelid)
4059 if (expected_parents == 0 &&
4062 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4063 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
4067 if (con->coninhcount > expected_parents)
4069 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4070 errmsg(
"cannot rename inherited constraint \"%s\"",
4075 && (con->contype == CONSTRAINT_PRIMARY
4076 || con->contype == CONSTRAINT_UNIQUE
4077 || con->contype == CONSTRAINT_EXCLUSION))
4115 elog(
ERROR,
"cache lookup failed for type %u", typid);
4130 (
errmsg(
"relation \"%s\" does not exist, skipping",
4131 stmt->relation->relname)));
4141 stmt->relation->inh),
4182 (
errmsg(
"relation \"%s\" does not exist, skipping",
4183 stmt->relation->relname)));
4194 obj_is_index = (relkind == RELKIND_INDEX ||
4195 relkind == RELKIND_PARTITIONED_INDEX);
4196 if (obj_is_index || is_index_stmt == obj_is_index)
4200 is_index_stmt = obj_is_index;
4244 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4250 (
errcode(ERRCODE_DUPLICATE_TABLE),
4251 errmsg(
"relation \"%s\" already exists",
4261 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4262 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
4284 newrelname, namespaceId);
4289 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4290 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
4321 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4363 int expected_refcnt;
4368 (
errcode(ERRCODE_OBJECT_IN_USE),
4370 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4373 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4374 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4377 (
errcode(ERRCODE_OBJECT_IN_USE),
4379 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4404 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4405 errmsg(
"cannot alter temporary tables of other sessions")));
4517 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4793 elog(
ERROR,
"unrecognized alter table type: %d",
4801 if (cmd_lockmode > lockmode)
4802 lockmode = cmd_lockmode;
4827 ATPrepCmd(&wqueue, rel, cmd, recurse,
false, lockmode, context);
4851 bool recurse,
bool recursing,
LOCKMODE lockmode,
4864 if (rel->
rd_rel->relispartition &&
4868 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4869 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4871 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));