97 #include "utils/fmgroids.h"
164 #define AT_NUM_PASSES (AT_PASS_MISC + 1)
262 gettext_noop(
"sequence \"%s\" does not exist, skipping"),
264 gettext_noop(
"Use DROP SEQUENCE to remove a sequence.")},
273 gettext_noop(
"materialized view \"%s\" does not exist"),
274 gettext_noop(
"materialized view \"%s\" does not exist, skipping"),
276 gettext_noop(
"Use DROP MATERIALIZED VIEW to remove a materialized view.")},
278 ERRCODE_UNDEFINED_OBJECT,
283 {RELKIND_COMPOSITE_TYPE,
284 ERRCODE_UNDEFINED_OBJECT,
289 {RELKIND_FOREIGN_TABLE,
290 ERRCODE_UNDEFINED_OBJECT,
292 gettext_noop(
"foreign table \"%s\" does not exist, skipping"),
294 gettext_noop(
"Use DROP FOREIGN TABLE to remove a foreign table.")},
295 {RELKIND_PARTITIONED_TABLE,
301 {RELKIND_PARTITIONED_INDEX,
302 ERRCODE_UNDEFINED_OBJECT,
307 {
'\0', 0, NULL, NULL, NULL, NULL}
325 #define ATT_TABLE 0x0001
326 #define ATT_VIEW 0x0002
327 #define ATT_MATVIEW 0x0004
328 #define ATT_INDEX 0x0008
329 #define ATT_COMPOSITE_TYPE 0x0010
330 #define ATT_FOREIGN_TABLE 0x0020
331 #define ATT_PARTITIONED_INDEX 0x0040
332 #define ATT_SEQUENCE 0x0080
353 #define child_dependency_type(child_is_partition) \
354 ((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
362 bool is_partition,
List **supconstr);
369 bool child_is_partition);
372 bool child_is_partition);
380 bool recurse,
bool recursing,
LOCKMODE lockmode);
386 bool recurse,
bool recursing,
LOCKMODE lockmode);
394 int numattrs,
int16 *attnums,
401 Oid pkindOid,
Oid constraintOid);
407 bool recurse,
bool recursing,
LOCKMODE lockmode,
439 bool recurse,
bool recursing,
453 const char *colName,
LOCKMODE lockmode);
455 const char *colName,
LOCKMODE lockmode);
458 List *testConstraint,
List *provenConstraint);
464 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
466 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
468 bool recurse,
bool recursing);
484 bool recurse,
bool recursing,
493 Constraint *newConstraint,
bool recurse,
bool is_readd,
501 bool recurse,
bool recursing,
bool is_readd,
505 bool recurse,
bool recursing,
510 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
511 int numfkdelsetcols,
int16 *fkdelsetcols,
513 Oid parentDelTrigger,
Oid parentUpdTrigger);
515 int numfksetcols,
const int16 *fksetcolsattnums,
520 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
521 int numfkdelsetcols,
int16 *fkdelsetcols,
522 bool old_check_ok,
LOCKMODE lockmode,
523 Oid parentInsTrigger,
Oid parentUpdTrigger);
532 Oid parentInsTrigger,
Oid parentUpdTrigger,
533 Oid *insertTrigOid,
Oid *updateTrigOid);
537 Oid parentDelTrigger,
Oid parentUpdTrigger,
538 Oid *deleteTrigOid,
Oid *updateTrigOid);
541 Oid parentConstrOid,
int numfks,
544 Oid parentInsTrigger,
545 Oid parentUpdTrigger,
549 Oid *deleteTriggerOid,
550 Oid *updateTriggerOid);
553 Oid *insertTriggerOid,
554 Oid *updateTriggerOid);
557 bool recurse,
bool recursing,
558 bool missing_ok,
LOCKMODE lockmode);
561 bool recurse,
bool recursing,
579 const char *conname);
585 Oid oldOwnerId,
Oid newOwnerId);
595 const char *tablespacename,
LOCKMODE lockmode);
602 char fires_when,
bool skip_system,
bool recurse,
605 char fires_when,
LOCKMODE lockmode);
624 Oid oldRelOid,
void *
arg);
629 List **partexprs,
Oid *partopclass,
Oid *partcollation,
633 bool expect_detached);
639 List *partConstraint,
640 bool validate_default);
648 bool concurrent,
Oid defaultPartOid);
696 List *old_constraints;
698 List *cookedDefaults;
719 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
721 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
722 errmsg(
"ON COMMIT can only be used on temporary tables")));
724 if (
stmt->partspec != NULL)
726 if (relkind != RELKIND_RELATION)
727 elog(
ERROR,
"unexpected relkind: %d", (
int) relkind);
729 relkind = RELKIND_PARTITIONED_TABLE;
749 if (
stmt->relation->relpersistence == RELPERSISTENCE_TEMP
752 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
753 errmsg(
"cannot create temporary table within security-restricted operation")));
776 foreach(listptr,
stmt->inhRelations)
788 (
errcode(ERRCODE_DUPLICATE_TABLE),
789 errmsg(
"relation \"%s\" would be inherited from more than once",
799 if (
stmt->tablespacename)
805 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
806 errmsg(
"cannot specify default tablespace for partitioned relations")));
808 else if (
stmt->partbound)
834 if (tablespaceId == GLOBALTABLESPACE_OID)
836 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
837 errmsg(
"only shared relations can be placed in pg_global tablespace")));
854 case RELKIND_PARTITIONED_TABLE:
861 if (
stmt->ofTypename)
881 stmt->relation->relpersistence,
882 stmt->partbound != NULL,
905 cookedDefaults =
NIL;
908 foreach(listptr,
stmt->tableElts)
927 rawDefaults =
lappend(rawDefaults, rawEnt);
928 attr->atthasdef =
true;
944 cookedDefaults =
lappend(cookedDefaults, cooked);
945 attr->atthasdef =
true;
954 if (
stmt->accessMethod != NULL)
956 Assert(RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE);
959 else if (RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE)
967 if (RELKIND_HAS_TABLE_AM(relkind) && !
OidIsValid(accessMethodId))
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);
1325 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1326 errmsg(
"too many array dimensions"));
1330 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1331 errmsg(
"column \"%s\" cannot be declared SETOF",
1335 atttypid, atttypmod, attdim);
1344 att->attinhcount = entry->
inhcount;
1345 att->attidentity = entry->
identity;
1349 att->attstorage = entry->
storage;
1372 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1378 (
errmsg(
"schema \"%s\" does not exist, skipping",
1386 if (rentry->
kind == rightkind)
1416 if (rentry->
kind == rightkind)
1421 if (wentry->
kind == wrongkind)
1426 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1457 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1458 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1461 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1462 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1475 relkind = RELKIND_RELATION;
1479 relkind = RELKIND_INDEX;
1483 relkind = RELKIND_SEQUENCE;
1487 relkind = RELKIND_VIEW;
1491 relkind = RELKIND_MATVIEW;
1495 relkind = RELKIND_FOREIGN_TABLE;
1499 elog(
ERROR,
"unrecognized drop object type: %d",
1528 state.expected_relkind = relkind;
1551 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1563 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1565 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1566 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1576 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1578 state.heap_lockmode,
1582 obj.
classId = RelationRelationId;
1610 bool invalid_system_index =
false;
1645 is_partition = classform->relispartition;
1648 state->actual_relkind = classform->relkind;
1649 state->actual_relpersistence = classform->relpersistence;
1659 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1661 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1668 state->expected_relkind);
1683 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1697 indisvalid = indexform->indisvalid;
1702 invalid_system_index =
true;
1708 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1709 errmsg(
"permission denied: \"%s\" is a system catalog",
1723 relOid != oldRelOid)
1736 if (is_partition && relOid != oldRelOid)
1770 foreach(cell,
stmt->relations)
1774 bool recurse = rv->
inh;
1800 relids_logged =
lappend_oid(relids_logged, myrelid);
1809 foreach(child, children)
1848 relids_logged =
lappend_oid(relids_logged, childrelid);
1851 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1853 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1854 errmsg(
"cannot truncate only a partitioned table"),
1855 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1859 stmt->behavior,
stmt->restart_seqs,
false);
1886 List *relids_logged,
1888 bool run_as_table_owner)
1892 HTAB *ft_htab = NULL;
1918 if (newrelids ==
NIL)
1921 foreach(cell, newrelids)
1928 (
errmsg(
"truncate cascades to table \"%s\"",
1938 relids_logged =
lappend_oid(relids_logged, relid);
1948 #ifdef USE_ASSERT_CHECKING
1969 foreach(seqcell, seqlist)
2003 resultRelInfo = resultRelInfos;
2024 resultRelInfo = resultRelInfos;
2029 if (run_as_table_owner)
2033 if (run_as_table_owner)
2048 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2058 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2069 memset(&hctl, 0,
sizeof(
HASHCTL));
2074 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2134 toast_relid = rel->
rd_rel->reltoastrelid;
2141 toastrel->
rd_rel->relpersistence);
2187 foreach(cell, seq_relids)
2201 if (relids_logged !=
NIL)
2210 foreach(cell, relids_logged)
2233 resultRelInfo = resultRelInfos;
2238 if (run_as_table_owner)
2242 if (run_as_table_owner)
2281 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2288 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2289 errmsg(
"cannot truncate foreign table \"%s\"",
2292 else if (reltuple->relkind != RELKIND_RELATION &&
2293 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2295 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2308 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2309 errmsg(
"permission denied: \"%s\" is a system catalog",
2345 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2346 errmsg(
"cannot truncate temporary tables of other sessions")));
2364 case TYPSTORAGE_PLAIN:
2366 case TYPSTORAGE_EXTERNAL:
2368 case TYPSTORAGE_EXTENDED:
2370 case TYPSTORAGE_MAIN:
2440 bool is_partition,
List **supconstr)
2444 bool have_bogus_defaults =
false;
2446 static Node bogus_marker = {0};
2463 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2464 errmsg(
"tables can have at most %d columns",
2481 for (
int coldefpos = 0; coldefpos <
list_length(columns); coldefpos++)
2485 if (!is_partition && coldef->
typeName == NULL)
2494 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2495 errmsg(
"column \"%s\" does not exist",
2500 for (
int restpos = coldefpos + 1; restpos <
list_length(columns);)
2520 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2521 errmsg(
"column \"%s\" specified more than once",
2536 saved_columns = columns;
2552 List *inherited_defaults;
2553 List *cols_with_defaults;
2572 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !is_partition)
2574 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2575 errmsg(
"cannot inherit from partitioned table \"%s\"",
2577 if (relation->
rd_rel->relispartition && !is_partition)
2579 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2580 errmsg(
"cannot inherit from partition \"%s\"",
2583 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2584 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2585 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2587 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2588 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2596 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2597 relpersistence == RELPERSISTENCE_TEMP)
2599 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2600 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2604 if (relpersistence != RELPERSISTENCE_TEMP &&
2605 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2607 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2609 ?
"cannot inherit from temporary relation \"%s\""
2610 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2614 if (relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
2617 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2619 ?
"cannot inherit from temporary relation of another session"
2620 :
"cannot create as partition of temporary relation of another session")));
2631 constr = tupleDesc->
constr;
2641 inherited_defaults = cols_with_defaults =
NIL;
2648 char *attributeName =
NameStr(attribute->attname);
2656 if (attribute->attisdropped)
2663 attribute->atttypmod, attribute->attcollation);
2665 newdef->
storage = attribute->attstorage;
2666 newdef->
generated = attribute->attgenerated;
2677 newdef->
identity = attribute->attidentity;
2684 if (exist_attno > 0)
2691 newattmap->
attnums[parent_attno - 1] = exist_attno;
2706 inh_columns =
lappend(inh_columns, newdef);
2708 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2715 if (attribute->atthasdef)
2720 if (this_default == NULL)
2721 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2730 inherited_defaults =
lappend(inherited_defaults, this_default);
2731 cols_with_defaults =
lappend(cols_with_defaults, mergeddef);
2739 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2743 bool found_whole_row;
2757 if (found_whole_row)
2759 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2760 errmsg(
"cannot convert whole-row table reference"),
2761 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2777 have_bogus_defaults =
true;
2794 bool found_whole_row;
2797 if (check[
i].ccnoinherit)
2811 if (found_whole_row)
2813 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2814 errmsg(
"cannot convert whole-row table reference"),
2815 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2839 if (inh_columns !=
NIL)
2841 int newcol_attno = 0;
2843 foreach(lc, columns)
2846 char *attributeName = newdef->
colname;
2861 if (exist_attno > 0)
2873 inh_columns =
lappend(inh_columns, newdef);
2877 columns = inh_columns;
2885 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2886 errmsg(
"tables can have at most %d columns",
2898 foreach(lc, saved_columns)
2924 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2925 errmsg(
"column \"%s\" inherits from generated column but specifies default",
2929 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2930 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
2937 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2938 errmsg(
"child column \"%s\" specifies generation expression",
2940 errhint(
"A child table column cannot be generated unless its parent column is.")));
2965 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2966 errmsg(
"column \"%s\" does not exist",
2975 if (have_bogus_defaults)
2977 foreach(lc, columns)
2985 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2986 errmsg(
"column \"%s\" inherits conflicting generation expressions",
2988 errhint(
"To resolve the conflict, specify a generation expression explicitly.")));
2991 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2992 errmsg(
"column \"%s\" inherits conflicting default values",
2994 errhint(
"To resolve the conflict, specify a default explicitly.")));
2999 *supconstr = constraints;
3026 foreach(lc, constraints)
3042 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3043 errmsg(
"too many inheritance parents"));
3049 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3060 newcon->
expr = expr;
3062 return lappend(constraints, newcon);
3089 char *attributeName = newdef->
colname;
3098 if (exist_attno == newcol_attno)
3100 (
errmsg(
"merging column \"%s\" with inherited definition",
3104 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
3105 errdetail(
"User-specified column moved to the position of the inherited column.")));
3114 if (inhtypeid != newtypeid || inhtypmod != newtypmod)
3116 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3117 errmsg(
"column \"%s\" has a type conflict",
3128 if (inhcollid != newcollid)
3130 (
errcode(ERRCODE_COLLATION_MISMATCH),
3131 errmsg(
"column \"%s\" has a collation conflict",
3150 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3151 errmsg(
"column \"%s\" has a storage parameter conflict",
3166 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3167 errmsg(
"column \"%s\" has a compression method conflict",
3195 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3196 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3200 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3201 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3208 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3209 errmsg(
"child column \"%s\" specifies generation expression",
3211 errhint(
"A child table column cannot be generated unless its parent column is.")));
3252 char *attributeName = newdef->
colname;
3262 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
3271 if (prevtypeid != newtypeid || prevtypmod != newtypmod)
3273 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3274 errmsg(
"inherited column \"%s\" has a type conflict",
3290 if (prevcollid != newcollid)
3292 (
errcode(ERRCODE_COLLATION_MISMATCH),
3293 errmsg(
"inherited column \"%s\" has a collation conflict",
3306 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3307 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
3322 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3323 errmsg(
"column \"%s\" has a compression method conflict",
3334 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3335 errmsg(
"inherited column \"%s\" has a generation conflict",
3345 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3346 errmsg(
"too many inheritance parents"));
3359 bool child_is_partition)
3385 foreach(entry, supers)
3390 child_is_partition);
3404 bool child_is_partition)
3415 parentobject.
classId = RelationRelationId;
3418 childobject.
classId = RelationRelationId;
3452 foreach(lc, columns)
3501 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3504 if (classtuple->relhassubclass != relhassubclass)
3506 classtuple->relhassubclass = relhassubclass;
3532 Oid oldTableSpaceId;
3538 oldTableSpaceId = rel->
rd_rel->reltablespace;
3539 if (newTableSpaceId == oldTableSpaceId ||
3549 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3550 errmsg(
"cannot move system relation \"%s\"",
3554 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3556 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3557 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3565 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3566 errmsg(
"cannot move temporary tables of other sessions")));
3588 Oid newTableSpaceId,
3603 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3610 rd_rel->relfilenode = newRelFilenumber;
3617 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3619 rd_rel->reltablespace);
3631 char relkind = classform->relkind;
3633 if (classform->reloftype && !recursing)
3635 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3636 errmsg(
"cannot rename column of typed table")));
3645 if (relkind != RELKIND_RELATION &&
3646 relkind != RELKIND_VIEW &&
3647 relkind != RELKIND_MATVIEW &&
3648 relkind != RELKIND_COMPOSITE_TYPE &&
3649 relkind != RELKIND_INDEX &&
3650 relkind != RELKIND_PARTITIONED_INDEX &&
3651 relkind != RELKIND_FOREIGN_TABLE &&
3652 relkind != RELKIND_PARTITIONED_TABLE)
3654 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3655 errmsg(
"cannot rename columns of relation \"%s\"",
3667 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3668 errmsg(
"permission denied: \"%s\" is a system catalog",
3669 NameStr(classform->relname))));
3679 const char *oldattname,
3680 const char *newattname,
3683 int expected_parents,
3727 forboth(lo, child_oids, li, child_numparents)
3732 if (childrelid == myrelid)
3735 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3746 if (expected_parents == 0 &&
3749 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3750 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3755 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3764 foreach(lo, child_oids)
3773 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3774 errmsg(
"column \"%s\" does not exist",
3778 attnum = attform->attnum;
3781 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3782 errmsg(
"cannot rename system column \"%s\"",
3794 if (attform->attinhcount > expected_parents)
3796 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3797 errmsg(
"cannot rename inherited column \"%s\"",
3858 (
errmsg(
"relation \"%s\" does not exist, skipping",
3859 stmt->relation->relname)));
3867 stmt->relation->inh,
3883 const char *oldconname,
3884 const char *newconname,
3887 int expected_parents)
3895 Assert(!myrelid || !mytypid);
3916 elog(
ERROR,
"cache lookup failed for constraint %u",
3920 if (myrelid && con->contype == CONSTRAINT_CHECK && !con->connoinherit)
3932 forboth(lo, child_oids, li, child_numparents)
3937 if (childrelid == myrelid)
3945 if (expected_parents == 0 &&
3948 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3949 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
3953 if (con->coninhcount > expected_parents)
3955 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3956 errmsg(
"cannot rename inherited constraint \"%s\"",
3961 && (con->contype == CONSTRAINT_PRIMARY
3962 || con->contype == CONSTRAINT_UNIQUE
3963 || con->contype == CONSTRAINT_EXCLUSION))
4001 elog(
ERROR,
"cache lookup failed for type %u", typid);
4016 (
errmsg(
"relation \"%s\" does not exist, skipping",
4017 stmt->relation->relname)));
4027 stmt->relation->inh),
4068 (
errmsg(
"relation \"%s\" does not exist, skipping",
4069 stmt->relation->relname)));
4080 obj_is_index = (relkind == RELKIND_INDEX ||
4081 relkind == RELKIND_PARTITIONED_INDEX);
4082 if (obj_is_index || is_index_stmt == obj_is_index)
4086 is_index_stmt = obj_is_index;
4129 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4134 (
errcode(ERRCODE_DUPLICATE_TABLE),
4135 errmsg(
"relation \"%s\" already exists",
4145 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4146 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
4167 newrelname, namespaceId);
4172 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4173 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
4204 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4246 int expected_refcnt;
4251 (
errcode(ERRCODE_OBJECT_IN_USE),
4253 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4256 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4257 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4260 (
errcode(ERRCODE_OBJECT_IN_USE),
4262 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4287 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4288 errmsg(
"cannot alter temporary tables of other sessions")));
4400 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4693 elog(
ERROR,
"unrecognized alter table type: %d",
4701 if (cmd_lockmode > lockmode)
4702 lockmode = cmd_lockmode;
4751 bool recurse,
bool recursing,
LOCKMODE lockmode,
4764 if (rel->
rd_rel->relispartition &&
4768 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4769 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4771 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
4972 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4973 errmsg(
"cannot change persistence setting twice")));
4987 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4988 errmsg(
"cannot change persistence setting twice")));
5008 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5009 errmsg(
"cannot have multiple SET ACCESS METHOD subcommands")));
5120 elog(
ERROR,
"unrecognized alter table type: %d",
5154 foreach(ltab, *wqueue)
5170 foreach(lcmd, subcmds)
5192 foreach(ltab, *wqueue)
5201 if (((tab->
relkind == RELKIND_RELATION ||
5202 tab->
relkind == RELKIND_PARTITIONED_TABLE) &&
5204 tab->
relkind == RELKIND_MATVIEW)
5309 cmd->
recurse,
false, lockmode);
5314 true,
true, lockmode);
5374 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
5385 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
5386 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
5495 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
5507 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5519 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5527 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5532 elog(
ERROR,
"unrecognized alter table type: %d",
5592 foreach(lc, beforeStmts)
5601 foreach(lc, atstmt->
cmds)
5661 if (pass < cur_pass)
5664 elog(
ERROR,
"ALTER TABLE scheduling failure: too late for pass %d",
5667 else if (pass > cur_pass)
5684 elog(
ERROR,
"ALTER TABLE scheduling failure: bogus item for pass %d",
5705 foreach(ltab, *wqueue)
5710 if (!RELKIND_HAS_STORAGE(tab->
relkind))
5751 Oid NewAccessMethod;
5764 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5765 errmsg(
"cannot rewrite system relation \"%s\"",
5770 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5771 errmsg(
"cannot rewrite table \"%s\" used as a catalog table",
5782 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5783 errmsg(
"cannot rewrite temporary tables of other sessions")));
5792 NewTableSpace = OldHeap->
rd_rel->reltablespace;
5801 NewAccessMethod = OldHeap->
rd_rel->relam;
5844 persistence, lockmode);
5903 foreach(lc, seqlist)
5919 foreach(ltab, *wqueue)
5926 if (!RELKIND_HAS_STORAGE(tab->
relkind))
5964 foreach(ltab, *wqueue)
5991 bool needscan =
false;
5992 List *notnull_attrs;
6053 elog(
ERROR,
"unrecognized constraint type: %d",
6073 notnull_attrs =
NIL;
6082 for (
i = 0;
i < newTupDesc->
natts;
i++)
6086 if (attr->attnotnull && !attr->attisdropped)
6093 if (newrel || needscan)
6163 for (
i = 0;
i < newTupDesc->
natts;
i++)
6199 foreach(lc, dropped_attrs)
6253 insertslot = newslot;
6262 insertslot = oldslot;
6268 foreach(l, notnull_attrs)
6277 (
errcode(ERRCODE_NOT_NULL_VIOLATION),
6278 errmsg(
"column \"%s\" of relation \"%s\" contains null values",
6294 (
errcode(ERRCODE_CHECK_VIOLATION),
6295 errmsg(
"check constraint \"%s\" of relation \"%s\" is violated by some row",
6304 elog(
ERROR,
"unrecognized constraint type: %d",
6309 if (partqualstate && !
ExecCheck(partqualstate, econtext))
6313 (
errcode(ERRCODE_CHECK_VIOLATION),
6314 errmsg(
"updated partition constraint for default partition \"%s\" would be violated by some row",
6319 (
errcode(ERRCODE_CHECK_VIOLATION),
6320 errmsg(
"partition constraint of relation \"%s\" is violated by some row",
6328 ti_options, bistate);
6367 foreach(ltab, *wqueue)
6370 if (tab->
relid == relid)
6389 *wqueue =
lappend(*wqueue, tab);
6401 return "ADD COLUMN";
6404 return "ALTER COLUMN ... SET DEFAULT";
6406 return "ALTER COLUMN ... DROP NOT NULL";
6408 return "ALTER COLUMN ... SET NOT NULL";
6410 return "ALTER COLUMN ... SET EXPRESSION";
6412 return "ALTER COLUMN ... DROP EXPRESSION";
6416 return "ALTER COLUMN ... SET STATISTICS";
6418 return "ALTER COLUMN ... SET";
6420 return "ALTER COLUMN ... RESET";
6422 return "ALTER COLUMN ... SET STORAGE";
6424 return "ALTER COLUMN ... SET COMPRESSION";
6426 return "DROP COLUMN";
6434 return "ADD CONSTRAINT";
6436 return "ALTER CONSTRAINT";
6438 return "VALIDATE CONSTRAINT";
6440 return "DROP CONSTRAINT";
6444 return "ALTER COLUMN ... SET DATA TYPE";
6446 return "ALTER COLUMN ... OPTIONS";
6450 return "CLUSTER ON";
6452 return "SET WITHOUT CLUSTER";
6454 return "SET ACCESS METHOD";
6456 return "SET LOGGED";
6458 return "SET UNLOGGED";
6460 return "SET WITHOUT OIDS";
6462 return "SET TABLESPACE";
6470 return "ENABLE TRIGGER";
6472 return "ENABLE ALWAYS TRIGGER";
6474 return "ENABLE REPLICA TRIGGER";
6476 return "DISABLE TRIGGER";
6478 return "ENABLE TRIGGER ALL";
6480 return "DISABLE TRIGGER ALL";
6482 return "ENABLE TRIGGER USER";
6484 return "DISABLE TRIGGER USER";
6486 return "ENABLE RULE";
6488 return "ENABLE ALWAYS RULE";
6490 return "ENABLE REPLICA RULE";
6492 return "DISABLE RULE";
6496 return "NO INHERIT";
6502 return "REPLICA IDENTITY";
6504 return "ENABLE ROW SECURITY";
6506 return "DISABLE ROW SECURITY";
6508 return "FORCE ROW SECURITY";
6510 return "NO FORCE ROW SECURITY";
6514 return "ATTACH PARTITION";
6516 return "DETACH PARTITION";
6518 return "DETACH PARTITION ... FINALIZE";
6520 return "SPLIT PARTITION";
6522 return "MERGE PARTITIONS";
6524 return "ALTER COLUMN ... ADD IDENTITY";
6526 return "ALTER COLUMN ... SET";
6528 return "ALTER COLUMN ... DROP IDENTITY";
6548 switch (rel->
rd_rel->relkind)
6550 case RELKIND_RELATION:
6551 case RELKIND_PARTITIONED_TABLE:
6557 case RELKIND_MATVIEW:
6563 case RELKIND_PARTITIONED_INDEX:
6566 case RELKIND_COMPOSITE_TYPE:
6569 case RELKIND_FOREIGN_TABLE:
6572 case RELKIND_SEQUENCE:
6581 if ((actual_target & allowed_targets) == 0)
6587 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6589 errmsg(
"ALTER action %s cannot be performed on relation \"%s\"",
6594 elog(
ERROR,
"invalid ALTER action attempted on relation \"%s\"",
6605 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6606 errmsg(
"permission denied: \"%s\" is a system catalog",
6627 if (recurse && rel->
rd_rel->relhassubclass)
6640 foreach(child, children)
6645 if (childrelid == relid)
6666 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
6700 Assert(rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
6706 foreach(child, children)
6740 const char *origTypeName)
6757 Anum_pg_depend_refclassid,
6761 Anum_pg_depend_refobjid,
6776 if (pg_depend->classid == TypeRelationId)
6785 origRelation, origTypeName);
6790 if (pg_depend->classid != RelationRelationId)
6809 if (pg_depend->objsubid > 0 && pg_depend->objsubid <= tupleDesc->
natts)
6814 for (
int attno = 1; attno <= tupleDesc->
natts; attno++)
6817 if (att->atttypid == typeOid && !att->attisdropped)
6838 if (RELKIND_HAS_STORAGE(rel->
rd_rel->relkind) ||
6839 RELKIND_HAS_PARTITIONS(rel->
rd_rel->relkind))
6843 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6844 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
6848 else if (origRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
6850 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6851 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
6855 else if (origRelation->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
6857 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6858 errmsg(
"cannot alter foreign table \"%s\" because column \"%s.%s\" uses its row type",
6864 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6865 errmsg(
"cannot alter table \"%s\" because column \"%s.%s\" uses its row type",
6877 origRelation, origTypeName);
6908 Anum_pg_class_reloftype,
6920 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
6921 errmsg(
"cannot alter type \"%s\" because it is the type of a typed table",
6923 errhint(
"Use ALTER ... CASCADE to alter the typed tables too.")));
6949 bool typeOk =
false;
6951 if (typ->typtype == TYPTYPE_COMPOSITE)
6957 typeOk = (typeRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
6968 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6969 errmsg(
"type %s is the row type of another table",
6971 errdetail(
"A typed table must use a stand-alone composite type created with CREATE TYPE.")));
6975 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6976 errmsg(
"type %s is not a composite type",
7000 if (rel->
rd_rel->reloftype && !recursing)
7002 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7003 errmsg(
"cannot add column to typed table")));
7005 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
7008 if (recurse && !is_view)
7027 bool if_not_exists = (*cmd)->missing_ok;
7048 if (rel->
rd_rel->relispartition && !recursing)
7050 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7051 errmsg(
"cannot add column to a partition")));
7076 if (ctypeId != childatt->atttypid ||
7077 ctypmod != childatt->atttypmod)
7079 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7080 errmsg(
"child table \"%s\" has different type for column \"%s\"",
7083 if (ccollid != childatt->attcollation)
7085 (
errcode(ERRCODE_COLLATION_MISMATCH),
7086 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
7093 childatt->attinhcount++;
7094 if (childatt->attinhcount < 0)
7096 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
7097 errmsg(
"too many inheritance parents"));
7104 (
errmsg(
"merging definition of column \"%s\" for child \"%s\"",
7134 if (
context != NULL && !recursing)
7153 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE &&
7156 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7157 errmsg(
"cannot recursively add identity column to table that has child tables")));
7163 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
7170 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
7171 errmsg(
"tables can have at most %d columns",
7182 attribute->attnum = newattnum;
7218 rawEnt->
attnum = attribute->attnum;
7235 false,
true,
false, NULL);
7281 if (RELKIND_HAS_STORAGE(relkind))
7292 nve->
typeId = attribute->atttypid;
7294 defval = (
Expr *) nve;
7308 baseTypeMod = attribute->atttypmod;
7315 attribute->atttypid,
7316 attribute->atttypmod,
7321 elog(
ERROR,
"failed to coerce base type to domain");
7329 newval->attnum = attribute->attnum;
7367 if (children && !recurse)
7369 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7370 errmsg(
"column must be added to child tables too")));
7383 foreach(child, children)
7398 &childcmd, recurse,
true,
7439 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7440 errmsg(
"column name \"%s\" conflicts with a system column name",
7447 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7448 errmsg(
"column \"%s\" of relation \"%s\" already exists, skipping",
7454 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7455 errmsg(
"column \"%s\" of relation \"%s\" already exists",
7471 myself.
classId = RelationRelationId;
7474 referenced.
classId = TypeRelationId;
7492 myself.
classId = RelationRelationId;
7495 referenced.
classId = CollationRelationId;
7513 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
7517 Assert(partdesc != NULL);
7518 if (partdesc->
nparts > 0 && !recurse && !recursing)
7520 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7521 errmsg(
"cannot remove constraint from only the partitioned table when partitions exist"),
7522 errhint(
"Do not specify the ONLY keyword.")));
7548 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7549 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7557 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7558 errmsg(
"cannot alter system column \"%s\"",
7561 if (attTup->attidentity)
7563 (
errcode(ERRCODE_SYNTAX_ERROR),
7564 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
7584 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
7591 if (indexStruct->indisprimary || indexStruct->indisreplident)
7598 for (
int i = 0;
i < indexStruct->indnkeyatts;
i++)
7600 if (indexStruct->indkey.values[
i] ==
attnum)
7602 if (indexStruct->indisprimary)
7604 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7605 errmsg(
"column \"%s\" is in a primary key",
7609 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7610 errmsg(
"column \"%s\" is in index used as replica identity",
7622 if (rel->
rd_rel->relispartition)
7629 parent_attnum =
get_attnum(parentId, colName);
7632 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7633 errmsg(
"column \"%s\" is marked NOT NULL in parent table",
7641 if (attTup->attnotnull)
7643 attTup->attnotnull =
false;
7691 if (rel->
rd_rel->relhassubclass &&
7692 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
7702 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7703 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7717 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
7736 const char *colName,
LOCKMODE lockmode)
7752 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7753 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7761 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7762 errmsg(
"cannot alter system column \"%s\"",
7818 const char *colName,
LOCKMODE lockmode)
7826 errcode(ERRCODE_UNDEFINED_COLUMN),
7827 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7832 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7833 errmsg(
"constraint must be added to child tables too"),
7834 errdetail(
"Column \"%s\" of relation \"%s\" is not already NOT NULL.",
7836 errhint(
"Do not specify the ONLY keyword.")));
7863 nnulltest->argisrow =
false;
7869 (
errmsg_internal(
"existing constraints on column \"%s.%s\" are sufficient to prove that it does not contain nulls",
7896 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7897 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7903 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7904 errmsg(
"cannot alter system column \"%s\"",
7909 (
errcode(ERRCODE_SYNTAX_ERROR),
7910 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
7913 newDefault ? 0 :
errhint(
"Use %s instead.",
7914 "ALTER TABLE ... ALTER COLUMN ... DROP IDENTITY")));
7918 (
errcode(ERRCODE_SYNTAX_ERROR),
7919 errmsg(
"column \"%s\" of relation \"%s\" is a generated column",
7923 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... SET EXPRESSION") :
7925 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... DROP EXPRESSION") : 0)));
7937 newDefault != NULL);
7955 false,
true,
false, NULL);
7999 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing)
8009 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8010 if (ispartitioned && !recurse)
8012 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8013 errmsg(
"cannot add identity to a column of only the partitioned table"),
8014 errhint(
"Do not specify the ONLY keyword.")));
8016 if (rel->
rd_rel->relispartition && !recursing)
8018 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8019 errmsg(
"cannot add identity to a column of a partition"));
8026 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8027 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8035 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8036 errmsg(
"cannot alter system column \"%s\"",
8044 if (!attTup->attnotnull)
8046 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8047 errmsg(
"column \"%s\" of relation \"%s\" must be declared NOT NULL before identity can be added",
8050 if (attTup->attidentity)
8052 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8053 errmsg(
"column \"%s\" of relation \"%s\" is already an identity column",
8056 if (attTup->atthasdef)
8058 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8059 errmsg(
"column \"%s\" of relation \"%s\" already has a default value",
8062 attTup->attidentity = cdef->
identity;
8078 if (recurse && ispartitioned)
8085 foreach(lc, children)
8105 LOCKMODE lockmode,
bool recurse,
bool recursing)
8116 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8117 if (ispartitioned && !recurse)
8119 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8120 errmsg(
"cannot change identity column of only the partitioned table"),
8121 errhint(
"Do not specify the ONLY keyword.")));
8123 if (rel->
rd_rel->relispartition && !recursing)
8125 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8126 errmsg(
"cannot change identity column of a partition"));
8132 if (strcmp(defel->
defname,
"generated") == 0)
8136 (
errcode(ERRCODE_SYNTAX_ERROR),
8137 errmsg(
"conflicting or redundant options")));
8138 generatedEl = defel;
8141 elog(
ERROR,
"option \"%s\" not recognized",
8155 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8156 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8164 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8165 errmsg(
"cannot alter system column \"%s\"",
8168 if (!attTup->attidentity)
8170 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8171 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8195 if (generatedEl && recurse && ispartitioned)
8202 foreach(lc, children)
8222 bool recurse,
bool recursing)
8233 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8234 if (ispartitioned && !recurse)
8236 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8237 errmsg(
"cannot drop identity from a column of only the partitioned table"),
8238 errhint(
"Do not specify the ONLY keyword.")));
8240 if (rel->
rd_rel->relispartition && !recursing)
8242 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8243 errmsg(
"cannot drop identity from a column of a partition"));
8249 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8250 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8258 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8259 errmsg(
"cannot alter system column \"%s\"",
8262 if (!attTup->attidentity)
8266 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8267 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8272 (
errmsg(
"column \"%s\" of relation \"%s\" is not an identity column, skipping",
8280 attTup->attidentity =
'\0';
8296 if (recurse && ispartitioned)
8303 foreach(lc, children)
8320 seqaddress.
classId = RelationRelationId;
8350 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8351 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8359 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8360 errmsg(
"cannot alter system column \"%s\"",
8363 if (attTup->attgenerated != ATTRIBUTE_GENERATED_STORED)
8365 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8366 errmsg(
"column \"%s\" of relation \"%s\" is not a generated column",
8393 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8413 rawEnt->
generated = ATTRIBUTE_GENERATED_STORED;
8417 false,
true,
false, NULL);
8428 newval->is_generated =
true;
8463 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8464 errmsg(
"ALTER TABLE / DROP EXPRESSION must be applied to child tables too")));
8477 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8478 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8483 if (attTup->attinhcount > 0)
8485 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8486 errmsg(
"cannot drop generation expression from inherited column")));
8507 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8508 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8516 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8517 errmsg(
"cannot alter system column \"%s\"",
8520 if (attTup->attgenerated != ATTRIBUTE_GENERATED_STORED)
8524 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8525 errmsg(
"column \"%s\" of relation \"%s\" is not a stored generated column",
8530 (
errmsg(
"column \"%s\" of relation \"%s\" is not a stored generated column, skipping",
8542 attTup->attgenerated =
'\0';
8559 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8588 bool newtarget_default;
8595 Datum repl_val[Natts_pg_attribute];
8596 bool repl_null[Natts_pg_attribute];
8597 bool repl_repl[Natts_pg_attribute];
8603 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
8604 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
8607 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8608 errmsg(
"cannot refer to non-index column by number")));
8611 if (newValue &&
intVal(newValue) != -1)
8613 newtarget =
intVal(newValue);
8614 newtarget_default =
false;
8617 newtarget_default =
true;
8619 if (!newtarget_default)
8627 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8628 errmsg(
"statistics target %d is too low",
8635 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8636 errmsg(
"lowering statistics target to %d",
8649 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8650 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8659 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8660 errmsg(
"column number %d of relation \"%s\" does not exist",
8666 attnum = attrtuple->attnum;
8669 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8670 errmsg(
"cannot alter system column \"%s\"",
8673 if (rel->
rd_rel->relkind == RELKIND_INDEX ||
8674 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
8678 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8679 errmsg(
"cannot alter statistics on included column \"%s\" of index \"%s\"",
8683 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8684 errmsg(
"cannot alter statistics on non-expression column \"%s\" of index \"%s\"",
8686 errhint(
"Alter statistics on table column instead.")));
8690 memset(repl_null,
false,
sizeof(repl_null));
8691 memset(repl_repl,
false,
sizeof(repl_repl));
8692 if (!newtarget_default)
8693 repl_val[Anum_pg_attribute_attstattarget - 1] = newtarget;
8695 repl_null[Anum_pg_attribute_attstattarget - 1] =
true;
8696 repl_repl[Anum_pg_attribute_attstattarget - 1] =
true;
8698 repl_val, repl_null, repl_repl);
8732 Datum repl_val[Natts_pg_attribute];
8733 bool repl_null[Natts_pg_attribute];
8734 bool repl_repl[Natts_pg_attribute];
8742 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8743 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8747 attnum = attrtuple->attnum;
8750 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8751 errmsg(
"cannot alter system column \"%s\"",
8764 memset(repl_null,
false,
sizeof(repl_null));
8765 memset(repl_repl,
false,
sizeof(repl_repl));
8766 if (newOptions != (
Datum) 0)
8767 repl_val[Anum_pg_attribute_attoptions - 1] = newOptions;
8769 repl_null[Anum_pg_attribute_attoptions - 1] =
true;
8770 repl_repl[Anum_pg_attribute_attoptions - 1] =
true;
8772 repl_val, repl_null, repl_repl);
8801 bool setstorage,
char newstorage,
8802 bool setcompression,
char newcompression,
8816 for (
int i = 0;
i < indrel->
rd_index->indnatts;
i++)
8838 attrtuple->attstorage = newstorage;
8841 attrtuple->attcompression = newcompression;
8876 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8877 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8881 attnum = attrtuple->attnum;
8884 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8885 errmsg(
"cannot alter system column \"%s\"",
8901 true, attrtuple->attstorage,
8929 if (rel->
rd_rel->reloftype && !recursing)
8931 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
8932 errmsg(
"cannot drop column from typed table")));
8934 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
8955 bool recurse,
bool recursing,
8956 bool missing_ok,
LOCKMODE lockmode,
8971 Assert(!recursing || addrs != NULL);
8988 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8989 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8995 (
errmsg(
"column \"%s\" of relation \"%s\" does not exist, skipping",
9002 attnum = targetatt->attnum;
9007 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9008 errmsg(
"cannot drop system column \"%s\"",
9015 if (targetatt->attinhcount > 0 && !recursing)
9017 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9018 errmsg(
"cannot drop inherited column \"%s\"",
9030 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9031 errmsg(
"cannot drop column \"%s\" because it is part of the partition key of relation \"%s\"",
9053 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !recurse)
9055 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9056 errmsg(
"cannot drop column from only the partitioned table when partitions exist"),
9057 errhint(
"Do not specify the ONLY keyword.")));
9060 foreach(child, children)
9072 elog(
ERROR,
"cache lookup failed for attribute \"%s\" of relation %u",
9073 colName, childrelid);
9076 if (childatt->attinhcount <= 0)
9077 elog(
ERROR,
"relation %u has non-inherited attribute \"%s\"",
9078 childrelid, colName);
9087 if (childatt->attinhcount == 1 && !childatt->attislocal)
9091 behavior,
true,
true,
9092 false, lockmode, addrs);
9097 childatt->attinhcount--;
9112 childatt->attinhcount--;
9113 childatt->attislocal =
true;
9129 object.classId = RelationRelationId;
9131 object.objectSubId =
attnum;
9169 check_rights = !is_rebuild;
9241 Oid index_oid =
stmt->indexOid;
9245 char *constraintName;
9246 char constraintType;
9258 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
9260 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9261 errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables")));
9271 elog(
ERROR,
"index \"%s\" is not unique", indexName);
9280 constraintName =
stmt->idxname;
9281 if (constraintName == NULL)
9282 constraintName = indexName;
9283 else if (strcmp(constraintName, indexName) != 0)
9286 (
errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index \"%s\" to \"%s\"",
9287 indexName, constraintName)));
9297 constraintType = CONSTRAINT_PRIMARY;
9299 constraintType = CONSTRAINT_UNIQUE;
9331 Constraint *newConstraint,
bool recurse,
bool is_readd,
9343 switch (newConstraint->
contype)
9348 newConstraint, recurse,
false, is_readd,
9364 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
9383 elog(
ERROR,
"unrecognized constraint type: %d",
9384 (
int) newConstraint->
contype);
9410 foreach(lc, colnames)
9415 buf[buflen++] =
'_';
9422 buflen += strlen(
buf + buflen);
9446 Constraint *constr,
bool recurse,
bool recursing,
9471 recursing || is_readd,
9481 foreach(lcon, newcons)
9538 if (!recurse && children !=
NIL)
9540 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9541 errmsg(
"constraint must be added to child tables too")));
9543 foreach(child, children)
9558 constr, recurse,
true, is_readd, lockmode);
9584 bool recurse,
bool recursing,
LOCKMODE lockmode)
9618 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
9622 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9623 errmsg(
"cannot use ONLY for foreign key on partitioned table \"%s\" referencing relation \"%s\"",
9628 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9629 errmsg(
"cannot add NOT VALID foreign key on partitioned table \"%s\" referencing relation \"%s\"",
9632 errdetail(
"This feature is not yet supported on partitioned tables.")));
9635 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
9636 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
9638 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9639 errmsg(
"referenced relation \"%s\" is not a table",
9644 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9645 errmsg(
"permission denied: \"%s\" is a system catalog",
9656 switch (rel->
rd_rel->relpersistence)
9658 case RELPERSISTENCE_PERMANENT:
9661 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9662 errmsg(
"constraints on permanent tables may reference only permanent tables")));
9664 case RELPERSISTENCE_UNLOGGED:
9666 && pkrel->
rd_rel->relpersistence != RELPERSISTENCE_UNLOGGED)
9668 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9669 errmsg(
"constraints on unlogged tables may reference only permanent or unlogged tables")));
9671 case RELPERSISTENCE_TEMP:
9672 if (pkrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
9674 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9675 errmsg(
"constraints on temporary tables may reference only temporary tables")));
9678 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9679 errmsg(
"constraints on temporary tables must involve temporary tables of this session")));
9689 fkattnum, fktypoid);
9693 fkdelsetcols, NULL);
9695 numfkdelsetcols, fkdelsetcols,
9715 pkattnum, pktypoid);
9729 for (
i = 0;
i < numfks;
i++)
9742 (
errcode(ERRCODE_SYNTAX_ERROR),
9743 errmsg(
"invalid %s action for foreign key constraint containing generated column",
9748 (
errcode(ERRCODE_SYNTAX_ERROR),
9749 errmsg(
"invalid %s action for foreign key constraint containing generated column",
9762 if (numfks != numpks)
9764 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
9765 errmsg(
"number of referencing and referenced columns for foreign key disagree")));
9774 for (
i = 0;
i < numpks;
i++)
9776 Oid pktype = pktypoid[
i];
9777 Oid fktype = fktypoid[
i];
9793 elog(
ERROR,
"cache lookup failed for opclass %u", opclasses[
i]);
9795 amid = cla_tup->opcmethod;
9796 opfamily = cla_tup->opcfamily;
9797 opcintype = cla_tup->opcintype;
9807 if (amid != BTREE_AM_OID)
9808 elog(
ERROR,
"only b-tree indexes are supported for foreign keys");
9819 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
9820 eqstrategy, opcintype, opcintype, opfamily);
9832 pfeqop_right = fktyped;
9854 Oid input_typeids[2];
9855 Oid target_typeids[2];
9857 input_typeids[0] = pktype;
9858 input_typeids[1] = fktype;
9859 target_typeids[0] = opcintype;
9860 target_typeids[1] = opcintype;
9864 pfeqop = ffeqop = ppeqop;
9865 pfeqop_right = opcintype;
9871 (
errcode(ERRCODE_DATATYPE_MISMATCH),
9872 errmsg(
"foreign key constraint \"%s\" cannot be implemented",
9874 errdetail(
"Key columns \"%s\" and \"%s\" "
9875 "are of incompatible types: %s and %s.",
9889 old_check_ok = (pfeqop ==
lfirst_oid(old_pfeqop_item));
9909 old_fktype = attr->atttypid;
9910 new_fktype = fktype;
9948 old_check_ok = (new_pathtype == old_pathtype &&
9949 new_castfunc == old_castfunc &&
9950 (!IsPolymorphicType(pfeqop_right) ||
9951 new_fktype == old_fktype));
9954 pfeqoperators[
i] = pfeqop;
9955 ppeqoperators[
i] = ppeqop;
9956 ffeqoperators[
i] = ffeqop;
10008 int numfksetcols,
const int16 *fksetcolsattnums,
10011 for (
int i = 0;
i < numfksetcols;
i++)
10013 int16 setcol_attnum = fksetcolsattnums[
i];
10016 for (
int j = 0;
j < numfks;
j++)
10018 if (fkattnums[
j] == setcol_attnum)
10030 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
10031 errmsg(
"column \"%s\" referenced in ON DELETE SET action must be part of foreign key", col)));
10073 Oid *ppeqoperators,
Oid *ffeqoperators,
10074 int numfkdelsetcols,
int16 *fkdelsetcols,
10076 Oid parentDelTrigger,
Oid parentUpdTrigger)
10084 Oid deleteTriggerOid,
10091 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
10092 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
10094 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10095 errmsg(
"referenced relation \"%s\" is not a table",
10110 conname = fkconstraint->
conname;
10114 conislocal =
false;
10116 connoinherit =
false;
10126 connoinherit = rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE;
10134 CONSTRAINT_FOREIGN,
10188 constrOid, indexOid,
10189 parentDelTrigger, parentUpdTrigger,
10190 &deleteTriggerOid, &updateTriggerOid);
10197 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10220 for (
int j = 0;
j < numfks;
j++)
10221 mapped_pkattnum[
j] = map->
attnums[pkattnum[
j] - 1];
10224 mapped_pkattnum = pkattnum;
10229 elog(
ERROR,
"index for %u not found in partition %s",
10232 partIndexId, constrOid, numfks,
10233 mapped_pkattnum, fkattnum,
10234 pfeqoperators, ppeqoperators, ffeqoperators,
10235 numfkdelsetcols, fkdelsetcols,
10237 deleteTriggerOid, updateTriggerOid);
10243 pfree(mapped_pkattnum);
10291 int numfks,
int16 *pkattnum,
int16 *fkattnum,
10292 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
10293 int numfkdelsetcols,
int16 *fkdelsetcols,
10294 bool old_check_ok,
LOCKMODE lockmode,
10295 Oid parentInsTrigger,
Oid parentUpdTrigger)
10297 Oid insertTriggerOid,
10302 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
10304 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10305 errmsg(
"foreign key constraints are not supported on foreign tables")));
10318 parentInsTrigger, parentUpdTrigger,
10319 &insertTriggerOid, &updateTriggerOid);
10321 if (rel->
rd_rel->relkind == RELKIND_RELATION)
10342 newcon->
conid = parentConstr;
10343 newcon->
qual = (
Node *) fkconstraint;
10348 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10385 for (
int j = 0;
j < numfks;
j++)
10386 mapped_fkattnum[
j] = attmap->
attnums[fkattnum[
j] - 1];
10391 foreach(cell, partFKs)
10428 conname = fkconstraint->
conname;
10432 CONSTRAINT_FOREIGN,
10517 Assert(parentRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
10594 foreach(cell, clone)
10608 int numfkdelsetcols;
10611 Oid deleteTriggerOid,
10616 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
10648 indexOid = constrForm->conindid;
10659 for (
int i = 0;
i < numfks;
i++)
10660 mapped_confkey[
i] = attmap->
attnums[confkey[
i] - 1];
10663 fkconstraint->
contype = CONSTRAINT_FOREIGN;
10665 fkconstraint->
deferrable = constrForm->condeferrable;
10668 fkconstraint->
pktable = NULL;
10671 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
10681 for (
int i = 0;
i < numfks;
i++)
10698 elog(
ERROR,
"index for %u not found in partition %s",
10707 constrForm->confrelid, constrForm->conrelid,
10708 &deleteTriggerOid, &updateTriggerOid);
10772 if (partRel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
10774 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10775 errmsg(
"foreign key constraints are not supported on foreign tables")));
10795 foreach(cell, clone)
10808 int numfkdelsetcols;
10817 Oid insertTriggerOid,
10822 elog(
ERROR,
"cache lookup failed for constraint %u",
10838 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10843 conpfeqop, conppeqop, conffeqop,
10844 &numfkdelsetcols, confdelsetcols);
10845 for (
int i = 0;
i < numfks;
i++)
10846 mapped_conkey[
i] = attmap->
attnums[conkey[
i] - 1];
10858 constrForm->confrelid, constrForm->conrelid,
10859 &insertTriggerOid, &updateTriggerOid);
10869 foreach(lc, partFKs)
10897 fkconstraint->
contype = CONSTRAINT_FOREIGN;
10899 fkconstraint->
deferrable = constrForm->condeferrable;
10902 fkconstraint->
pktable = NULL;
10905 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
10913 for (
int i = 0;
i < numfks;
i++)
10918 mapped_conkey[
i] - 1);
10924 NameStr(constrForm->conname)))
10933 indexOid = constrForm->conindid;
10936 constrForm->connamespace,
10937 CONSTRAINT_FOREIGN,
10940 constrForm->convalidated,
10948 constrForm->confrelid,
11019 Oid parentConstrOid,
11024 Oid parentInsTrigger,
11025 Oid parentUpdTrigger,
11035 Oid insertTriggerOid,
11041 elog(
ERROR,
"cache lookup failed for constraint %u", parentConstrOid);
11048 if (fk->
confrelid != parentConstr->confrelid || fk->
nkeys != numfks)
11053 for (
int i = 0;
i < numfks;
i++)
11055 if (fk->conkey[
i] != mapped_conkey[
i] ||
11056 fk->confkey[
i] != confkey[
i] ||
11057 fk->conpfeqop[
i] != conpfeqop[
i])
11075 !partConstr->convalidated ||
11076 partConstr->condeferrable != parentConstr->condeferrable ||
11077 partConstr->condeferred != parentConstr->condeferred ||
11078 partConstr->confupdtype != parentConstr->confupdtype ||
11079 partConstr->confdeltype != parentConstr->confdeltype ||
11080 partConstr->confmatchtype != parentConstr->confmatchtype)
11098 Anum_pg_trigger_tgconstraint,
11108 if (trgform->tgconstrrelid != fk->
conrelid)
11142 &insertTriggerOid, &updateTriggerOid);
11161 Oid conoid,
Oid confrelid,
Oid conrelid,
11162 Oid *deleteTriggerOid,
11163 Oid *updateTriggerOid)
11169 *deleteTriggerOid = *updateTriggerOid =
InvalidOid;
11171 Anum_pg_trigger_tgconstraint,
11181 if (trgform->tgconstrrelid != conrelid)
11183 if (trgform->tgrelid != confrelid)
11188 if (TRIGGER_FOR_DELETE(trgform->tgtype))
11191 *deleteTriggerOid = trgform->oid;
11193 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
11196 *updateTriggerOid = trgform->oid;
11198 #ifndef USE_ASSERT_CHECKING
11206 elog(
ERROR,
"could not find ON DELETE action trigger of foreign key constraint %u",
11209 elog(
ERROR,
"could not find ON UPDATE action trigger of foreign key constraint %u",
11222 Oid conoid,
Oid confrelid,
Oid conrelid,
11223 Oid *insertTriggerOid,
11224 Oid *updateTriggerOid)
11230 *insertTriggerOid = *updateTriggerOid =
InvalidOid;
11232 Anum_pg_trigger_tgconstraint,
11242 if (trgform->tgconstrrelid != confrelid)
11244 if (trgform->tgrelid != conrelid)
11249 if (TRIGGER_FOR_INSERT(trgform->tgtype))
11252 *insertTriggerOid = trgform->oid;
11254 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
11257 *updateTriggerOid = trgform->oid;
11259 #ifndef USE_ASSERT_CHECKING
11267 elog(
ERROR,
"could not find ON INSERT check triggers of foreign key constraint %u",
11270 elog(
ERROR,
"could not find ON UPDATE check triggers of foreign key constraint %u",
11288 bool recursing,
LOCKMODE lockmode)
11310 Anum_pg_constraint_conrelid,
11314 Anum_pg_constraint_contypid,
11318 Anum_pg_constraint_conname,
11322 true, NULL, 3, skey);
11327 (
errcode(ERRCODE_UNDEFINED_OBJECT),
11328 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
11332 if (currcon->contype != CONSTRAINT_FOREIGN)
11334 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11335 errmsg(
"constraint \"%s\" of relation \"%s\" is not a foreign key constraint",
11350 Oid parent = currcon->conparentid;
11351 char *ancestorname = NULL;
11352 char *ancestortable = NULL;
11368 parent = contup->conparentid;
11373 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
11374 errmsg(
"cannot alter constraint \"%s\" on relation \"%s\"",
11376 ancestorname && ancestortable ?
11377 errdetail(
"Constraint \"%s\" is derived from constraint \"%s\" of relation \"%s\".",
11378 cmdcon->
conname, ancestorname, ancestortable) : 0,
11379 errhint(
"You may alter the constraint it derives from instead.")));
11388 if (currcon->condeferrable != cmdcon->
deferrable ||
11390 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11393 &otherrelids, lockmode))
11402 foreach(lc, otherrelids)
11432 bool changed =
false;
11438 conoid = currcon->oid;
11439 refrelid = currcon->confrelid;
11447 if (currcon->condeferrable != cmdcon->
deferrable ||
11458 copy_con->condeferrable = cmdcon->
deferrable;
11476 Anum_pg_trigger_tgconstraint,
11503 if (tgform->tgfoid != F_RI_FKEY_NOACTION_DEL &&
11504 tgform->tgfoid != F_RI_FKEY_NOACTION_UPD &&
11505 tgform->tgfoid != F_RI_FKEY_CHECK_INS &&
11506 tgform->tgfoid != F_RI_FKEY_CHECK_UPD)
11532 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
11540 Anum_pg_constraint_conparentid,
11545 true, NULL, 1, &pkey);
11552 childrel =
table_open(childcon->conrelid, lockmode);
11554 otherrelids, lockmode);
11577 bool recurse,
bool recursing,
LOCKMODE lockmode)
11592 Anum_pg_constraint_conrelid,
11596 Anum_pg_constraint_contypid,
11600 Anum_pg_constraint_conname,
11604 true, NULL, 3, skey);
11609 (
errcode(ERRCODE_UNDEFINED_OBJECT),
11610 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
11614 if (con->contype != CONSTRAINT_FOREIGN &&
11615 con->contype != CONSTRAINT_CHECK)
11617 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11618 errmsg(
"constraint \"%s\" of relation \"%s\" is not a foreign key or check constraint",
11621 if (!con->convalidated)
11627 if (con->contype == CONSTRAINT_FOREIGN)
11635 fkconstraint->
conname = constrName;
11638 newcon->
name = constrName;
11640 newcon->
refrelid = con->confrelid;
11642 newcon->
conid = con->oid;
11643 newcon->
qual = (
Node *) fkconstraint;
11654 else if (con->contype == CONSTRAINT_CHECK)
11667 if (!recursing && !con->connoinherit)
11679 foreach(child, children)
11694 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
11695 errmsg(
"constraint must be validated on child tables too")));
11707 newcon->
name = constrName;
11711 newcon->
conid = con->oid;
11714 Anum_pg_constraint_conbin);
11734 copy_con->convalidated =
true;
11772 foreach(l, colList)
11781 (
errcode(ERRCODE_UNDEFINED_COLUMN),
11782 errmsg(
"column \"%s\" referenced in foreign key constraint does not exist",
11785 if (attform->attnum < 0)
11787 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11788 errmsg(
"system columns cannot be used in foreign keys")));
11791 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
11792 errmsg(
"cannot have more than %d keys in a foreign key",
11794 attnums[
attnum] = attform->attnum;
11795 if (atttypids != NULL)
11796 atttypids[
attnum] = attform->atttypid;
11818 List **attnamelist,
11822 List *indexoidlist;
11826 Datum indclassDatum;
11839 foreach(indexoidscan, indexoidlist)
11845 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
11847 if (indexStruct->indisprimary && indexStruct->indisvalid)
11854 if (!indexStruct->indimmediate)
11856 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
11857 errmsg(
"cannot use a deferrable primary key for referenced table \"%s\"",
11860 *indexOid = indexoid;
11873 (
errcode(ERRCODE_UNDEFINED_OBJECT),
11874 errmsg(
"there is no primary key for referenced table \"%s\"",
11879 Anum_pg_index_indclass);
11886 *attnamelist =
NIL;
11887 for (
i = 0;
i < indexStruct->indnkeyatts;
i++)
11889 int pkattno = indexStruct->indkey.values[
i];
11891 attnums[
i] = pkattno;
11893 opclasses[
i] = indclass->
values[
i];
11894 *attnamelist =
lappend(*attnamelist,
11917 int numattrs,
int16 *attnums,
11921 bool found =
false;
11922 bool found_deferrable =
false;
11923 List *indexoidlist;
11935 for (
i = 0;
i < numattrs;
i++)
11937 for (
j =
i + 1;
j < numattrs;
j++)
11939 if (attnums[
i] == attnums[
j])
11941 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
11942 errmsg(
"foreign key referenced-columns list must not contain duplicates")));
11953 foreach(indexoidscan, indexoidlist)
11961 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
11969 if (indexStruct->indnkeyatts == numattrs &&
11970 indexStruct->indisunique &&
11971 indexStruct->indisvalid &&
11975 Datum indclassDatum;
11980 Anum_pg_index_indclass);
11993 for (
i = 0;
i < numattrs;
i++)
11996 for (
j = 0;
j < numattrs;
j++)
11998 if (attnums[
i] == indexStruct->indkey.values[
j])
12000 opclasses[
i] = indclass->
values[
j];
12014 if (found && !indexStruct->indimmediate)
12020 found_deferrable =
true;
12031 if (found_deferrable)
12033 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12034 errmsg(
"cannot use a deferrable unique constraint for referenced table \"%s\"",
12038 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
12039 errmsg(
"there is no unique constraint matching given keys for referenced table \"%s\"",
12059 if (targetTypeId == sourceTypeId)
12070 elog(
ERROR,
"could not find cast from %u to %u",
12071 sourceTypeId, targetTypeId);
12096 for (
i = 0;
i < natts;
i++)
12127 (
errmsg_internal(
"validating foreign key constraint \"%s\"", conname)));
12160 "validateForeignKeyConstraint",
12181 trigdata.
type = T_TriggerData;
12188 fcinfo->context = (
Node *) &trigdata;
12211 Oid constraintOid,
Oid indexOid,
Oid parentTrigOid,
12229 fk_trigger->
trigname =
"RI_ConstraintTrigger_c";
12236 fk_trigger->
events = TRIGGER_TYPE_INSERT;
12241 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
12245 fk_trigger->
row =
true;
12246 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12254 trigAddress =
CreateTrigger(fk_trigger, NULL, myRelOid, refRelOid,
12256 parentTrigOid, NULL,
true,
false);
12274 Oid constraintOid,
Oid indexOid,
12275 Oid parentDelTrigger,
Oid parentUpdTrigger,
12276 Oid *deleteTrigOid,
Oid *updateTrigOid)
12288 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
12291 fk_trigger->
row =
true;
12292 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12293 fk_trigger->
events = TRIGGER_TYPE_DELETE;
12326 elog(
ERROR,
"unrecognized FK action type: %d",
12334 parentDelTrigger, NULL,
true,
false);
12336 *deleteTrigOid = trigAddress.
objectId;
12348 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
12351 fk_trigger->
row =
true;
12352 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12353 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
12386 elog(
ERROR,
"unrecognized FK action type: %d",
12394 parentUpdTrigger, NULL,
true,
false);
12396 *updateTrigOid = trigAddress.
objectId;
12411 Oid parentInsTrigger,
Oid parentUpdTrigger,
12412 Oid *insertTrigOid,
Oid *updateTrigOid)
12415 constraintOid, indexOid,
12416 parentInsTrigger,
true);
12418 constraintOid, indexOid,
12419 parentUpdTrigger,
false);
12430 bool recurse,
bool recursing,
12431 bool missing_ok,
LOCKMODE lockmode)
12439 bool found =
false;
12440 bool is_no_inherit_constraint =
false;
12453 Anum_pg_constraint_conrelid,
12457 Anum_pg_constraint_contypid,
12461 Anum_pg_constraint_conname,
12465 true, NULL, 3, skey);
12475 if (con->coninhcount > 0 && !recursing)
12477 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12478 errmsg(
"cannot drop inherited constraint \"%s\" of relation \"%s\"",
12481 is_no_inherit_constraint = con->connoinherit;
12482 contype = con->contype;
12491 if (contype == CONSTRAINT_FOREIGN &&
12505 conobj.
classId = ConstraintRelationId;
12521 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12522 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12528 (
errmsg(
"constraint \"%s\" of relation \"%s\" does not exist, skipping",
12539 if (contype != CONSTRAINT_CHECK &&
12540 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
12551 if (!is_no_inherit_constraint)
12561 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
12562 children !=
NIL && !recurse)
12564 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12565 errmsg(
"cannot remove constraint from only the partitioned table when partitions exist"),
12566 errhint(
"Do not specify the ONLY keyword.")));
12578 Anum_pg_constraint_conrelid,
12582 Anum_pg_constraint_contypid,
12586 Anum_pg_constraint_conname,
12590 true, NULL, 3, skey);
12595 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12596 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12607 if (con->contype != CONSTRAINT_CHECK)
12608 elog(
ERROR,
"inherited constraint is not a CHECK constraint");
12610 if (con->coninhcount <= 0)
12611 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
12612 childrelid, constrName);
12620 if (con->coninhcount == 1 && !con->conislocal)
12630 con->coninhcount--;
12644 con->coninhcount--;
12645 con->conislocal =
true;
12681 bool recurse,
bool recursing,
12685 char *colName = cmd->
name;
12693 int32 targettypmod;
12700 if (rel->
rd_rel->reloftype && !recursing)
12702 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
12703 errmsg(
"cannot alter column type of typed table")));
12709 (
errcode(ERRCODE_UNDEFINED_COLUMN),
12710 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
12713 attnum = attTup->attnum;
12718 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12719 errmsg(
"cannot alter system column \"%s\"",
12727 if (attTup->attinhcount > 0 && !recursing)
12729 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12730 errmsg(
"cannot alter inherited column \"%s\"",
12738 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12739 errmsg(
"cannot alter column \"%s\" because it is part of the partition key of relation \"%s\"",
12757 if (tab->
relkind == RELKIND_RELATION ||
12758 tab->
relkind == RELKIND_PARTITIONED_TABLE)
12772 attTup->atttypid, attTup->atttypmod,
12773 attTup->attcollation,
12779 targettype, targettypmod,
12783 if (transform == NULL)
12788 (
errcode(ERRCODE_DATATYPE_MISMATCH),
12789 errmsg(
"result of USING clause for column \"%s\""
12790 " cannot be cast automatically to type %s",
12792 errhint(
"You might need to add an explicit cast.")));
12795 (
errcode(ERRCODE_DATATYPE_MISMATCH),
12796 errmsg(
"column \"%s\" cannot be cast automatically to type %s",
12799 errhint(
"You might need to specify \"USING %s::%s\".",
12818 newval->is_generated =
false;
12824 else if (transform)
12826 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
12827 errmsg(
"\"%s\" is not a table",
12830 if (!RELKIND_HAS_STORAGE(tab->
relkind))
12858 &child_numparents);
12865 forboth(lo, child_oids, li, child_numparents)
12873 if (childrelid == relid)
12890 (
errcode(ERRCODE_UNDEFINED_COLUMN),
12891 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
12895 if (childattTup->attinhcount > numparents)
12897 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12898 errmsg(
"cannot alter inherited column \"%s\" of relation \"%s\"",
12910 bool found_whole_row;
12923 if (found_whole_row)
12925 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12926 errmsg(
"cannot convert whole-row table reference"),
12927 errdetail(
"USING expression contains a whole-row table reference.")));
12934 else if (!recursing &&
12937 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12938 errmsg(
"type of inherited column \"%s\" must be changed in child tables too",
12941 if (tab->
relkind == RELKIND_COMPOSITE_TYPE)
12967 if (
IsA(expr,
Var) && ((
Var *) expr)->varattno == varattno)
12985 case F_TIMESTAMPTZ_TIMESTAMP:
12986 case F_TIMESTAMP_TIMESTAMPTZ:
13010 char *colName = cmd->
name;
13020 int32 targettypmod;
13051 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13052 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
13055 attnum = attTup->attnum;
13059 if (attTup->atttypid != attOldTup->atttypid ||
13060 attTup->atttypmod != attOldTup->atttypmod)
13062 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13063 errmsg(
"cannot alter type of column \"%s\" twice",
13067 typeTuple =
typenameType(NULL, typeName, &targettypmod);
13069 targettype = tform->oid;
13085 if (attTup->atthasdef)
13091 defaultexpr,
exprType(defaultexpr),
13092 targettype, targettypmod,
13096 if (defaultexpr == NULL)
13098 if (attTup->attgenerated)
13100 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13101 errmsg(
"generation expression for column \"%s\" cannot be cast automatically to type %s",
13105 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13106 errmsg(
"default for column \"%s\" cannot be cast automatically to type %s",
13111 defaultexpr = NULL;
13132 Anum_pg_depend_classid,
13136 Anum_pg_depend_objid,
13140 Anum_pg_depend_objsubid,
13152 foundObject.
classId = foundDep->refclassid;
13153 foundObject.
objectId = foundDep->refobjid;
13157 elog(
ERROR,
"found unexpected dependency type '%c'",
13158 foundDep->deptype);
13159 if (!(foundDep->refclassid == TypeRelationId &&
13160 foundDep->refobjid == attTup->atttypid) &&
13161 !(foundDep->refclassid == CollationRelationId &&
13162 foundDep->refobjid == attTup->attcollation))
13163 elog(
ERROR,
"found unexpected dependency for column: %s",
13178 if (attTup->atthasmissing)
13188 Anum_pg_attribute_attmissingval,
13189 attrelation->rd_att,
13205 Datum valuesAtt[Natts_pg_attribute] = {0};
13206 bool nullsAtt[Natts_pg_attribute] = {0};
13207 bool replacesAtt[Natts_pg_attribute] = {0};
13225 valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
13226 replacesAtt[Anum_pg_attribute_attmissingval - 1] =
true;
13227 nullsAtt[Anum_pg_attribute_attmissingval - 1] =
false;
13230 valuesAtt, nullsAtt, replacesAtt);
13237 attTup->atttypid = targettype;
13238 attTup->atttypmod = targettypmod;
13239 attTup->attcollation = targetcollid;
13242 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
13243 errmsg(
"too many array dimensions"));
13244 attTup->attndims =
list_length(typeName->arrayBounds);
13245 attTup->attlen = tform->typlen;
13246 attTup->attbyval = tform->typbyval;
13247 attTup->attalign = tform->typalign;
13248 attTup->attstorage = tform->typstorage;
13283 if (attTup->attgenerated)
13288 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
13337 Anum_pg_depend_refclassid,
13341 Anum_pg_depend_refobjid,
13345 Anum_pg_depend_refobjsubid,
13357 foundObject.
classId = foundDep->classid;
13358 foundObject.
objectId = foundDep->objid;
13363 case RelationRelationId:
13367 if (relKind == RELKIND_INDEX ||
13368 relKind == RELKIND_PARTITIONED_INDEX)
13373 else if (relKind == RELKIND_SEQUENCE)
13384 elog(
ERROR,
"unexpected object depending on column: %s",
13390 case ConstraintRelationId:
13395 case ProcedureRelationId:
13409 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13410 errmsg(
"cannot alter type of a column used by a function or procedure"),
13411 errdetail(
"%s depends on column \"%s\"",
13416 case RewriteRelationId:
13424 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13425 errmsg(
"cannot alter type of a column used by a view or rule"),
13426 errdetail(
"%s depends on column \"%s\"",
13431 case TriggerRelationId:
13444 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13445 errmsg(
"cannot alter type of a column used in a trigger definition"),
13446 errdetail(
"%s depends on column \"%s\"",
13451 case PolicyRelationId:
13463 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13464 errmsg(
"cannot alter type of a column used in a policy definition"),
13465 errdetail(
"%s depends on column \"%s\"",
13470 case AttrDefaultRelationId:
13494 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13495 errmsg(
"cannot alter type of a column used by a generated column"),
13496 errdetail(
"Column \"%s\" is used by generated column \"%s\".",
13505 case StatisticExtRelationId:
13514 case PublicationRelRelationId:
13522 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13523 errmsg(
"cannot alter type of a column used by a publication WHERE clause"),
13524 errdetail(
"%s depends on column \"%s\"",
13535 elog(
ERROR,
"unexpected object depending on column: %s",
13556 elog(
ERROR,
"relation %u has multiple indexes marked as replica identity", tab->
relid);
13571 elog(
ERROR,
"relation %u has multiple clustered indexes", tab->
relid);
13741 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
13744 relid = con->conrelid;
13750 elog(
ERROR,
"could not identify relation associated with constraint %u", oldId);
13752 confrelid = con->confrelid;
13753 contype = con->contype;
13754 conislocal = con->conislocal;
13775 if (relid != tab->
relid && contype == CONSTRAINT_FOREIGN)
13779 (
char *)
lfirst(def_item),
13780 wqueue, lockmode, tab->
rewrite);
13782 forboth(oid_item, tab->changedIndexOids,
13783 def_item, tab->changedIndexDefs)
13790 (
char *)
lfirst(def_item),
13791 wqueue, lockmode, tab->rewrite);
13798 forboth(oid_item, tab->changedStatisticsOids,
13799 def_item, tab->changedStatisticsDefs)
13806 (
char *)
lfirst(def_item),
13807 wqueue, lockmode, tab->rewrite);
13816 if (tab->replicaIdentityIndex)
13822 subcmd->
name = tab->replicaIdentityIndex;
13834 if (tab->clusterOnIndex)
13839 cmd->
name = tab->clusterOnIndex;
13872 List *raw_parsetree_list;
13873 List *querytree_list;
13884 querytree_list =
NIL;
13885 foreach(list_item, raw_parsetree_list)
13891 querytree_list =
lappend(querytree_list,
13905 querytree_list =
list_concat(querytree_list, beforeStmts);
13907 querytree_list =
list_concat(querytree_list, afterStmts);
13910 querytree_list =
lappend(querytree_list,
13929 foreach(list_item, querytree_list)
13943 stmt->reset_default_tblspc =
true;
13958 foreach(lcmd,
stmt->cmds)
13974 RelationRelationId, 0);
13996 !rewrite && tab->
rewrite == 0)
14022 elog(
ERROR,
"unexpected statement subtype: %d",
14030 if (
stmt->subtype ==
'C')
14049 elog(
ERROR,
"unexpected statement subtype: %d",
14050 (
int)
stmt->subtype);
14058 stmt->stxcomment =
GetComment(oldId, StatisticExtRelationId, 0);
14067 elog(
ERROR,
"unexpected statement type: %d",
14087 const char *conname)
14094 comment_str =
GetComment(objid, ConstraintRelationId, 0);
14095 if (comment_str == NULL)
14132 stmt->accessMethod,
14134 stmt->excludeOpNames))
14139 if (irel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
14171 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
14174 Anum_pg_constraint_conpfeqop);
14181 elog(
ERROR,
"conpfeqop is not a 1-D Oid array");
14185 for (
i = 0;
i < numkeys;
i++)
14198 const char *colName,
14209 Datum repl_val[Natts_pg_attribute];
14210 bool repl_null[Natts_pg_attribute];
14211 bool repl_repl[Natts_pg_attribute];
14226 (
errcode(ERRCODE_UNDEFINED_OBJECT),
14227 errmsg(
"foreign table \"%s\" does not exist",
14240 (
errcode(ERRCODE_UNDEFINED_COLUMN),
14241 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
14246 attnum = atttableform->attnum;
14249 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14250 errmsg(
"cannot alter system column \"%s\"", colName)));
14254 memset(repl_val, 0,
sizeof(repl_val));
14255 memset(repl_null,
false,
sizeof(repl_null));
14256 memset(repl_repl,
false,
sizeof(repl_repl));
14261 Anum_pg_attribute_attfdwoptions,
14273 repl_val[Anum_pg_attribute_attfdwoptions - 1] = datum;
14275 repl_null[Anum_pg_attribute_attfdwoptions - 1] =
true;
14277 repl_repl[Anum_pg_attribute_attfdwoptions - 1] =
true;
14282 repl_val, repl_null, repl_repl);
14288 atttableform->attnum);
14332 elog(
ERROR,
"cache lookup failed for relation %u", relationOid);
14336 switch (tuple_class->relkind)
14338 case RELKIND_RELATION:
14340 case RELKIND_MATVIEW:
14341 case RELKIND_FOREIGN_TABLE:
14342 case RELKIND_PARTITIONED_TABLE:
14345 case RELKIND_INDEX:
14355 if (tuple_class->relowner != newOwnerId)
14357 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14358 errmsg(
"cannot change owner of index \"%s\"",
14359 NameStr(tuple_class->relname)),
14360 errhint(
"Change the ownership of the index's table instead.")));
14362 newOwnerId = tuple_class->relowner;
14365 case RELKIND_PARTITIONED_INDEX:
14369 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14370 errmsg(
"cannot change owner of index \"%s\"",
14371 NameStr(tuple_class->relname)),
14372 errhint(
"Change the ownership of the index's table instead.")));
14374 case RELKIND_SEQUENCE:
14376 tuple_class->relowner != newOwnerId)
14385 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14386 errmsg(
"cannot change owner of sequence \"%s\"",
14387 NameStr(tuple_class->relname)),
14388 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
14389 NameStr(tuple_class->relname),
14393 case RELKIND_COMPOSITE_TYPE:
14397 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14398 errmsg(
"\"%s\" is a composite type",
14399 NameStr(tuple_class->relname)),
14404 case RELKIND_TOASTVALUE:
14410 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14411 errmsg(
"cannot change owner of relation \"%s\"",
14412 NameStr(tuple_class->relname)),
14420 if (tuple_class->relowner != newOwnerId)
14422 Datum repl_val[Natts_pg_class];
14423 bool repl_null[Natts_pg_class];
14424 bool repl_repl[Natts_pg_class];
14436 Oid namespaceOid = tuple_class->relnamespace;
14448 aclresult =
object_aclcheck(NamespaceRelationId, namespaceOid, newOwnerId,
14456 memset(repl_null,
false,
sizeof(repl_null));
14457 memset(repl_repl,
false,
sizeof(repl_repl));
14459 repl_repl[Anum_pg_class_relowner - 1] =
true;
14467 Anum_pg_class_relacl,
14472 tuple_class->relowner, newOwnerId);
14473 repl_repl[Anum_pg_class_relacl - 1] =
true;
14488 tuple_class->relowner,
14496 if (tuple_class->relkind != RELKIND_COMPOSITE_TYPE &&
14497 tuple_class->relkind != RELKIND_INDEX &&
14498 tuple_class->relkind != RELKIND_PARTITIONED_INDEX &&
14499 tuple_class->relkind != RELKIND_TOASTVALUE)
14514 if (tuple_class->relkind == RELKIND_RELATION ||
14515 tuple_class->relkind == RELKIND_PARTITIONED_TABLE ||
14516 tuple_class->relkind == RELKIND_MATVIEW ||
14517 tuple_class->relkind == RELKIND_TOASTVALUE)
14519 List *index_oid_list;
14526 foreach(
i, index_oid_list)
14533 if (tuple_class->reltoastrelid !=
InvalidOid)
14564 Anum_pg_attribute_attrelid,
14568 true, NULL, 1,
key);
14572 Datum repl_val[Natts_pg_attribute];
14573 bool repl_null[Natts_pg_attribute];
14574 bool repl_repl[Natts_pg_attribute];
14581 if (att->attisdropped)
14585 Anum_pg_attribute_attacl,
14592 memset(repl_null,
false,
sizeof(repl_null));
14593 memset(repl_repl,
false,
sizeof(repl_repl));
14596 oldOwnerId, newOwnerId);
14597 repl_repl[Anum_pg_attribute_attacl - 1] =
true;
14602 repl_val, repl_null, repl_repl);
14634 Anum_pg_depend_refclassid,
14638 Anum_pg_depend_refobjid,
14652 if (depForm->refobjsubid == 0 ||
14653 depForm->classid != RelationRelationId ||
14654 depForm->objsubid != 0 ||
14698 (
errcode(ERRCODE_UNDEFINED_OBJECT),
14699 errmsg(
"index \"%s\" for table \"%s\" does not exist",
14709 RelationRelationId, indexOid);
14742 if (amname != NULL)
14744 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
14750 if (rel->
rd_rel->relam == amoid)
14770 Oid oldAccessMethodId;
14786 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
14790 oldAccessMethodId = rd_rel->relam;
14791 rd_rel->relam = newAccessMethodId;
14794 if (rd_rel->relam == oldAccessMethodId)
14830 AccessMethodRelationId,
14840 AccessMethodRelationId,
14841 oldAccessMethodId, rd_rel->relam);
14877 (
errcode(ERRCODE_SYNTAX_ERROR),
14878 errmsg(
"cannot have multiple SET TABLESPACE subcommands")));
14897 Datum repl_val[Natts_pg_class];
14898 bool repl_null[Natts_pg_class];
14899 bool repl_repl[Natts_pg_class];
14911 elog(
ERROR,
"cache lookup failed for relation %u", relid);
14931 defList, NULL, validnsps,
false,
14935 switch (rel->
rd_rel->relkind)
14937 case RELKIND_RELATION:
14938 case RELKIND_TOASTVALUE:
14939 case RELKIND_MATVIEW:
14942 case RELKIND_PARTITIONED_TABLE:
14948 case RELKIND_INDEX:
14949 case RELKIND_PARTITIONED_INDEX:
14954 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14955 errmsg(
"cannot set options for relation \"%s\"",
14962 if (rel->
rd_rel->relkind == RELKIND_VIEW)
14967 bool check_option =
false;
14969 foreach(cell, view_options)
14973 if (strcmp(defel->
defname,
"check_option") == 0)
14974 check_option =
true;
14983 const char *view_updatable_error =
14986 if (view_updatable_error)
14988 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14989 errmsg(
"WITH CHECK OPTION is supported only on automatically updatable views"),
14990 errhint(
"%s",
_(view_updatable_error))));
14998 memset(repl_val, 0,
sizeof(repl_val));
14999 memset(repl_null,
false,
sizeof(repl_null));
15000 memset(repl_repl,
false,
sizeof(repl_repl));
15002 if (newOptions != (
Datum) 0)
15003 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
15005 repl_null[Anum_pg_class_reloptions - 1] =
true;
15007 repl_repl[Anum_pg_class_reloptions - 1] =
true;
15010 repl_val, repl_null, repl_repl);
15024 Oid toastid = rel->
rd_rel->reltoastrelid;
15031 elog(
ERROR,
"cache lookup failed for relation %u", toastid);
15050 defList,
"toast", validnsps,
false,
15055 memset(repl_val, 0,
sizeof(repl_val));
15056 memset(repl_null,
false,
sizeof(repl_null));
15057 memset(repl_repl,
false,
sizeof(repl_repl));
15059 if (newOptions != (
Datum) 0)
15060 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
15062 repl_null[Anum_pg_class_reloptions - 1] =
true;
15064 repl_repl[Anum_pg_class_reloptions - 1] =
true;
15067 repl_val, repl_null, repl_repl);
15113 reltoastrelid = rel->
rd_rel->reltoastrelid;
15128 rel->
rd_rel->relpersistence);
15132 newrlocator.
relNumber = newrelfilenumber;
15133 newrlocator.
spcOid = newTableSpace;
15136 if (rel->
rd_rel->relkind == RELKIND_INDEX)
15168 foreach(lc, reltoastidxids)
15230 Oid orig_tablespaceoid;
15231 Oid new_tablespaceoid;
15238 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15239 errmsg(
"only tables, indexes, and materialized views exist in tablespaces")));
15247 if (orig_tablespaceoid == GLOBALTABLESPACE_OID ||
15248 new_tablespaceoid == GLOBALTABLESPACE_OID)
15250 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15251 errmsg(
"cannot move relations in to or out of pg_global tablespace")));
15280 if (orig_tablespaceoid == new_tablespaceoid)
15281 return new_tablespaceoid;
15288 Anum_pg_class_reltablespace,
15297 Oid relOid = relForm->oid;
15308 relForm->relisshared ||
15315 relForm->relkind != RELKIND_RELATION &&
15316 relForm->relkind != RELKIND_PARTITIONED_TABLE) ||
15318 relForm->relkind != RELKIND_INDEX &&
15319 relForm->relkind != RELKIND_PARTITIONED_INDEX) ||
15321 relForm->relkind != RELKIND_MATVIEW))
15339 if (
stmt->nowait &&
15342 (
errcode(ERRCODE_OBJECT_IN_USE),
15343 errmsg(
"aborting because lock on relation \"%s.%s\" is not available",
15345 NameStr(relForm->relname))));
15356 if (relations ==
NIL)
15358 (
errcode(ERRCODE_NO_DATA_FOUND),
15359 errmsg(
"no matching relations in tablespace \"%s\" found",
15360 orig_tablespaceoid ==
InvalidOid ?
"(database default)" :
15364 foreach(l, relations)
15370 cmd->
name =
stmt->new_tablespacename;
15380 return new_tablespaceoid;
15407 rel->
rd_rel->relpersistence);
15422 (rel->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
15426 rel->
rd_rel->relpersistence);
15442 char fires_when,
bool skip_system,
bool recurse,
15446 fires_when, skip_system, recurse,
15460 char fires_when,
LOCKMODE lockmode)
15478 if (child_rel->
rd_rel->reloftype)
15480 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15481 errmsg(
"cannot change inheritance of typed table")));
15483 if (child_rel->
rd_rel->relispartition)
15485 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15486 errmsg(
"cannot change inheritance of a partition")));
15488 if (child_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
15490 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15491 errmsg(
"cannot change inheritance of partitioned table")));
15503 const char *trigger_name;
15518 if (parent_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
15519 child_rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
15521 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15522 errmsg(
"cannot inherit from temporary relation \"%s\"",
15526 if (parent_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
15529 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15530 errmsg(
"cannot inherit from temporary relation of another session")));
15533 if (child_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
15536 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15537 errmsg(
"cannot inherit to temporary relation of another session")));
15540 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
15542 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15543 errmsg(
"cannot inherit from partitioned table \"%s\"",
15547 if (parent_rel->
rd_rel->relispartition)
15549 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15550 errmsg(
"cannot inherit from a partition")));
15571 (
errcode(ERRCODE_DUPLICATE_TABLE),
15572 errmsg(
"circular inheritance not allowed"),
15573 errdetail(
"\"%s\" is already a child of \"%s\".",
15583 if (trigger_name != NULL)
15585 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15586 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming an inheritance child",
15588 errdetail(
"ROW triggers with transition tables are not supported in inheritance hierarchies.")));
15631 Anum_pg_inherits_inhrelid,
15635 true, NULL, 1, &
key);
15645 (
errcode(ERRCODE_DUPLICATE_TABLE),
15646 errmsg(
"relation \"%s\" would be inherited from more than once",
15649 if (inh->inhseqno > inhseqno)
15650 inhseqno = inh->inhseqno;
15667 parent_rel->
rd_rel->relkind ==
15668 RELKIND_PARTITIONED_TABLE);
15687 attr =
heap_getattr(contup, Anum_pg_constraint_conbin, tupdesc, &isnull);
15689 elog(
ERROR,
"null conbin for constraint %u", con->oid);
15709 if (acon->condeferrable != bcon->condeferrable ||
15710 acon->condeferred != bcon->condeferred ||
15741 for (
AttrNumber parent_attno = 1; parent_attno <= parent_desc->
natts; parent_attno++)
15744 char *parent_attname =
NameStr(parent_att->attname);
15748 if (parent_att->attisdropped)
15757 if (parent_att->atttypid != child_att->atttypid ||
15758 parent_att->atttypmod != child_att->atttypmod)
15760 (
errcode(ERRCODE_DATATYPE_MISMATCH),
15761 errmsg(
"child table \"%s\" has different type for column \"%s\"",
15764 if (parent_att->attcollation != child_att->attcollation)
15766 (
errcode(ERRCODE_COLLATION_MISMATCH),
15767 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
15774 if (parent_att->attnotnull && !child_att->attnotnull)
15776 (
errcode(ERRCODE_DATATYPE_MISMATCH),
15777 errmsg(
"column \"%s\" in child table must be marked NOT NULL",
15783 if (parent_att->attgenerated && !child_att->attgenerated)
15785 (
errcode(ERRCODE_DATATYPE_MISMATCH),
15786 errmsg(
"column \"%s\" in child table must be a generated column", parent_attname)));
15787 if (child_att->attgenerated && !parent_att->attgenerated)
15789 (
errcode(ERRCODE_DATATYPE_MISMATCH),
15790 errmsg(
"column \"%s\" in child table must not be a generated column", parent_attname)));
15798 child_att->attidentity = parent_att->attidentity;
15804 child_att->attinhcount++;
15805 if (child_att->attinhcount < 0)
15807 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
15808 errmsg(
"too many inheritance parents"));
15815 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
15817 Assert(child_att->attinhcount == 1);
15818 child_att->attislocal =
false;
15827 (
errcode(ERRCODE_DATATYPE_MISMATCH),
15828 errmsg(
"child table is missing column \"%s\"", parent_attname)));
15865 Anum_pg_constraint_conrelid,
15869 true, NULL, 1, &parent_key);
15877 bool found =
false;
15879 if (parent_con->contype != CONSTRAINT_CHECK)
15883 if (parent_con->connoinherit)
15888 Anum_pg_constraint_conrelid,
15892 true, NULL, 1, &child_key);
15899 if (child_con->contype != CONSTRAINT_CHECK)
15902 if (strcmp(
NameStr(parent_con->conname),
15903 NameStr(child_con->conname)) != 0)
15908 (
errcode(ERRCODE_DATATYPE_MISMATCH),
15909 errmsg(
"child table \"%s\" has different definition for check constraint \"%s\"",
15913 if (child_con->connoinherit)
15915 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
15916 errmsg(
"constraint \"%s\" conflicts with non-inherited constraint on child table \"%s\"",
15923 if (parent_con->convalidated && !child_con->convalidated)
15925 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
15926 errmsg(
"constraint \"%s\" conflicts with NOT VALID constraint on child table \"%s\"",
15935 child_con->coninhcount++;
15936 if (child_con->coninhcount < 0)
15938 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
15939 errmsg(
"too many inheritance parents"));
15946 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
15948 Assert(child_con->coninhcount == 1);
15949 child_con->conislocal =
false;
15963 (
errcode(ERRCODE_DATATYPE_MISMATCH),
15964 errmsg(
"child table is missing constraint \"%s\"",
15965 NameStr(parent_con->conname))));
15983 if (rel->
rd_rel->relispartition)
15985 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15986 errmsg(
"cannot change inheritance of a partition")));
16026 bool found =
false;
16028 Assert(parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
16036 Anum_pg_inherits_inhparent,
16040 true, NULL, 1, &
key);
16047 if (inhForm->inhdetachpending)
16049 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
16050 errmsg(
"partition \"%s\" already pending detach in partitioned table \"%s.%s\"",
16054 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
16079 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
16112 bool is_partitioning;
16114 is_partitioning = (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
16122 if (is_partitioning)
16125 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
16131 errmsg(
"relation \"%s\" is not a parent of relation \"%s\"",
16141 Anum_pg_attribute_attrelid,
16145 true, NULL, 1,
key);
16151 if (att->attisdropped)
16153 if (att->attinhcount <= 0)
16163 copy_att->attinhcount--;
16164 if (copy_att->attinhcount == 0)
16165 copy_att->attislocal =
true;
16182 Anum_pg_constraint_conrelid,
16186 true, NULL, 1,
key);
16194 if (con->contype == CONSTRAINT_CHECK)
16202 Anum_pg_constraint_conrelid,
16206 true, NULL, 1,
key);
16213 if (con->contype != CONSTRAINT_CHECK)
16219 if (strcmp(
NameStr(con->conname), chkname) == 0)
16232 if (copy_con->coninhcount <= 0)
16233 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
16236 copy_con->coninhcount--;
16237 if (copy_con->coninhcount == 0)
16238 copy_con->conislocal =
true;
16249 RelationRelationId,
16282 Anum_pg_depend_classid,
16286 Anum_pg_depend_objid,
16290 Anum_pg_depend_objsubid,
16301 if (dep->refclassid == refclassid &&
16302 dep->refobjid == refobjid &&
16303 dep->refobjsubid == 0 &&
16304 dep->deptype == deptype)
16345 typeid = typeform->oid;
16350 Anum_pg_inherits_inhrelid,
16354 true, NULL, 1, &
key);
16357 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16358 errmsg(
"typed tables cannot inherit")));
16369 for (type_attno = 1; type_attno <= typeTupleDesc->
natts; type_attno++)
16373 const char *type_attname,
16378 if (type_attr->attisdropped)
16380 type_attname =
NameStr(type_attr->attname);
16385 if (table_attno > tableTupleDesc->
natts)
16387 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16388 errmsg(
"table is missing column \"%s\"",
16390 table_attr =
TupleDescAttr(tableTupleDesc, table_attno - 1);
16392 }
while (table_attr->attisdropped);
16393 table_attname =
NameStr(table_attr->attname);
16396 if (strncmp(table_attname, type_attname,
NAMEDATALEN) != 0)
16398 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16399 errmsg(
"table has column \"%s\" where type requires \"%s\"",
16400 table_attname, type_attname)));
16403 if (table_attr->atttypid != type_attr->atttypid ||
16404 table_attr->atttypmod != type_attr->atttypmod ||
16405 table_attr->attcollation != type_attr->attcollation)
16407 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16408 errmsg(
"table \"%s\" has different type for column \"%s\"",
16414 for (; table_attno <= tableTupleDesc->
natts; table_attno++)
16419 if (!table_attr->attisdropped)
16421 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16422 errmsg(
"table has extra column \"%s\"",
16423 NameStr(table_attr->attname))));
16427 if (rel->
rd_rel->reloftype)
16432 tableobj.
classId = RelationRelationId;
16435 typeobj.
classId = TypeRelationId;
16444 elog(
ERROR,
"cache lookup failed for relation %u", relid);
16473 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16474 errmsg(
"\"%s\" is not a typed table",
16489 elog(
ERROR,
"cache lookup failed for relation %u", relid);
16527 elog(
ERROR,
"cache lookup failed for relation \"%s\"",
16530 if (pg_class_form->relreplident != ri_type)
16532 pg_class_form->relreplident = ri_type;
16545 bool dirty =
false;
16550 elog(
ERROR,
"cache lookup failed for index %u", thisIndexOid);
16553 if (thisIndexOid == indexOid)
16556 if (!pg_index_form->indisreplident)
16559 pg_index_form->indisreplident =
true;
16565 if (pg_index_form->indisreplident)
16568 pg_index_form->indisreplident =
false;
16603 if (
stmt->identity_type == REPLICA_IDENTITY_DEFAULT)
16608 else if (
stmt->identity_type == REPLICA_IDENTITY_FULL)
16613 else if (
stmt->identity_type == REPLICA_IDENTITY_NOTHING)
16618 else if (
stmt->identity_type == REPLICA_IDENTITY_INDEX)
16623 elog(
ERROR,
"unexpected identity type %u",
stmt->identity_type);
16629 (
errcode(ERRCODE_UNDEFINED_OBJECT),
16630 errmsg(
"index \"%s\" for table \"%s\" does not exist",
16639 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16640 errmsg(
"\"%s\" is not an index for table \"%s\"",
16647 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16648 errmsg(
"cannot use non-unique index \"%s\" as replica identity",
16651 if (!indexRel->
rd_index->indimmediate)
16653 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16654 errmsg(
"cannot use non-immediate index \"%s\" as replica identity",
16659 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16660 errmsg(
"cannot use expression index \"%s\" as replica identity",
16665 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16666 errmsg(
"cannot use partial index \"%s\" as replica identity",
16682 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
16683 errmsg(
"index \"%s\" cannot be used as replica identity because column %d is a system column",
16687 if (!attr->attnotnull)
16689 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16690 errmsg(
"index \"%s\" cannot be used as replica identity because column \"%s\" is nullable",
16719 elog(
ERROR,
"cache lookup failed for relation %u", relid);
16748 elog(
ERROR,
"cache lookup failed for relation %u", relid);
16771 Datum repl_val[Natts_pg_foreign_table];
16772 bool repl_null[Natts_pg_foreign_table];
16773 bool repl_repl[Natts_pg_foreign_table];
16786 (
errcode(ERRCODE_UNDEFINED_OBJECT),
16787 errmsg(
"foreign table \"%s\" does not exist",
16793 memset(repl_val, 0,
sizeof(repl_val));
16794 memset(repl_null,
false,
sizeof(repl_null));
16795 memset(repl_repl,
false,
sizeof(repl_repl));
16800 Anum_pg_foreign_table_ftoptions,
16812 repl_val[Anum_pg_foreign_table_ftoptions - 1] = datum;
16814 repl_null[Anum_pg_foreign_table_ftoptions - 1] =
true;
16816 repl_repl[Anum_pg_foreign_table_ftoptions - 1] =
true;
16821 repl_val, repl_null, repl_repl);
16846 const char *column,
16858 compression =
strVal(newValue);
16866 (
errcode(ERRCODE_UNDEFINED_COLUMN),
16867 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
16872 attnum = atttableform->attnum;
16875 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16876 errmsg(
"cannot alter system column \"%s\"", column)));
16885 atttableform->attcompression = cmethod;
16937 switch (rel->
rd_rel->relpersistence)
16939 case RELPERSISTENCE_TEMP:
16941 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
16942 errmsg(
"cannot change logged status of table \"%s\" because it is temporary",
16946 case RELPERSISTENCE_PERMANENT:
16951 case RELPERSISTENCE_UNLOGGED:
16965 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
16966 errmsg(
"cannot change table \"%s\" to unlogged because it is part of a publication",
16968 errdetail(
"Unlogged relations cannot be replicated.")));
16982 toLogged ? Anum_pg_constraint_conrelid :
16983 Anum_pg_constraint_confrelid,
16987 toLogged ? ConstraintRelidTypidNameIndexId :
InvalidOid,
16988 true, NULL, 1, skey);
16994 if (con->contype == CONSTRAINT_FOREIGN)
17000 foreignrelid = toLogged ? con->confrelid : con->conrelid;
17012 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17013 errmsg(
"could not change table \"%s\" to logged because it references unlogged table \"%s\"",
17022 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17023 errmsg(
"could not change table \"%s\" to unlogged because it references logged table \"%s\"",
17062 (
errmsg(
"relation \"%s\" does not exist, skipping",
17063 stmt->relation->relname)));
17072 if (rel->
rd_rel->relkind == RELKIND_SEQUENCE)
17080 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17081 errmsg(
"cannot move an owned sequence into another schema"),
17082 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
17101 *oldschema = oldNspOid;
17120 Assert(objsMoved != NULL);
17126 nspOid,
true, objsMoved);
17153 Oid oldNspOid,
Oid newNspOid,
17154 bool hasDependEntry,
17160 bool already_done =
false;
17164 elog(
ERROR,
"cache lookup failed for relation %u", relOid);
17167 Assert(classForm->relnamespace == oldNspOid);
17169 thisobj.
classId = RelationRelationId;
17179 if (!already_done && oldNspOid != newNspOid)
17185 (
errcode(ERRCODE_DUPLICATE_TABLE),
17186 errmsg(
"relation \"%s\" already exists in schema \"%s\"",
17191 classForm->relnamespace = newNspOid;
17196 if (hasDependEntry &&
17199 NamespaceRelationId,
17202 elog(
ERROR,
"could not change schema dependency for relation \"%s\"",
17203 NameStr(classForm->relname));
17230 foreach(l, indexList)
17235 thisobj.
classId = RelationRelationId;
17250 oldNspOid, newNspOid,
17283 Anum_pg_depend_refclassid,
17287 Anum_pg_depend_refobjid,
17301 if (depForm->refobjsubid == 0 ||
17302 depForm->classid != RelationRelationId ||
17303 depForm->objsubid != 0 ||
17320 oldNspOid, newNspOid,
17396 if (oc->
relid == relid)
17414 List *oids_to_truncate =
NIL;
17455 if (oids_to_truncate !=
NIL)
17458 if (oids_to_drop !=
NIL)
17462 foreach(l, oids_to_drop)
17466 object.
classId = RelationRelationId;
17468 object.objectSubId = 0;
17490 #ifdef USE_ASSERT_CHECKING
17603 if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE &&
17604 relkind != RELKIND_MATVIEW && relkind != RELKIND_PARTITIONED_TABLE)
17606 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17607 errmsg(
"\"%s\" is not a table or materialized view", relation->
relname)));
17632 elog(
ERROR,
"cache lookup failed for relation %u", relId);
17656 elog(
ERROR,
"cache lookup failed for relation %u", relId);
17665 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
17666 errmsg(
"permission denied: \"%s\" is a system catalog",
17691 relkind = classform->relkind;
17700 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
17701 errmsg(
"permission denied: \"%s\" is a system catalog",
17712 aclresult =
object_aclcheck(NamespaceRelationId, classform->relnamespace,
17739 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17742 if (reltype ==
OBJECT_VIEW && relkind != RELKIND_VIEW)
17744 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17749 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17750 errmsg(
"\"%s\" is not a materialized view", rv->
relname)));
17754 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17757 if (reltype ==
OBJECT_TYPE && relkind != RELKIND_COMPOSITE_TYPE)
17759 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17762 if (reltype ==
OBJECT_INDEX && relkind != RELKIND_INDEX &&
17763 relkind != RELKIND_PARTITIONED_INDEX
17766 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17773 if (reltype !=
OBJECT_TYPE && relkind == RELKIND_COMPOSITE_TYPE)
17775 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17787 if (relkind == RELKIND_INDEX || relkind == RELKIND_PARTITIONED_INDEX)
17789 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17790 errmsg(
"cannot change schema of index \"%s\"",
17792 errhint(
"Change the schema of the table instead.")));
17793 else if (relkind == RELKIND_COMPOSITE_TYPE)
17795 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17796 errmsg(
"cannot change schema of composite type \"%s\"",
17801 else if (relkind == RELKIND_TOASTVALUE)
17803 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17804 errmsg(
"cannot change schema of TOAST table \"%s\"",
17806 errhint(
"Change the schema of the table instead.")));
17835 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
17836 errmsg(
"cannot use \"list\" partition strategy with more than one column")));
17844 NULL,
false,
true);
17877 List **partexprs,
Oid *partopclass,
Oid *partcollation,
17885 foreach(lc, partParams)
17891 if (pelem->
name != NULL)
17901 (
errcode(ERRCODE_UNDEFINED_COLUMN),
17902 errmsg(
"column \"%s\" named in partition key does not exist",
17907 if (attform->attnum <= 0)
17909 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
17910 errmsg(
"cannot use system column \"%s\" in partition key",
17918 if (attform->attgenerated)
17920 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
17921 errmsg(
"cannot use generated column in partition key"),
17922 errdetail(
"Column \"%s\" is a generated column.",
17926 partattrs[attn] = attform->attnum;
17927 atttype = attform->atttypid;
17928 attcollation = attform->attcollation;
17935 char partattname[16];
17947 snprintf(partattname,
sizeof(partattname),
"%d", attn + 1);
17949 atttype, attcollation,
17960 ((
Var *) expr)->varattno > 0)
17966 partattrs[attn] = ((
Var *) expr)->varattno;
17973 partattrs[attn] = 0;
17974 *partexprs =
lappend(*partexprs, expr);
17993 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
17994 errmsg(
"partition key expressions cannot contain system column references")));
18010 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18011 errmsg(
"cannot use generated column in partition key"),
18012 errdetail(
"Column \"%s\" is a generated column.",
18040 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18041 errmsg(
"functions in partition key expression must be marked IMMUTABLE")));
18049 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18050 errmsg(
"cannot use constant expression as partition key")));
18070 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
18071 errmsg(
"could not determine which collation to use for partition expression"),
18072 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
18078 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18079 errmsg(
"collations are not supported by type %s",
18083 partcollation[attn] = attcollation;
18091 am_oid = HASH_AM_OID;
18093 am_oid = BTREE_AM_OID;
18103 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18104 errmsg(
"data type %s has no default operator class for access method \"%s\"",
18106 errhint(
"You must specify a hash operator class or define a default hash operator class for the data type.")));
18109 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18110 errmsg(
"data type %s has no default operator class for access method \"%s\"",
18112 errhint(
"You must specify a btree operator class or define a default btree operator class for the data type.")));
18118 am_oid == HASH_AM_OID ?
"hash" :
"btree",
18135 List *partConstraint)
18145 for (
i = 1;
i <= natts;
i++)
18149 if (att->attnotnull && !att->attisdropped)
18166 ntest->argisrow =
false;
18168 existConstraint =
lappend(existConstraint, ntest);
18194 num_check = (constr != NULL) ? constr->
num_check : 0;
18195 for (
i = 0;
i < num_check;
i++)
18245 List *partConstraint,
18246 bool validate_default)
18254 if (!validate_default)
18256 (
errmsg_internal(
"partition constraint for table \"%s\" is implied by existing constraints",
18260 (
errmsg_internal(
"updated partition constraint for default partition \"%s\" is implied by existing constraints",
18270 if (scanrel->
rd_rel->relkind == RELKIND_RELATION)
18280 else if (scanrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
18288 List *thisPartConstraint;
18299 thisPartConstraint =
18301 part_rel, scanrel);
18304 thisPartConstraint,
18353 List *attachrel_children;
18354 List *partConstraint;
18361 const char *trigger_name;
18362 Oid defaultPartOid;
18363 List *partBoundConstraint;
18391 if (attachrel->
rd_rel->relispartition)
18393 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18394 errmsg(
"\"%s\" is already a partition",
18399 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18400 errmsg(
"cannot attach a typed table as partition")));
18408 Anum_pg_inherits_inhrelid,
18415 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18416 errmsg(
"cannot attach inheritance child as partition")));
18421 Anum_pg_inherits_inhparent,
18427 attachrel->
rd_rel->relkind == RELKIND_RELATION)
18429 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18430 errmsg(
"cannot attach inheritance parent as partition")));
18453 (
errcode(ERRCODE_DUPLICATE_TABLE),
18454 errmsg(
"circular inheritance not allowed"),
18455 errdetail(
"\"%s\" is already a child of \"%s\".",
18460 if (rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
18461 attachrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
18463 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18464 errmsg(
"cannot attach a temporary relation as partition of permanent relation \"%s\"",
18468 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
18469 attachrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
18471 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18472 errmsg(
"cannot attach a permanent relation as partition of temporary relation \"%s\"",
18476 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
18479 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18480 errmsg(
"cannot attach as partition of temporary relation of another session")));
18483 if (attachrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
18486 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18487 errmsg(
"cannot attach temporary relation of another session as partition")));
18494 natts = tupleDesc->
natts;
18495 for (attno = 1; attno <= natts; attno++)
18498 char *attributeName =
NameStr(attribute->attname);
18501 if (attribute->attisdropped)
18504 if (attribute->attidentity)
18506 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
18507 errmsg(
"table \"%s\" being attached contains an identity column \"%s\"",
18509 errdetail(
"The new partition may not contain an identity column."));
18516 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18517 errmsg(
"table \"%s\" contains column \"%s\" not found in parent \"%s\"",
18520 errdetail(
"The new partition may contain only the columns present in parent.")));
18529 if (trigger_name != NULL)
18531 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18532 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming a partition",
18534 errdetail(
"ROW triggers with transition tables are not supported on partitions.")));
18542 cmd->
bound, pstate);
18553 partConstraint =
list_concat(partBoundConstraint,
18557 if (partConstraint)
18566 (
Node *) partConstraint);
18593 List *defPartConstraint;
18599 defPartConstraint =
18606 defPartConstraint =
18608 1, defaultrel, rel);
18610 defPartConstraint,
true);
18624 if (attachrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
18628 foreach(l, attachrel_children)
18652 List *attachRelIdxs;
18660 "AttachPartitionEnsureIndexes",
18684 if (attachrel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
18686 foreach(cell, idxes)
18691 if (idxRel->
rd_index->indisunique ||
18694 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18695 errmsg(
"cannot attach foreign table \"%s\" as partition of partitioned table \"%s\"",
18698 errdetail(
"Partitioned table \"%s\" contains unique indexes.",
18710 foreach(cell, idxes)
18716 bool found =
false;
18723 if (idxRel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
18747 if (attachrelIdxRels[
i]->rd_rel->relispartition)
18751 if (!attachrelIdxRels[
i]->rd_index->indisvalid)
18755 attachrelIdxRels[
i]->rd_indcollation,
18810 true,
false,
false,
false,
false);
18842 true, NULL, 1, &
key);
18861 if (!TRIGGER_FOR_ROW(trigForm->tgtype))
18868 if (trigForm->tgisinternal)
18874 if (!TRIGGER_FOR_BEFORE(trigForm->tgtype) &&
18875 !TRIGGER_FOR_AFTER(trigForm->tgtype))
18876 elog(
ERROR,
"unexpected trigger \"%s\" found",
18892 partition, parent);
18894 partition, parent);
18901 if (trigForm->tgattr.dim1 > 0)
18905 for (
i = 0;
i < trigForm->tgattr.dim1;
i++)
18910 trigForm->tgattr.values[
i] - 1);
18917 if (trigForm->tgnargs > 0)
18924 elog(
ERROR,
"tgargs is null for trigger \"%s\" in partition \"%s\"",
18929 for (
int i = 0;
i < trigForm->tgnargs;
i++)
18932 p += strlen(p) + 1;
18942 trigStmt->
args = trigargs;
18943 trigStmt->
row =
true;
18944 trigStmt->
timing = trigForm->tgtype & TRIGGER_TYPE_TIMING_MASK;
18945 trigStmt->
events = trigForm->tgtype & TRIGGER_TYPE_EVENT_MASK;
18949 trigStmt->
deferrable = trigForm->tgdeferrable;
18955 trigForm->tgfoid, trigForm->oid, qual,
18956 false,
true, trigForm->tgenabled);
18992 Oid defaultPartOid;
19019 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19020 errmsg(
"cannot detach partitions concurrently when a default partition exists")));
19062 char *parentrelname;
19124 if (partRel != NULL)
19125 elog(
WARNING,
"dangling partition \"%s\" remains, can't fix",
19128 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19129 errmsg(
"partitioned table \"%s\" was removed concurrently",
19132 if (partRel == NULL)
19134 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19135 errmsg(
"partition \"%s\" was removed concurrently", partrelname)));
19159 Oid defaultPartOid)
19165 Datum new_val[Natts_pg_class];
19166 bool new_null[Natts_pg_class],
19167 new_repl[Natts_pg_class];
19197 Oid insertTriggerOid,
19206 if (conform->contype != CONSTRAINT_FOREIGN ||
19222 &insertTriggerOid, &updateTriggerOid);
19236 fkconstraint->
contype = CONSTRAINT_FOREIGN;
19238 fkconstraint->
deferrable = conform->condeferrable;
19241 fkconstraint->
pktable = NULL;
19254 fkconstraint, fk->
conoid,
19278 ConstraintRelationId,
19288 foreach(cell, indexes)
19294 Oid parentConstrOid;
19326 elog(
ERROR,
"cache lookup failed for relation %u",
19331 memset(new_val, 0,
sizeof(new_val));
19332 memset(new_null,
false,
sizeof(new_null));
19333 memset(new_repl,
false,
sizeof(new_repl));
19334 new_val[Anum_pg_class_relpartbound - 1] = (
Datum) 0;
19335 new_null[Anum_pg_class_relpartbound - 1] =
true;
19336 new_repl[Anum_pg_class_relpartbound - 1] =
true;
19338 new_val, new_null, new_repl);
19352 if (!attr->attisdropped && attr->attidentity)
19386 if (partRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
19392 foreach(cell, children)
19443 List *constraintExpr;
19499 true, NULL, 1, &skey);
19525 RelationRelationId,
19564 if (!
state->lockedParentTbl)
19567 state->lockedParentTbl =
true;
19590 if (classform->relkind != RELKIND_PARTITIONED_INDEX &&
19591 classform->relkind != RELKIND_INDEX)
19593 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19628 state.lockedParentTbl =
false;
19636 (
errcode(ERRCODE_UNDEFINED_OBJECT),
19637 errmsg(
"index \"%s\" does not exist",
name->relname)));
19649 currParent = partIdx->
rd_rel->relispartition ?
19670 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19671 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
19674 errdetail(
"Index \"%s\" is already attached to another index.",
19682 if (partDesc->
oids[
i] ==
state.partitionOid)
19690 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19691 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
19694 errdetail(
"Index \"%s\" is not an index on any partition of table \"%s\".",
19711 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19712 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
19715 errdetail(
"The index definitions do not match.")));
19730 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19731 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
19734 errdetail(
"The index \"%s\" belongs to a constraint in table \"%s\" but no constraint exists for index \"%s\".",
19772 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19773 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
19776 errdetail(
"Another index is already attached for partition \"%s\".",
19794 bool updated =
false;
19796 Assert(partedIdx->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX);
19818 elog(
ERROR,
"cache lookup failed for index %u", inhForm->inhrelid);
19820 if (indexForm->indisvalid)
19843 elog(
ERROR,
"cache lookup failed for index %u",
19847 indexForm->indisvalid =
true;
19860 if (updated && partedIdx->
rd_rel->relispartition)
19926 constraints =
lappend_oid(constraints, constrForm->oid);
19932 return constraints;
19948 foreach(cell, constraints)
19958 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
19994 if (compression == NULL || strcmp(compression,
"default") == 0)
20011 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20012 errmsg(
"column data type %s does not support compression",
20018 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20019 errmsg(
"invalid compression method \"%s\"", compression)));
20033 cstorage = TYPSTORAGE_PLAIN;
20035 cstorage = TYPSTORAGE_EXTERNAL;
20037 cstorage = TYPSTORAGE_EXTENDED;
20039 cstorage = TYPSTORAGE_MAIN;
20044 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20045 errmsg(
"invalid storage type \"%s\"",
20054 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20055 errmsg(
"column data type %s can only have storage PLAIN",
20140 bool isOldDefaultPart =
false;
20146 forboth(listptr, partlist, listptr2, newPartRels)
20155 defaultPartCtx = pc;
20159 List *partConstraint;
20165 (
Node *) partConstraint);
20176 pc->partqualstate =
20178 Assert(pc->partqualstate != NULL);
20182 partContexts =
lappend(partContexts, pc);
20189 if (!defaultPartCtx &&
OidIsValid(defaultPartOid))
20192 isOldDefaultPart =
true;
20223 bool found =
false;
20232 foreach(listptr, partContexts)
20236 if (pc->partqualstate &&
20237 ExecCheck(pc->partqualstate, econtext))
20247 if (defaultPartCtx)
20248 pc = defaultPartCtx;
20251 (
errcode(ERRCODE_CHECK_VIOLATION),
20252 errmsg(
"can not find partition for split partition row"),
20264 insertslot = pc->dstslot;
20278 ti_options, pc->bistate);
20297 foreach(listptr, partContexts)
20301 if (isOldDefaultPart)
20334 if (modelRel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
20337 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20338 errmsg(
"cannot create as partition of temporary relation of another session")));
20344 createStmt->
relation = newPartName;
20397 if (modelRel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
20398 newRel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
20400 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20401 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
20405 if (newRel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
20406 modelRel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
20408 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20409 errmsg(
"cannot create a permanent relation as partition of temporary relation \"%s\"",
20428 bool isSameName =
false;
20432 Oid defaultPartOid;
20447 Oid existing_relid;
20467 if (existing_relid == splitRelOid && !isSameName)
20472 (
errcode(ERRCODE_DUPLICATE_TABLE),
20510 newPartRels =
lappend(newPartRels, newPartRel);
20534 object.classId = RelationRelationId;
20535 object.objectId = splitRelOid;
20536 object.objectSubId = 0;
20568 foreach(listptr, mergingPartitionsList)
20606 insertslot = dstslot;
20620 ti_options, bistate);
20649 List *mergingPartitionsList =
NIL;
20650 Oid defaultPartOid;
20670 mergingPartitionsList =
lappend(mergingPartitionsList,
20694 Relation sameNamePartition = NULL;
20700 sameNamePartition = mergingPartition;
20705 if (sameNamePartition)
20723 tmpRelName,
false,
false);
20734 (
errcode(ERRCODE_DUPLICATE_TABLE),
20742 foreach(listptr, mergingPartitionsList)
20759 foreach(listptr, mergingPartitionsList)
20766 object.classId = RelationRelationId;
20767 object.objectSubId = 0;
Datum idx(PG_FUNCTION_ARGS)
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
void check_can_set_role(Oid member, Oid role)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Oid get_table_am_oid(const char *amname, bool missing_ok)
char * get_am_name(Oid amOid)
#define DatumGetArrayTypeP(X)
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
void free_attrmap(AttrMap *map)
AttrMap * make_attrmap(int maplen)
AttrMap * build_attrmap_by_name_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
#define InvalidAttrNumber
char * get_tablespace_name(Oid spc_oid)
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Oid GetDefaultTablespace(char relpersistence, bool partitioned)
List * roleSpecsToIds(List *memberNames)
List * raw_parser(const char *str, RawParseMode mode)
bool TimestampTimestampTzRequiresRewrite(void)
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_make_singleton(int x)
void FlushRelationBuffers(Relation rel)
#define TextDatumGetCString(d)
#define InvalidSubTransactionId
#define Assert(condition)
#define PointerIsValid(pointer)
#define MemSet(start, val, len)
#define OidIsValid(objectId)
bool IsToastNamespace(Oid namespaceId)
bool IsSystemRelation(Relation relation)
RelFileNumber GetNewRelFileNumber(Oid reltablespace, Relation pg_class, char relpersistence)
bool IsCatalogNamespace(Oid namespaceId)
bool IsSystemClass(Oid relid, Form_pg_class reltuple)
bool contain_mutable_functions(Node *clause)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
void check_index_is_clusterable(Relation OldHeap, Oid indexOid, LOCKMODE lockmode)
void finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, bool is_system_catalog, bool swap_toast_by_content, bool check_constraints, bool is_internal, TransactionId frozenXid, MultiXactId cutoffMulti, char newrelpersistence)
Oid make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, Oid NewAccessMethod, char relpersistence, LOCKMODE lockmode)
void mark_index_clustered(Relation rel, Oid indexOid, bool is_internal)
void ResetSequence(Oid seq_relid)
void SequenceChangePersistence(Oid relid, char newrelpersistence)
int32 defGetInt32(DefElem *def)
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
void free_object_addresses(ObjectAddresses *addrs)
#define PERFORM_DELETION_CONCURRENTLY
@ DEPENDENCY_PARTITION_PRI
@ DEPENDENCY_PARTITION_SEC
#define PERFORM_DELETION_QUIETLY
#define PERFORM_DELETION_INTERNAL
DestReceiver * None_Receiver
void hash_destroy(HTAB *hashp)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
void EventTriggerAlterTableStart(Node *parsetree)
void EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
void EventTriggerAlterTableRelid(Oid objectId)
void EventTriggerAlterTableEnd(void)
void EventTriggerCollectAlterTableSubcmd(Node *subcmd, ObjectAddress address)
#define AT_REWRITE_ALTER_PERSISTENCE
#define AT_REWRITE_DEFAULT_VAL
#define AT_REWRITE_ACCESS_METHOD
#define AT_REWRITE_COLUMN_REWRITE
ExprState * ExecPrepareExpr(Expr *node, EState *estate)
bool ExecCheck(ExprState *state, ExprContext *econtext)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, ResultRelInfo *partition_root_rri, int instrument_options)
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
HeapTuple ExecFetchSlotHeapTuple(TupleTableSlot *slot, bool materialize, bool *shouldFree)
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
EState * CreateExecutorState(void)
void FreeExecutorState(EState *estate)
struct ResultRelInfo ResultRelInfo
#define GetPerTupleExprContext(estate)
#define ResetExprContext(econtext)
#define GetPerTupleMemoryContext(estate)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
#define palloc0_object(type)
#define DirectFunctionCall2(func, arg1, arg2)
#define DatumGetByteaPP(X)
#define SizeForFunctionCallInfo(nargs)
#define LOCAL_FCINFO(name, nargs)
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
ForeignServer * GetForeignServer(Oid serverid)
Oid GetForeignServerIdByRelId(Oid relid)
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Datum transformGenericOptions(Oid catalogId, Datum oldOptions, List *options, Oid fdwvalidator)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
bool allowSystemTableMods
void RelationClearMissing(Relation rel)
void StorePartitionKey(Relation rel, char strategy, int16 partnatts, AttrNumber *partattrs, List *partexprs, Oid *partopclass, Oid *partcollation)
List * heap_truncate_find_FKs(List *relationIds)
void RemoveStatistics(Oid relid, AttrNumber attnum)
Oid heap_create_with_catalog(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, Oid reltypeid, Oid reloftypeid, Oid ownerid, Oid accessmtd, TupleDesc tupdesc, List *cooked_constraints, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, OnCommitAction oncommit, Datum reloptions, bool use_user_acl, bool allow_system_table_mods, bool is_internal, Oid relrewrite, ObjectAddress *typaddress)
void heap_truncate(List *relids)
void CheckAttributeType(const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, int flags)
void heap_truncate_check_FKs(List *relations, bool tempTables)
void StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
void InsertPgAttributeTuples(Relation pg_attribute_rel, TupleDesc tupdesc, Oid new_rel_oid, const FormExtraData_pg_attribute tupdesc_extra[], CatalogIndexState indstate)
void heap_truncate_one_rel(Relation rel)
List * AddRelationNewConstraints(Relation rel, List *newColDefaults, List *newConstraints, bool allow_merge, bool is_local, bool is_internal, const char *queryString)
#define CHKATYPE_IS_PARTKEY
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
BulkInsertState GetBulkInsertState(void)
void FreeBulkInsertState(BulkInsertState bistate)
#define XLOG_HEAP_TRUNCATE
#define XLH_TRUNCATE_RESTART_SEQS
#define SizeOfHeapTruncate
#define XLH_TRUNCATE_CASCADE
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
HeapTuple heap_copytuple(HeapTuple tuple)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
#define MaxHeapAttributeNumber
Oid IndexGetRelation(Oid indexId, bool missing_ok)
bool CompareIndexInfo(const IndexInfo *info1, const IndexInfo *info2, const Oid *collations1, const Oid *collations2, const Oid *opfamilies1, const Oid *opfamilies2, const AttrMap *attmap)
bool reindex_relation(const ReindexStmt *stmt, Oid relid, int flags, const ReindexParams *params)
void index_check_primary_key(Relation heapRel, const IndexInfo *indexInfo, bool is_alter_table, const IndexStmt *stmt)
ObjectAddress index_constraint_create(Relation heapRelation, Oid indexRelationId, Oid parentConstraintId, const IndexInfo *indexInfo, const char *constraintName, char constraintType, bits16 constr_flags, bool allow_system_table_mods, bool is_internal)
IndexInfo * BuildIndexInfo(Relation index)
#define REINDEX_REL_PROCESS_TOAST
#define INDEX_CONSTR_CREATE_UPDATE_INDEX
#define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS
#define INDEX_CONSTR_CREATE_DEFERRABLE
#define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY
#define INDEX_CONSTR_CREATE_INIT_DEFERRED
void index_close(Relation relation, LOCKMODE lockmode)
Relation index_open(Oid relationId, LOCKMODE lockmode)
bool CheckIndexCompatible(Oid oldId, const char *accessMethodName, const List *attributeList, const List *exclusionOpNames)
ObjectAddress DefineIndex(Oid tableId, IndexStmt *stmt, Oid indexRelationId, Oid parentIndexId, Oid parentConstraintId, int total_parts, bool is_alter_table, bool check_rights, bool check_not_in_use, bool skip_build, bool quiet)
void IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
Oid ResolveOpClass(const List *opclass, Oid attrType, const char *accessMethodName, Oid accessMethodId)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
void AcceptInvalidationMessages(void)
void CacheInvalidateRelcache(Relation relation)
void CacheInvalidateRelcacheByRelid(Oid relid)
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
if(TABLE==NULL||TABLE_index==NULL)
List * list_difference_ptr(const List *list1, const List *list2)
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
List * list_copy(const List *oldlist)
List * list_delete_nth_cell(List *list, int n)
void list_free(List *list)
bool list_member_oid(const List *list, Oid datum)
List * list_concat(List *list1, const List *list2)
List * lcons(void *datum, List *list)
List * list_append_unique_oid(List *list, Oid datum)
void list_free_deep(List *list)
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
bool CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode, bool orstronger)
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
#define AccessExclusiveLock
#define ShareRowExclusiveLock
#define ShareUpdateExclusiveLock
AttrNumber get_attnum(Oid relid, const char *attname)
Oid get_constraint_index(Oid conoid)
char * get_namespace_name(Oid nspid)
char get_typstorage(Oid typid)
bool get_index_isreplident(Oid index_oid)
char get_rel_relkind(Oid relid)
Oid get_typcollation(Oid typid)
char * get_rel_name(Oid relid)
bool get_index_isclustered(Oid index_oid)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
char * get_collation_name(Oid colloid)
char * get_constraint_name(Oid conoid)
Oid get_rel_relam(Oid relid)
bool type_is_collatable(Oid typid)
Oid get_rel_tablespace(Oid relid)
Oid get_typ_typrelid(Oid typid)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Oid getBaseType(Oid typid)
char get_constraint_type(Oid conoid)
Oid get_relname_relid(const char *relname, Oid relnamespace)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
#define TypeIsToastable(typid)
List * make_ands_implicit(Expr *clause)
TypeName * makeTypeNameFromNameList(List *names)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
ColumnDef * makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Expr * make_ands_explicit(List *andclauses)
void MemoryContextReset(MemoryContext context)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
char * MemoryContextStrdup(MemoryContext context, const char *string)
MemoryContext CacheMemoryContext
void MemoryContextDelete(MemoryContext context)
MemoryContext PortalContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define ALLOCSET_SMALL_SIZES
#define CHECK_FOR_INTERRUPTS()
bool InSecurityRestrictedOperation(void)
MultiXactId ReadNextMultiXactId(void)
void namestrcpy(Name name, const char *str)
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
bool isAnyTempNamespace(Oid namespaceId)
Oid get_collation_oid(List *collname, bool missing_ok)
void CheckSetNamespace(Oid oldNspOid, Oid nspOid)
RangeVar * makeRangeVarFromNameList(const List *names)
Oid LookupNamespaceNoError(const char *nspname)
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Oid exprType(const Node *expr)
Oid exprCollation(const Node *expr)
Node * strip_implicit_coercions(Node *node)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectTruncateHook(objectId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
#define InvokeObjectPostAlterHookArg(classId, objectId, subId, auxiliaryId, is_internal)
ObjectType get_relkind_objtype(char relkind)
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
char * nodeToString(const void *obj)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
CoercionPathType find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
@ COERCION_PATH_RELABELTYPE
void assign_expr_collations(ParseState *pstate, Node *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
int parser_errposition(ParseState *pstate, int location)
ParseState * make_parsestate(ParseState *parentParseState)
@ EXPR_KIND_PARTITION_EXPRESSION
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
const NameData * attnumAttName(Relation rd, int attid)
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
Oid attnumTypeId(Relation rd, int attid)
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
Type typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
Oid GetColumnDefCollation(ParseState *pstate, const ColumnDef *coldef, Oid typeOid)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
IndexStmt * generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx, const AttrMap *attmap, Oid *constraintOid)
CreateStatsStmt * transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
AlterTableStmt * transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, const char *queryString, List **beforeStmts, List **afterStmts)
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
PartitionBoundSpec * transformPartitionBound(ParseState *pstate, Relation parent, PartitionBoundSpec *spec)
#define FKCONSTR_ACTION_RESTRICT
#define FKCONSTR_ACTION_SETDEFAULT
@ PARTITION_STRATEGY_HASH
@ PARTITION_STRATEGY_LIST
@ AT_DetachPartitionFinalize
@ AT_ReAddDomainConstraint
@ AT_AlterColumnGenericOptions
#define FKCONSTR_ACTION_CASCADE
#define FKCONSTR_ACTION_SETNULL
@ CREATE_TABLE_LIKE_IDENTITY
@ CREATE_TABLE_LIKE_INDEXES
@ CREATE_TABLE_LIKE_STATISTICS
#define FKCONSTR_ACTION_NOACTION
List * SystemFuncName(char *name)
void check_new_partition_bound(char *relname, Relation parent, PartitionBoundSpec *spec, ParseState *pstate)
List * get_qual_from_partbound(Relation parent, PartitionBoundSpec *spec)
void check_default_partition_contents(Relation parent, Relation default_rel, PartitionBoundSpec *new_spec)
List * RelationGetPartitionQual(Relation rel)
PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached)
Oid get_default_oid_from_partdesc(PartitionDesc partdesc)
bool has_partition_attrs(Relation rel, Bitmapset *attnums, bool *used_in_expr)
List * map_partition_varattnos(List *expr, int fromrel_varno, Relation to_rel, Relation from_rel)
List * get_proposed_default_constraint(List *new_part_constraints)
void update_default_partition_oid(Oid parentId, Oid defaultPartId)
Oid index_get_partition(Relation partition, Oid indexId)
Oid get_partition_parent(Oid relid, bool even_if_detached)
Oid GetAttrDefaultOid(Oid relid, AttrNumber attnum)
Oid StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr, bool is_internal, bool add_column_mode)
ObjectAddress GetAttrDefaultColumnAddress(Oid attrdefoid)
void RemoveAttrDefault(Oid relid, AttrNumber attnum, DropBehavior behavior, bool complain, bool internal)
FormData_pg_attribute * Form_pg_attribute
int errdetail_relkind_not_supported(char relkind)
FormData_pg_class * Form_pg_class
#define PARTITION_MAX_KEYS
char * ChooseConstraintName(const char *name1, const char *name2, const char *label, Oid namespaceid, List *others)
bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)
void RenameConstraintById(Oid conId, const char *newname)
Oid get_relation_idx_constraint_oid(Oid relationId, Oid indexId)
void ConstraintSetParentConstraint(Oid childConstrId, Oid parentConstrId, Oid childTableId)
void DeconstructFkConstraintRow(HeapTuple tuple, int *numfks, AttrNumber *conkey, AttrNumber *confkey, Oid *pf_eq_oprs, Oid *pp_eq_oprs, Oid *ff_eq_oprs, int *num_fk_del_set_cols, AttrNumber *fk_del_set_cols)
void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, Oid newNspId, bool isType, ObjectAddresses *objsMoved)
Oid CreateConstraintEntry(const char *constraintName, Oid constraintNamespace, char constraintType, bool isDeferrable, bool isDeferred, bool isValidated, Oid parentConstrId, Oid relId, const int16 *constraintKey, int constraintNKeys, int constraintNTotalKeys, Oid domainId, Oid indexRelId, Oid foreignRelId, const int16 *foreignKey, const Oid *pfEqOp, const Oid *ppEqOp, const Oid *ffEqOp, int foreignNKeys, char foreignUpdateType, char foreignDeleteType, const int16 *fkDeleteSetCols, int numFkDeleteSetCols, char foreignMatchType, const Oid *exclOp, Node *conExpr, const char *conBin, bool conIsLocal, int conInhCount, bool conNoInherit, bool is_internal)
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
FormData_pg_constraint * Form_pg_constraint
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
Oid getIdentitySequence(Relation rel, AttrNumber attnum, bool missing_ok)
Oid get_index_constraint(Oid indexId)
List * getOwnedSequences(Oid relid)
bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId)
FormData_pg_depend * Form_pg_depend
FormData_pg_foreign_table * Form_pg_foreign_table
FormData_pg_index * Form_pg_index
bool DeleteInheritsTuple(Oid inhrelid, Oid inhparent, bool expect_detach_pending, const char *childname)
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
void StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)
List * find_inheritance_children(Oid parentrelId, LOCKMODE lockmode)
bool has_superclass(Oid relationId)
bool PartitionHasPendingDetach(Oid partoid)
FormData_pg_inherits * Form_pg_inherits
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
#define foreach_current_index(var_or_cell)
#define foreach_delete_current(lst, var_or_cell)
#define list_make1_oid(x1)
#define foreach_ptr(type, var, lst)
static ListCell * list_head(const List *l)
#define for_each_from(cell, lst, N)
#define list_make3(x1, x2, x3)
static void * list_nth(const List *list, int n)
#define foreach_oid(var, lst)
#define list_nth_node(type, list, n)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make2(x1, x2)
FormData_pg_opclass * Form_pg_opclass
List * GetRelationPublications(Oid relid)
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
void changeDependencyOnTablespace(Oid classId, Oid objectId, Oid newTablespaceId)
FormData_pg_trigger * Form_pg_trigger
void RenameTypeInternal(Oid typeOid, const char *newTypeName, Oid typeNamespace)
FormData_pg_type * Form_pg_type
#define ERRCODE_UNDEFINED_TABLE
void pgstat_count_truncate(Relation rel)
Expr * expression_planner(Expr *expr)
int pg_strcasecmp(const char *s1, const char *s2)
size_t strlcpy(char *dst, const char *src, size_t siz)
void check_stack_depth(void)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static Datum CharGetDatum(char X)
void CheckTableForSerializableConflictIn(Relation relation)
void TransferPredicateLocksToHeapRelation(Relation relation)
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Expr * canonicalize_qual(Expr *qual, bool is_check)
MemoryContextSwitchTo(old_ctx)
void * stringToNode(const char *str)
#define RelationGetForm(relation)
#define RelationGetRelid(relation)
#define RelationIsLogicallyLogged(relation)
#define RelationIsUsedAsCatalogTable(relation)
static SMgrRelation RelationGetSmgr(Relation rel)
#define RelationGetDescr(relation)
#define RelationIsMapped(relation)
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
#define RELATION_IS_OTHER_TEMP(relation)
#define RelationGetNamespace(relation)
#define IndexRelationGetNumberOfKeyAttributes(relation)
#define RelationIsPermanent(relation)
List * RelationGetIndexList(Relation relation)
int errtableconstraint(Relation rel, const char *conname)
int errtablecol(Relation rel, int attnum)
List * RelationGetIndexPredicate(Relation relation)
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
List * RelationGetFKeyList(Relation relation)
void RelationSetNewRelfilenumber(Relation relation, char persistence)
void RelationAssumeNewRelfilelocator(Relation relation)
int errtable(Relation rel)
List * RelationGetIndexExpressions(Relation relation)
struct RelationData * Relation
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
List * untransformRelOptions(Datum options)
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
bytea * view_reloptions(Datum reloptions, bool validate)
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
LOCKMODE AlterTableGetRelOptionsLockLevel(List *defList)
bytea * attribute_reloptions(Datum reloptions, bool validate)
#define HEAP_RELOPT_NAMESPACES
#define RelFileNumberIsValid(relnumber)
void EnableDisableRule(Relation rel, const char *rulename, char fires_when)
#define RULE_FIRES_ON_ORIGIN
#define RULE_FIRES_ON_REPLICA
#define RULE_FIRES_ALWAYS
const char * view_query_is_auto_updatable(Query *viewquery, bool check_cols)
Query * get_view_query(Relation view)
Node * build_column_default(Relation rel, int attrno)
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
Datum RI_FKey_check_ins(PG_FUNCTION_ARGS)
bool RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
void RI_PartitionRemove_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
int RI_FKey_trigger_type(Oid tgfoid)
char * pg_get_constraintdef_command(Oid constraintId)
const char * quote_identifier(const char *ident)
char * pg_get_statisticsobjdef_string(Oid statextid)
Datum pg_get_expr(PG_FUNCTION_ARGS)
char * pg_get_indexdef_string(Oid indexrelid)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
void smgrclose(SMgrRelation reln)
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Snapshot GetTransactionSnapshot(void)
Snapshot GetLatestSnapshot(void)
void UnregisterSnapshot(Snapshot snapshot)
void PushActiveSnapshot(Snapshot snapshot)
Snapshot RegisterSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
Snapshot GetActiveSnapshot(void)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation try_relation_open(Oid relationId, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
ObjectAddress CreateStatistics(CreateStatsStmt *stmt)
Oid StatisticsGetRelation(Oid statId, bool missing_ok)
void RelationPreserveStorage(RelFileLocator rlocator, bool atCommit)
void RelationCopyStorage(SMgrRelation src, SMgrRelation dst, ForkNumber forkNum, char relpersistence)
SMgrRelation RelationCreateStorage(RelFileLocator rlocator, char relpersistence, bool register_delete)
void log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum)
void RelationDropStorage(Relation rel)
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
List * changedConstraintDefs
Expr * partition_constraint
List * changedStatisticsDefs
char * replicaIdentityIndex
List * changedStatisticsOids
List * changedConstraintOids
List * subcmds[AT_NUM_PASSES]
RangeVar * identitySequence
bool reset_default_tblspc
char actual_relpersistence
List * es_opened_result_relations
TupleTableSlot * ecxt_scantuple
ExecForeignTruncate_function ExecForeignTruncate
amoptions_function amoptions
bool reset_default_tblspc
NullTestType nulltesttype
SubTransactionId creating_subid
SubTransactionId deleting_subid
const char * p_sourcetext
PartitionBoundSpec * bound
PartitionStrategy strategy
struct IndexAmRoutine * rd_indam
SubTransactionId rd_firstRelfilelocatorSubid
SubTransactionId rd_newRelfilelocatorSubid
SubTransactionId rd_createSubid
RelFileLocator rd_locator
PartitionBoundSpec * bound
ExprState * partqualstate
TupleTableSlot * tg_trigslot
const char * skipping_msg
const char * nonexistent_msg
const char * drophint_msg
Oid values[FLEXIBLE_ARRAY_MEMBER]
#define FirstLowInvalidHeapAttributeNumber
HeapTuple SearchSysCacheCopyAttName(Oid relid, const char *attname)
HeapTuple SearchSysCacheCopyAttNum(Oid relid, int16 attnum)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
HeapTuple SearchSysCacheAttNum(Oid relid, int16 attnum)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
bool SearchSysCacheExistsAttName(Oid relid, const char *attname)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
#define SearchSysCacheCopy1(cacheId, key1)
#define SearchSysCacheExists2(cacheId, key1, key2)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
char * default_table_access_method
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
static void table_endscan(TableScanDesc scan)
#define TABLE_INSERT_SKIP_FSM
static void table_finish_bulk_insert(Relation rel, int options)
static void table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
static void table_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
static AttrNumber renameatt_internal(Oid myrelid, const char *oldattname, const char *newattname, bool recurse, bool recursing, int expected_parents, DropBehavior behavior)
void ResetRelRewrite(Oid myrelid)
static void MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel, bool ispartition)
static ObjectAddress ATExecSetNotNull(AlteredTableInfo *tab, Relation rel, const char *colName, LOCKMODE lockmode)
static void MarkInheritDetached(Relation child_rel, Relation parent_rel)
static ObjectAddress ATExecAlterColumnGenericOptions(Relation rel, const char *colName, List *options, LOCKMODE lockmode)
static void ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode, AlterTableUtilityContext *context)
static ObjectAddress ATExecAddInherit(Relation child_rel, RangeVar *parent, LOCKMODE lockmode)
ObjectAddress RenameRelation(RenameStmt *stmt)
static AlteredTableInfo * ATGetQueueEntry(List **wqueue, Relation rel)
static void ATExecDropOf(Relation rel, LOCKMODE lockmode)
static ColumnDef * MergeInheritedAttribute(List *inh_columns, int exist_attno, const ColumnDef *newdef)
static bool ConstraintImpliedByRelConstraint(Relation scanrel, List *testConstraint, List *provenConstraint)
static const char * storage_name(char c)
static ObjectAddress ATExecDropExpression(Relation rel, const char *colName, bool missing_ok, LOCKMODE lockmode)
void AtEOSubXact_on_commit_actions(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid)
static void add_column_datatype_dependency(Oid relid, int32 attnum, Oid typid)
static ObjectAddress ATExecColumnDefault(Relation rel, const char *colName, Node *newDefault, LOCKMODE lockmode)
static void ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd, List **wqueue, LOCKMODE lockmode, bool rewrite)
static void ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode)
static void drop_parent_dependency(Oid relid, Oid refclassid, Oid refobjid, DependencyType deptype)
static void RemoveInheritance(Relation child_rel, Relation parent_rel, bool expect_detached)
void PreCommit_on_commit_actions(void)
static int transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, List **attnamelist, int16 *attnums, Oid *atttypids, Oid *opclasses)
struct SplitPartitionContext SplitPartitionContext
static void ATExecDropConstraint(Relation rel, const char *constrName, DropBehavior behavior, bool recurse, bool recursing, bool missing_ok, LOCKMODE lockmode)
static ObjectAddress ATExecDropIdentity(Relation rel, const char *colName, bool missing_ok, LOCKMODE lockmode, bool recurse, bool recursing)
static char GetAttributeCompression(Oid atttypid, const char *compression)
static ObjectAddress ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
static int findAttrByName(const char *attributeName, const List *columns)
static void RememberIndexForRebuilding(Oid indoid, AlteredTableInfo *tab)
static bool ATColumnChangeRequiresRewrite(Node *expr, AttrNumber varattno)
static char * ChooseForeignKeyConstraintNameAddition(List *colnames)
static ObjectAddress ATExecValidateConstraint(List **wqueue, Relation rel, char *constrName, bool recurse, bool recursing, LOCKMODE lockmode)
void AlterTable(AlterTableStmt *stmt, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void RememberStatisticsForRebuilding(Oid stxoid, AlteredTableInfo *tab)
static CoercionPathType findFkeyCast(Oid targetTypeId, Oid sourceTypeId, Oid *funcid)
static void add_column_collation_dependency(Oid relid, int32 attnum, Oid collid)
void RemoveRelations(DropStmt *drop)
static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacename, LOCKMODE lockmode)
static void ATTypedTableRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void RememberReplicaIdentityForRebuilding(Oid indoid, AlteredTableInfo *tab)
static List * MergeAttributes(List *columns, const List *supers, char relpersistence, bool is_partition, List **supconstr)
static List * GetParentedForeignKeyRefs(Relation partition)
void AlterRelationNamespaceInternal(Relation classRel, Oid relOid, Oid oldNspOid, Oid newNspOid, bool hasDependEntry, ObjectAddresses *objsMoved)
static ObjectAddress ATExecAddConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *newConstraint, bool recurse, bool is_readd, LOCKMODE lockmode)
ObjectAddress renameatt(RenameStmt *stmt)
void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lockmode)
static void RangeVarCallbackForAlterRelation(const RangeVar *rv, Oid relid, Oid oldrelid, void *arg)
static void CheckAlterTableIsSafe(Relation rel)
static void DropErrorMsgWrongType(const char *relname, char wrongkind, char rightkind)
LOCKMODE AlterTableGetLockLevel(List *cmds)
static int transformColumnNameList(Oid relId, List *colList, int16 *attnums, Oid *atttypids)
static void validateForeignKeyConstraint(char *conname, Relation rel, Relation pkrel, Oid pkindOid, Oid constraintOid)
struct ForeignTruncateInfo ForeignTruncateInfo
static ObjectAddress ATExecDetachPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, RangeVar *name, bool concurrent)
static bool ATExecAlterConstrRecurse(Constraint *cmdcon, Relation conrel, Relation tgrel, Relation rel, HeapTuple contuple, List **otherrelids, LOCKMODE lockmode)
static void AlterSeqNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved, LOCKMODE lockmode)
static void RangeVarCallbackForRenameAttribute(const RangeVar *rv, Oid relid, Oid oldrelid, void *arg)
TupleDesc BuildDescForRelation(const List *columns)
static void attachPartitionTable(List **wqueue, Relation rel, Relation attachrel, PartitionBoundSpec *bound)
static void ATExecForceNoForceRowSecurity(Relation rel, bool force_rls)
void AtEOXact_on_commit_actions(bool isCommit)
static void checkFkeyPermissions(Relation rel, int16 *attnums, int natts)
struct OnCommitItem OnCommitItem
void CheckTableNotInUse(Relation rel, const char *stmt)
static void moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPartRels, Oid defaultPartOid)
static void ATExecEnableDisableTrigger(Relation rel, const char *trigname, char fires_when, bool skip_system, bool recurse, LOCKMODE lockmode)
static void createForeignKeyActionTriggers(Relation rel, Oid refRelOid, Constraint *fkconstraint, Oid constraintOid, Oid indexOid, Oid parentDelTrigger, Oid parentUpdTrigger, Oid *deleteTrigOid, Oid *updateTrigOid)
static void renameatt_check(Oid myrelid, Form_pg_class classform, bool recursing)
static void RangeVarCallbackForAttachIndex(const RangeVar *rv, Oid relOid, Oid oldRelOid, void *arg)
static void ATCheckPartitionsNotInUse(Relation rel, LOCKMODE lockmode)
static void truncate_check_activity(Relation rel)
static void validatePartitionedIndex(Relation partedIdx, Relation partedTbl)
static ObjectAddress ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *fkconstraint, bool recurse, bool recursing, LOCKMODE lockmode)
static void TryReuseIndex(Oid oldId, IndexStmt *stmt)
static void GetForeignKeyCheckTriggers(Relation trigrel, Oid conoid, Oid confrelid, Oid conrelid, Oid *insertTriggerOid, Oid *updateTriggerOid)
static void ATPrepSetNotNull(List **wqueue, Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void RememberClusterOnForRebuilding(Oid indoid, AlteredTableInfo *tab)
static ObjectAddress ATExecSetOptions(Relation rel, const char *colName, Node *options, bool isReset, LOCKMODE lockmode)
static ObjectAddress ATExecDropColumn(List **wqueue, Relation rel, const char *colName, DropBehavior behavior, bool recurse, bool recursing, bool missing_ok, LOCKMODE lockmode, ObjectAddresses *addrs)
static void CloneFkReferencing(List **wqueue, Relation parentRel, Relation partRel)
static void ATPrepDropNotNull(Relation rel, bool recurse, bool recursing)
static void SetIndexStorageProperties(Relation rel, Relation attrelation, AttrNumber attnum, bool setstorage, char newstorage, bool setcompression, char newcompression, LOCKMODE lockmode)
static void ATController(AlterTableStmt *parsetree, Relation rel, List *cmds, bool recurse, LOCKMODE lockmode, AlterTableUtilityContext *context)
bool CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId)
static void ATExecSetRowSecurity(Relation rel, bool rls)
static void ATExecCheckNotNull(AlteredTableInfo *tab, Relation rel, const char *colName, LOCKMODE lockmode)
static Oid transformFkeyCheckAttrs(Relation pkrel, int numattrs, int16 *attnums, Oid *opclasses)
void find_composite_type_dependencies(Oid typeOid, Relation origRelation, const char *origTypeName)
static void truncate_check_perms(Oid relid, Form_pg_class reltuple)
static void truncate_check_rel(Oid relid, Form_pg_class reltuple)
static void change_owner_recurse_to_sequences(Oid relationOid, Oid newOwnerId, LOCKMODE lockmode)
static void StoreCatalogInheritance1(Oid relationId, Oid parentOid, int32 seqNumber, Relation inhRelation, bool child_is_partition)
static void RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, Relation rel, AttrNumber attnum, const char *colName)
static void ATPrepDropExpression(Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode)
static ObjectAddress ATExecCookedColumnDefault(Relation rel, AttrNumber attnum, Node *newDefault)
static void moveMergedTablesRows(Relation rel, List *mergingPartitionsList, Relation newPartRel)
static ObjectAddress rename_constraint_internal(Oid myrelid, Oid mytypid, const char *oldconname, const char *newconname, bool recurse, bool recursing, int expected_parents)
static void DropErrorMsgNonExistent(RangeVar *rel, char rightkind, bool missing_ok)
static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab, LOCKMODE lockmode)
static bool tryAttachPartitionForeignKey(ForeignKeyCacheInfo *fk, Oid partRelid, Oid parentConstrOid, int numfks, AttrNumber *mapped_conkey, AttrNumber *confkey, Oid *conpfeqop, Oid parentInsTrigger, Oid parentUpdTrigger, Relation trigrel)
static void ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel, PartitionCmd *cmd, AlterTableUtilityContext *context)
static AlterTableCmd * ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses *objsMoved)
static void CloneFkReferenced(Relation parentRel, Relation partitionRel)
static void MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel)
static void ATPrepDropColumn(List **wqueue, Relation rel, bool recurse, bool recursing, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
void SetRelationHasSubclass(Oid relationId, bool relhassubclass)
static void MergeChildAttribute(List *inh_columns, int exist_attno, int newcol_attno, const ColumnDef *newdef)
static void ATSimplePermissions(AlterTableType cmdtype, Relation rel, int allowed_targets)
static List * MergeCheckConstraint(List *constraints, const char *name, Node *expr)
static void ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation, LOCKMODE lockmode)
static ObjectAddress ATExecSetIdentity(Relation rel, const char *colName, Node *def, LOCKMODE lockmode, bool recurse, bool recursing)
ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
static void RememberConstraintForRebuilding(Oid conoid, AlteredTableInfo *tab)
void ExecuteTruncate(TruncateStmt *stmt)
static bool ATPrepChangePersistence(Relation rel, bool toLogged)
static void relation_mark_replica_identity(Relation rel, char ri_type, Oid indexOid, bool is_internal)
#define ATT_FOREIGN_TABLE
static ObjectAddress ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode)
static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing, bool is_view, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNumber *partattrs, List **partexprs, Oid *partopclass, Oid *partcollation, PartitionStrategy strategy)
static void CloneRowTriggersToPartition(Relation parent, Relation partition)
static void AttachPartitionEnsureIndexes(List **wqueue, Relation rel, Relation attachrel)
static void StoreCatalogInheritance(Oid relationId, List *supers, bool child_is_partition)
static ObjectAddress ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *constr, bool recurse, bool recursing, bool is_readd, LOCKMODE lockmode)
static void ATExecGenericOptions(Relation rel, List *options)
static void TryReuseForeignKey(Oid oldId, Constraint *con)
struct AlteredTableInfo AlteredTableInfo
static void validateFkOnDeleteSetColumns(int numfks, const int16 *fkattnums, int numfksetcols, const int16 *fksetcolsattnums, List *fksetcols)
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
struct NewConstraint NewConstraint
static ObjectAddress ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newValue, LOCKMODE lockmode)
static void ATSimpleRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void DetachPartitionFinalize(Relation rel, Relation partRel, bool concurrent, Oid defaultPartOid)
static Relation createPartitionTable(RangeVar *newPartName, Relation modelRel, AlterTableUtilityContext *context)
static void RebuildConstraintComment(AlteredTableInfo *tab, AlterTablePass pass, Oid objid, Relation rel, List *domname, const char *conname)
static void CloneForeignKeyConstraints(List **wqueue, Relation parentRel, Relation partitionRel)
static bool check_for_column_name_collision(Relation rel, const char *colname, bool if_not_exists)
static ObjectAddress ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, AlterTableCmd **cmd, bool recurse, bool recursing, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
@ AT_PASS_ADD_OTHERCONSTR
@ AT_PASS_ADD_INDEXCONSTR
static ObjectAddress ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd, LOCKMODE lockmode)
void SetRelationTableSpace(Relation rel, Oid newTableSpaceId, RelFileNumber newRelFilenumber)
void remove_on_commit_action(Oid relid)
static void DetachAddConstraintIfNeeded(List **wqueue, Relation partRel)
static void ATExecDropCluster(Relation rel, LOCKMODE lockmode)
#define ATT_PARTITIONED_INDEX
static void CreateInheritance(Relation child_rel, Relation parent_rel, bool ispartition)
static void addFkRecurseReferencing(List **wqueue, Constraint *fkconstraint, Relation rel, Relation pkrel, Oid indexOid, Oid parentConstr, int numfks, int16 *pkattnum, int16 *fkattnum, Oid *pfeqoperators, Oid *ppeqoperators, Oid *ffeqoperators, int numfkdelsetcols, int16 *fkdelsetcols, bool old_check_ok, LOCKMODE lockmode, Oid parentInsTrigger, Oid parentUpdTrigger)
static const struct dropmsgstrings dropmsgstringarray[]
static ObjectAddress ATExecSetExpression(AlteredTableInfo *tab, Relation rel, const char *colName, Node *newExpr, LOCKMODE lockmode)
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
static Oid CreateFKCheckTrigger(Oid myRelOid, Oid refRelOid, Constraint *fkconstraint, Oid constraintOid, Oid indexOid, Oid parentTrigOid, bool on_insert)
static SplitPartitionContext * createSplitPartitionContext(Relation partRel)
static void DropClonedTriggersFromPartition(Oid partitionId)
static void QueuePartitionConstraintValidation(List **wqueue, Relation scanrel, List *partConstraint, bool validate_default)
static ObjectAddress ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode)
static void RangeVarCallbackForDropRelation(const RangeVar *rel, Oid relOid, Oid oldRelOid, void *arg)
void AlterTableInternal(Oid relid, List *cmds, bool recurse)
static void GetForeignKeyActionTriggers(Relation trigrel, Oid conoid, Oid confrelid, Oid conrelid, Oid *deleteTriggerOid, Oid *updateTriggerOid)
void check_of_type(HeapTuple typetuple)
static ObjectAddress ATExecDropInherit(Relation rel, RangeVar *parent, LOCKMODE lockmode)
static void ATDetachCheckNoForeignKeyRefs(Relation partition)
static ObjectAddress ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel, IndexStmt *stmt, LOCKMODE lockmode)
static void AlterIndexNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved)
static char * decompile_conbin(HeapTuple contup, TupleDesc tupdesc)
static void ATExecCmd(List **wqueue, AlteredTableInfo *tab, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
static void ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode)
static void createForeignKeyCheckTriggers(Oid myRelOid, Oid refRelOid, Constraint *fkconstraint, Oid constraintOid, Oid indexOid, Oid parentInsTrigger, Oid parentUpdTrigger, Oid *insertTrigOid, Oid *updateTrigOid)
static void ATPrepAddInherit(Relation child_rel)
static ObjectAddress ATExecDetachPartitionFinalize(Relation rel, RangeVar *name)
static ObjectAddress ATExecSetStorage(Relation rel, const char *colName, Node *newValue, LOCKMODE lockmode)
static ObjectAddress ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd, AlterTableUtilityContext *context)
static List * find_typed_table_dependencies(Oid typeOid, const char *typeName, DropBehavior behavior)
Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
static ObjectAddress ATExecAddIdentity(Relation rel, const char *colName, Node *def, LOCKMODE lockmode, bool recurse, bool recursing)
static void ATExecSetAccessMethodNoStorage(Relation rel, Oid newAccessMethodId)
static ObjectAddress ATExecAddIndex(AlteredTableInfo *tab, Relation rel, IndexStmt *stmt, bool is_rebuild, LOCKMODE lockmode)
static ObjectAddress ATExecSetCompression(Relation rel, const char *column, Node *newValue, LOCKMODE lockmode)
static PartitionSpec * transformPartitionSpec(Relation rel, PartitionSpec *partspec)
static void ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
static void index_copy_data(Relation rel, RelFileLocator newrlocator)
void RenameRelationInternal(Oid myrelid, const char *newrelname, bool is_internal, bool is_index)
static void ATExecSetTableSpaceNoStorage(Relation rel, Oid newTableSpace)
static void ATPrepAlterColumnType(List **wqueue, AlteredTableInfo *tab, Relation rel, bool recurse, bool recursing, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
static void change_owner_fix_column_acls(Oid relationOid, Oid oldOwnerId, Oid newOwnerId)
#define ATT_COMPOSITE_TYPE
static ObjectAddress ATExecAttachPartitionIdx(List **wqueue, Relation parentIdx, RangeVar *name)
bool PartConstraintImpliedByRelConstraint(Relation scanrel, List *partConstraint)
void RangeVarCallbackMaintainsTable(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
static void ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, PartitionCmd *cmd, AlterTableUtilityContext *context)
static const char * alter_table_type_to_string(AlterTableType cmdtype)
static ObjectAddress addFkRecurseReferenced(List **wqueue, Constraint *fkconstraint, Relation rel, Relation pkrel, Oid indexOid, Oid parentConstr, int numfks, int16 *pkattnum, int16 *fkattnum, Oid *pfeqoperators, Oid *ppeqoperators, Oid *ffeqoperators, int numfkdelsetcols, int16 *fkdelsetcols, bool old_check_ok, Oid parentDelTrigger, Oid parentUpdTrigger)
static bool constraints_equivalent(HeapTuple a, HeapTuple b, TupleDesc tupleDesc)
static ObjectAddress ATExecAddStatistics(AlteredTableInfo *tab, Relation rel, CreateStatsStmt *stmt, bool is_rebuild, LOCKMODE lockmode)
ObjectAddress RenameConstraint(RenameStmt *stmt)
static void ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode, AlterTableUtilityContext *context)
void register_on_commit_action(Oid relid, OnCommitAction action)
static void RangeVarCallbackForTruncate(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
static ObjectAddress ATExecClusterOn(Relation rel, const char *indexName, LOCKMODE lockmode)
static char GetAttributeStorage(Oid atttypid, const char *storagemode)
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
#define child_dependency_type(child_is_partition)
static void refuseDupeIndexAttach(Relation parentIdx, Relation partIdx, Relation partitionTbl)
void ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged, DropBehavior behavior, bool restart_seqs, bool run_as_table_owner)
static void ATExecEnableDisableRule(Relation rel, const char *rulename, char fires_when, LOCKMODE lockmode)
struct NewColumnValue NewColumnValue
static void ATPrepSetAccessMethod(AlteredTableInfo *tab, Relation rel, const char *amname)
static bool NotNullImpliedByRelConstraints(Relation rel, Form_pg_attribute attr)
const char * GetCompressionMethodName(char method)
char CompressionNameToMethod(const char *compression)
#define CompressionMethodIsValid(cm)
#define InvalidCompressionMethod
void AlterTableCreateToastTable(Oid relOid, Datum reloptions, LOCKMODE lockmode)
void ExecBSTruncateTriggers(EState *estate, ResultRelInfo *relinfo)
void EnableDisableTrigger(Relation rel, const char *tgname, Oid tgparent, char fires_when, bool skip_system, bool recurse, LOCKMODE lockmode)
void ExecASTruncateTriggers(EState *estate, ResultRelInfo *relinfo)
const char * FindTriggerIncompatibleWithInheritance(TriggerDesc *trigdesc)
ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition)
void TriggerSetParentTrigger(Relation trigRel, Oid childTrigId, Oid parentTrigId, Oid childTableId)
ObjectAddress CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition, char trigger_fires_when)
bool AfterTriggerPendingOnRel(Oid relid)
void AfterTriggerEndQuery(EState *estate)
void AfterTriggerBeginQuery(void)
#define TRIGGER_FIRES_ON_ORIGIN
#define TRIGGER_FIRES_ON_REPLICA
#define TRIGGER_EVENT_ROW
#define TRIGGER_FIRES_ALWAYS
#define TRIGGER_EVENT_INSERT
TupleTableSlot * execute_attr_map_slot(AttrMap *attrMap, TupleTableSlot *in_slot, TupleTableSlot *out_slot)
void free_conversion_map(TupleConversionMap *map)
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc)
TupleDesc CreateTemplateTupleDesc(int natts)
Node * TupleDescGetDefault(TupleDesc tupdesc, AttrNumber attnum)
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
#define ReleaseTupleDesc(tupdesc)
#define TupleDescAttr(tupdesc, i)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
static void slot_getallattrs(TupleTableSlot *slot)
static bool slot_attisnull(TupleTableSlot *slot, int attnum)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
bool DomainHasConstraints(Oid type_id)
void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId)
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
void checkDomainOwner(HeapTuple tup)
Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid, bool isImplicitArray, bool ignoreDependent, bool errorOnTableType, ObjectAddresses *objsMoved)
void SwitchToUntrustedUser(Oid userid, UserContext *context)
void RestoreUserContext(UserContext *context)
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
void ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
@ PROCESS_UTILITY_SUBCOMMAND
#define MAX_STATISTICS_TARGET
String * makeString(char *str)
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
SubTransactionId GetCurrentSubTransactionId(void)
void CommandCounterIncrement(void)
void StartTransactionCommand(void)
void CommitTransactionCommand(void)
CommandId GetCurrentCommandId(bool used)
#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE
#define XLogLogicalInfoActive()
#define XLOG_INCLUDE_ORIGIN
void XLogRegisterData(char *data, uint32 len)
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void XLogSetRecordFlags(uint8 flags)
void XLogBeginInsert(void)