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);
399 bool recurse,
bool recursing,
LOCKMODE lockmode);
405 Oid *opclasses,
bool *pk_has_without_overlaps);
407 int numattrs,
int16 *attnums,
408 bool with_period,
Oid *opclasses,
409 bool *pk_has_without_overlaps);
415 Oid pkindOid,
Oid constraintOid,
bool hasperiod);
421 bool recurse,
bool recursing,
LOCKMODE lockmode,
453 bool recurse,
bool recursing,
465 char *constrname,
char *colName,
466 bool recurse,
bool recursing,
470 List *testConstraint,
List *provenConstraint);
476 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
478 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
480 bool recurse,
bool recursing);
496 bool recurse,
bool recursing,
508 Constraint *newConstraint,
bool recurse,
bool is_readd,
516 bool recurse,
bool recursing,
bool is_readd,
520 bool recurse,
bool recursing,
523 int numfksetcols,
const int16 *fksetcolsattnums,
526 char *constraintname,
531 Oid *pfeqoperators,
Oid *ppeqoperators,
532 Oid *ffeqoperators,
int numfkdelsetcols,
533 int16 *fkdelsetcols,
bool is_internal,
538 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
539 int numfkdelsetcols,
int16 *fkdelsetcols,
541 Oid parentDelTrigger,
Oid parentUpdTrigger,
546 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
547 int numfkdelsetcols,
int16 *fkdelsetcols,
548 bool old_check_ok,
LOCKMODE lockmode,
549 Oid parentInsTrigger,
Oid parentUpdTrigger,
559 Oid parentInsTrigger,
Oid parentUpdTrigger,
560 Oid *insertTrigOid,
Oid *updateTrigOid);
564 Oid parentDelTrigger,
Oid parentUpdTrigger,
565 Oid *deleteTrigOid,
Oid *updateTrigOid);
568 Oid parentConstrOid,
int numfks,
571 Oid parentInsTrigger,
572 Oid parentUpdTrigger,
576 Oid *deleteTriggerOid,
577 Oid *updateTriggerOid);
580 Oid *insertTriggerOid,
581 Oid *updateTriggerOid);
584 bool missing_ok,
LOCKMODE lockmode);
587 bool recurse,
bool recursing,
588 bool missing_ok,
LOCKMODE lockmode);
591 bool recurse,
bool recursing,
609 const char *conname);
615 Oid oldOwnerId,
Oid newOwnerId);
626 const char *tablespacename,
LOCKMODE lockmode);
633 char fires_when,
bool skip_system,
bool recurse,
636 char fires_when,
LOCKMODE lockmode);
655 Oid oldRelOid,
void *
arg);
660 List **partexprs,
Oid *partopclass,
Oid *partcollation,
664 bool expect_detached);
670 List *partConstraint,
671 bool validate_default);
679 bool concurrent,
Oid defaultPartOid);
723 List *old_constraints;
726 List *cookedDefaults;
748 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
750 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
751 errmsg(
"ON COMMIT can only be used on temporary tables")));
753 if (
stmt->partspec != NULL)
755 if (relkind != RELKIND_RELATION)
756 elog(
ERROR,
"unexpected relkind: %d", (
int) relkind);
758 relkind = RELKIND_PARTITIONED_TABLE;
764 if (relkind == RELKIND_PARTITIONED_TABLE &&
765 stmt->relation->relpersistence == RELPERSISTENCE_UNLOGGED)
767 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
768 errmsg(
"partitioned tables cannot be unlogged")));
784 if (
stmt->relation->relpersistence == RELPERSISTENCE_TEMP
787 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
788 errmsg(
"cannot create temporary table within security-restricted operation")));
811 foreach(listptr,
stmt->inhRelations)
823 (
errcode(ERRCODE_DUPLICATE_TABLE),
824 errmsg(
"relation \"%s\" would be inherited from more than once",
834 if (
stmt->tablespacename)
840 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
841 errmsg(
"cannot specify default tablespace for partitioned relations")));
843 else if (
stmt->partbound)
869 if (tablespaceId == GLOBALTABLESPACE_OID)
871 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
872 errmsg(
"only shared relations can be placed in pg_global tablespace")));
889 case RELKIND_PARTITIONED_TABLE:
896 if (
stmt->ofTypename)
916 stmt->relation->relpersistence,
917 stmt->partbound != NULL,
918 &old_constraints, &old_notnulls);
941 cookedDefaults =
NIL;
944 foreach(listptr,
stmt->tableElts)
963 rawDefaults =
lappend(rawDefaults, rawEnt);
964 attr->atthasdef =
true;
980 cookedDefaults =
lappend(cookedDefaults, cooked);
981 attr->atthasdef =
true;
990 if (
stmt->accessMethod != NULL)
992 Assert(RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE);
995 else if (RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE)
1003 if (RELKIND_HAS_TABLE_AM(relkind) && !
OidIsValid(accessMethodId))
1024 stmt->relation->relpersistence,
1063 true,
true,
false, queryString);
1071 if (
stmt->partbound)
1088 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1090 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1091 errmsg(
"\"%s\" is not partitioned",
1129 NULL,
false,
false);
1184 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1185 errmsg(
"cannot partition using more than %d columns",
1197 partattrs, &partexprs, partopclass,
1198 partcollation,
stmt->partspec->strategy);
1202 partopclass, partcollation);
1215 if (
stmt->partbound)
1229 foreach(cell, idxlist)
1236 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1240 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1241 errmsg(
"cannot create foreign partition of partitioned table \"%s\"",
1243 errdetail(
"Table \"%s\" contains indexes that are unique.",
1257 attmap, &constraintOid);
1264 false,
false,
false,
false,
false);
1292 if (
stmt->constraints)
1294 true,
true,
false, queryString);
1372 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1373 errmsg(
"too many array dimensions"));
1377 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1378 errmsg(
"column \"%s\" cannot be declared SETOF",
1382 atttypid, atttypmod, attdim);
1391 att->attinhcount = entry->
inhcount;
1392 att->attidentity = entry->
identity;
1396 att->attstorage = entry->
storage;
1419 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1425 (
errmsg(
"schema \"%s\" does not exist, skipping",
1433 if (rentry->
kind == rightkind)
1463 if (rentry->
kind == rightkind)
1468 if (wentry->
kind == wrongkind)
1473 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1504 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1505 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1508 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1509 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1522 relkind = RELKIND_RELATION;
1526 relkind = RELKIND_INDEX;
1530 relkind = RELKIND_SEQUENCE;
1534 relkind = RELKIND_VIEW;
1538 relkind = RELKIND_MATVIEW;
1542 relkind = RELKIND_FOREIGN_TABLE;
1546 elog(
ERROR,
"unrecognized drop object type: %d",
1575 state.expected_relkind = relkind;
1598 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1610 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1612 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1613 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1623 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1625 state.heap_lockmode,
1629 obj.
classId = RelationRelationId;
1657 bool invalid_system_index =
false;
1692 is_partition = classform->relispartition;
1695 state->actual_relkind = classform->relkind;
1696 state->actual_relpersistence = classform->relpersistence;
1706 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1708 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1715 state->expected_relkind);
1730 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1744 indisvalid = indexform->indisvalid;
1749 invalid_system_index =
true;
1755 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1756 errmsg(
"permission denied: \"%s\" is a system catalog",
1770 relOid != oldRelOid)
1783 if (is_partition && relOid != oldRelOid)
1817 foreach(cell,
stmt->relations)
1821 bool recurse = rv->
inh;
1847 relids_logged =
lappend_oid(relids_logged, myrelid);
1856 foreach(child, children)
1895 relids_logged =
lappend_oid(relids_logged, childrelid);
1898 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1900 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1901 errmsg(
"cannot truncate only a partitioned table"),
1902 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1906 stmt->behavior,
stmt->restart_seqs,
false);
1933 List *relids_logged,
1935 bool run_as_table_owner)
1939 HTAB *ft_htab = NULL;
1965 if (newrelids ==
NIL)
1968 foreach(cell, newrelids)
1975 (
errmsg(
"truncate cascades to table \"%s\"",
1985 relids_logged =
lappend_oid(relids_logged, relid);
1995 #ifdef USE_ASSERT_CHECKING
2016 foreach(seqcell, seqlist)
2050 resultRelInfo = resultRelInfos;
2071 resultRelInfo = resultRelInfos;
2076 if (run_as_table_owner)
2080 if (run_as_table_owner)
2095 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2105 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2116 memset(&hctl, 0,
sizeof(
HASHCTL));
2121 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2181 toast_relid = rel->
rd_rel->reltoastrelid;
2188 toastrel->
rd_rel->relpersistence);
2234 foreach(cell, seq_relids)
2248 if (relids_logged !=
NIL)
2257 foreach(cell, relids_logged)
2280 resultRelInfo = resultRelInfos;
2285 if (run_as_table_owner)
2289 if (run_as_table_owner)
2328 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2335 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2336 errmsg(
"cannot truncate foreign table \"%s\"",
2339 else if (reltuple->relkind != RELKIND_RELATION &&
2340 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2342 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2355 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2356 errmsg(
"permission denied: \"%s\" is a system catalog",
2392 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2393 errmsg(
"cannot truncate temporary tables of other sessions")));
2411 case TYPSTORAGE_PLAIN:
2413 case TYPSTORAGE_EXTERNAL:
2415 case TYPSTORAGE_EXTENDED:
2417 case TYPSTORAGE_MAIN:
2492 bool is_partition,
List **supconstr,
List **supnotnulls)
2497 bool have_bogus_defaults =
false;
2499 static Node bogus_marker = {0};
2516 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2517 errmsg(
"tables can have at most %d columns",
2534 for (
int coldefpos = 0; coldefpos <
list_length(columns); coldefpos++)
2538 if (!is_partition && coldef->
typeName == NULL)
2547 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2548 errmsg(
"column \"%s\" does not exist",
2553 for (
int restpos = coldefpos + 1; restpos <
list_length(columns);)
2573 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2574 errmsg(
"column \"%s\" specified more than once",
2589 saved_columns = columns;
2605 List *inherited_defaults;
2606 List *cols_with_defaults;
2627 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !is_partition)
2629 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2630 errmsg(
"cannot inherit from partitioned table \"%s\"",
2632 if (relation->
rd_rel->relispartition && !is_partition)
2634 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2635 errmsg(
"cannot inherit from partition \"%s\"",
2638 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2639 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2640 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2642 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2643 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2651 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2652 relpersistence == RELPERSISTENCE_TEMP)
2654 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2655 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2659 if (relpersistence != RELPERSISTENCE_TEMP &&
2660 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2662 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2664 ?
"cannot inherit from temporary relation \"%s\""
2665 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2669 if (relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
2672 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2674 ?
"cannot inherit from temporary relation of another session"
2675 :
"cannot create as partition of temporary relation of another session")));
2686 constr = tupleDesc->
constr;
2696 inherited_defaults = cols_with_defaults =
NIL;
2712 char *attributeName =
NameStr(attribute->attname);
2720 if (attribute->attisdropped)
2727 attribute->atttypmod, attribute->attcollation);
2728 newdef->
storage = attribute->attstorage;
2729 newdef->
generated = attribute->attgenerated;
2740 newdef->
identity = attribute->attidentity;
2747 if (exist_attno > 0)
2754 newattmap->
attnums[parent_attno - 1] = exist_attno;
2769 inh_columns =
lappend(inh_columns, newdef);
2771 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2784 if (attribute->atthasdef)
2789 if (this_default == NULL)
2790 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2799 inherited_defaults =
lappend(inherited_defaults, this_default);
2800 cols_with_defaults =
lappend(cols_with_defaults, mergeddef);
2808 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2812 bool found_whole_row;
2826 if (found_whole_row)
2828 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2829 errmsg(
"cannot convert whole-row table reference"),
2830 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2846 have_bogus_defaults =
true;
2863 bool found_whole_row;
2866 if (check[
i].ccnoinherit)
2880 if (found_whole_row)
2882 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2883 errmsg(
"cannot convert whole-row table reference"),
2884 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2900 nn->attnum = newattmap->
attnums[nn->attnum - 1];
2902 nnconstraints =
lappend(nnconstraints, nn);
2921 if (inh_columns !=
NIL)
2923 int newcol_attno = 0;
2925 foreach(lc, columns)
2928 char *attributeName = newdef->
colname;
2943 if (exist_attno > 0)
2955 inh_columns =
lappend(inh_columns, newdef);
2959 columns = inh_columns;
2967 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2968 errmsg(
"tables can have at most %d columns",
2979 foreach(lc, saved_columns)
3004 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3005 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3009 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3010 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3017 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3018 errmsg(
"child column \"%s\" specifies generation expression",
3020 errhint(
"A child table column cannot be generated unless its parent column is.")));
3045 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3046 errmsg(
"column \"%s\" does not exist",
3055 if (have_bogus_defaults)
3057 foreach(lc, columns)
3065 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3066 errmsg(
"column \"%s\" inherits conflicting generation expressions",
3068 errhint(
"To resolve the conflict, specify a generation expression explicitly.")));
3071 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3072 errmsg(
"column \"%s\" inherits conflicting default values",
3074 errhint(
"To resolve the conflict, specify a default explicitly.")));
3079 *supconstr = constraints;
3080 *supnotnulls = nnconstraints;
3107 foreach(lc, constraints)
3123 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3124 errmsg(
"too many inheritance parents"));
3130 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3141 newcon->
expr = expr;
3143 return lappend(constraints, newcon);
3170 char *attributeName = newdef->
colname;
3179 if (exist_attno == newcol_attno)
3181 (
errmsg(
"merging column \"%s\" with inherited definition",
3185 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
3186 errdetail(
"User-specified column moved to the position of the inherited column.")));
3195 if (inhtypeid != newtypeid || inhtypmod != newtypmod)
3197 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3198 errmsg(
"column \"%s\" has a type conflict",
3209 if (inhcollid != newcollid)
3211 (
errcode(ERRCODE_COLLATION_MISMATCH),
3212 errmsg(
"column \"%s\" has a collation conflict",
3231 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3232 errmsg(
"column \"%s\" has a storage parameter conflict",
3247 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3248 errmsg(
"column \"%s\" has a compression method conflict",
3276 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3277 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3281 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3282 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3289 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3290 errmsg(
"child column \"%s\" specifies generation expression",
3292 errhint(
"A child table column cannot be generated unless its parent column is.")));
3333 char *attributeName = newdef->
colname;
3343 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
3352 if (prevtypeid != newtypeid || prevtypmod != newtypmod)
3354 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3355 errmsg(
"inherited column \"%s\" has a type conflict",
3366 if (prevcollid != newcollid)
3368 (
errcode(ERRCODE_COLLATION_MISMATCH),
3369 errmsg(
"inherited column \"%s\" has a collation conflict",
3382 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3383 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
3398 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3399 errmsg(
"column \"%s\" has a compression method conflict",
3410 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3411 errmsg(
"inherited column \"%s\" has a generation conflict",
3421 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3422 errmsg(
"too many inheritance parents"));
3435 bool child_is_partition)
3461 foreach(entry, supers)
3466 child_is_partition);
3480 bool child_is_partition)
3491 parentobject.
classId = RelationRelationId;
3494 childobject.
classId = RelationRelationId;
3528 foreach(lc, columns)
3577 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3580 if (classtuple->relhassubclass != relhassubclass)
3582 classtuple->relhassubclass = relhassubclass;
3608 Oid oldTableSpaceId;
3614 oldTableSpaceId = rel->
rd_rel->reltablespace;
3615 if (newTableSpaceId == oldTableSpaceId ||
3625 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3626 errmsg(
"cannot move system relation \"%s\"",
3630 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3632 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3633 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3641 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3642 errmsg(
"cannot move temporary tables of other sessions")));
3664 Oid newTableSpaceId,
3680 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3688 rd_rel->relfilenode = newRelFilenumber;
3696 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3698 rd_rel->reltablespace);
3710 char relkind = classform->relkind;
3712 if (classform->reloftype && !recursing)
3714 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3715 errmsg(
"cannot rename column of typed table")));
3724 if (relkind != RELKIND_RELATION &&
3725 relkind != RELKIND_VIEW &&
3726 relkind != RELKIND_MATVIEW &&
3727 relkind != RELKIND_COMPOSITE_TYPE &&
3728 relkind != RELKIND_INDEX &&
3729 relkind != RELKIND_PARTITIONED_INDEX &&
3730 relkind != RELKIND_FOREIGN_TABLE &&
3731 relkind != RELKIND_PARTITIONED_TABLE)
3733 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3734 errmsg(
"cannot rename columns of relation \"%s\"",
3746 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3747 errmsg(
"permission denied: \"%s\" is a system catalog",
3748 NameStr(classform->relname))));
3758 const char *oldattname,
3759 const char *newattname,
3762 int expected_parents,
3806 forboth(lo, child_oids, li, child_numparents)
3811 if (childrelid == myrelid)
3814 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3825 if (expected_parents == 0 &&
3828 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3829 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3834 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3843 foreach(lo, child_oids)
3852 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3853 errmsg(
"column \"%s\" does not exist",
3857 attnum = attform->attnum;
3860 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3861 errmsg(
"cannot rename system column \"%s\"",
3873 if (attform->attinhcount > expected_parents)
3875 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3876 errmsg(
"cannot rename inherited column \"%s\"",
3937 (
errmsg(
"relation \"%s\" does not exist, skipping",
3938 stmt->relation->relname)));
3946 stmt->relation->inh,
3962 const char *oldconname,
3963 const char *newconname,
3966 int expected_parents)
3974 Assert(!myrelid || !mytypid);
3995 elog(
ERROR,
"cache lookup failed for constraint %u",
4000 (con->contype == CONSTRAINT_CHECK ||
4001 con->contype == CONSTRAINT_NOTNULL) &&
4014 forboth(lo, child_oids, li, child_numparents)
4019 if (childrelid == myrelid)
4027 if (expected_parents == 0 &&
4030 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4031 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
4035 if (con->coninhcount > expected_parents)
4037 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4038 errmsg(
"cannot rename inherited constraint \"%s\"",
4043 && (con->contype == CONSTRAINT_PRIMARY
4044 || con->contype == CONSTRAINT_UNIQUE
4045 || con->contype == CONSTRAINT_EXCLUSION))
4083 elog(
ERROR,
"cache lookup failed for type %u", typid);
4098 (
errmsg(
"relation \"%s\" does not exist, skipping",
4099 stmt->relation->relname)));
4109 stmt->relation->inh),
4150 (
errmsg(
"relation \"%s\" does not exist, skipping",
4151 stmt->relation->relname)));
4162 obj_is_index = (relkind == RELKIND_INDEX ||
4163 relkind == RELKIND_PARTITIONED_INDEX);
4164 if (obj_is_index || is_index_stmt == obj_is_index)
4168 is_index_stmt = obj_is_index;
4212 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4218 (
errcode(ERRCODE_DUPLICATE_TABLE),
4219 errmsg(
"relation \"%s\" already exists",
4229 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4230 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
4252 newrelname, namespaceId);
4257 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4258 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
4289 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4331 int expected_refcnt;
4336 (
errcode(ERRCODE_OBJECT_IN_USE),
4338 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4341 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4342 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4345 (
errcode(ERRCODE_OBJECT_IN_USE),
4347 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4372 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4373 errmsg(
"cannot alter temporary tables of other sessions")));
4485 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4761 elog(
ERROR,
"unrecognized alter table type: %d",
4769 if (cmd_lockmode > lockmode)
4770 lockmode = cmd_lockmode;
4819 bool recurse,
bool recursing,
LOCKMODE lockmode,
4832 if (rel->
rd_rel->relispartition &&
4836 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4837 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4839 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
5065 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5066 errmsg(
"cannot change persistence setting twice")));
5082 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5083 errmsg(
"cannot have multiple SET ACCESS METHOD subcommands")));
5194 elog(
ERROR,
"unrecognized alter table type: %d",
5228 foreach(ltab, *wqueue)
5244 foreach(lcmd, subcmds)
5266 foreach(ltab, *wqueue)
5275 if (((tab->
relkind == RELKIND_RELATION ||
5276 tab->
relkind == RELKIND_PARTITIONED_TABLE) &&
5278 tab->
relkind == RELKIND_MATVIEW)