93 #include "utils/fmgroids.h"
160 #define AT_NUM_PASSES (AT_PASS_MISC + 1)
256 gettext_noop(
"sequence \"%s\" does not exist, skipping"),
258 gettext_noop(
"Use DROP SEQUENCE to remove a sequence.")},
267 gettext_noop(
"materialized view \"%s\" does not exist"),
268 gettext_noop(
"materialized view \"%s\" does not exist, skipping"),
270 gettext_noop(
"Use DROP MATERIALIZED VIEW to remove a materialized view.")},
272 ERRCODE_UNDEFINED_OBJECT,
277 {RELKIND_COMPOSITE_TYPE,
278 ERRCODE_UNDEFINED_OBJECT,
283 {RELKIND_FOREIGN_TABLE,
284 ERRCODE_UNDEFINED_OBJECT,
286 gettext_noop(
"foreign table \"%s\" does not exist, skipping"),
288 gettext_noop(
"Use DROP FOREIGN TABLE to remove a foreign table.")},
289 {RELKIND_PARTITIONED_TABLE,
295 {RELKIND_PARTITIONED_INDEX,
296 ERRCODE_UNDEFINED_OBJECT,
301 {
'\0', 0, NULL, NULL, NULL, NULL}
319 #define ATT_TABLE 0x0001
320 #define ATT_VIEW 0x0002
321 #define ATT_MATVIEW 0x0004
322 #define ATT_INDEX 0x0008
323 #define ATT_COMPOSITE_TYPE 0x0010
324 #define ATT_FOREIGN_TABLE 0x0020
325 #define ATT_PARTITIONED_INDEX 0x0040
326 #define ATT_SEQUENCE 0x0080
347 #define child_dependency_type(child_is_partition) \
348 ((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
356 bool is_partition,
List **supconstr,
364 bool child_is_partition);
367 bool child_is_partition);
375 bool recurse,
bool recursing,
LOCKMODE lockmode);
381 bool recurse,
bool recursing,
LOCKMODE lockmode);
389 int numattrs,
int16 *attnums,
396 Oid pkindOid,
Oid constraintOid);
401 bool recurse,
bool recursing,
LOCKMODE lockmode,
433 bool recurse,
bool recursing,
445 char *constrname,
char *colName,
446 bool recurse,
bool recursing,
449 const char *colName,
LOCKMODE lockmode);
452 List *testConstraint,
List *provenConstraint);
458 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
460 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
462 bool recurse,
bool recursing);
478 bool recurse,
bool recursing,
489 Constraint *newConstraint,
bool recurse,
bool is_readd,
497 bool recurse,
bool recursing,
bool is_readd,
501 bool recurse,
bool recursing,
506 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
507 int numfkdelsetcols,
int16 *fkdelsetcols,
509 Oid parentDelTrigger,
Oid parentUpdTrigger);
511 int numfksetcols,
const int16 *fksetcolsattnums,
516 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
517 int numfkdelsetcols,
int16 *fkdelsetcols,
518 bool old_check_ok,
LOCKMODE lockmode,
519 Oid parentInsTrigger,
Oid parentUpdTrigger);
528 Oid parentInsTrigger,
Oid parentUpdTrigger,
529 Oid *insertTrigOid,
Oid *updateTrigOid);
533 Oid parentDelTrigger,
Oid parentUpdTrigger,
534 Oid *deleteTrigOid,
Oid *updateTrigOid);
537 Oid parentConstrOid,
int numfks,
540 Oid parentInsTrigger,
541 Oid parentUpdTrigger,
545 Oid *deleteTriggerOid,
546 Oid *updateTriggerOid);
549 Oid *insertTriggerOid,
550 Oid *updateTriggerOid);
553 bool missing_ok,
LOCKMODE lockmode);
556 bool recurse,
bool recursing,
557 bool missing_ok,
List **readyRels,
561 bool recurse,
bool recursing,
579 const char *conname);
585 Oid oldOwnerId,
Oid newOwnerId);
594 const char *tablespacename,
LOCKMODE lockmode);
601 char fires_when,
bool skip_system,
bool recurse,
604 char fires_when,
LOCKMODE lockmode);
623 Oid oldRelOid,
void *
arg);
628 List **partexprs,
Oid *partopclass,
Oid *partcollation,
632 bool expect_detached);
640 List *partConstraint,
641 bool validate_default);
649 bool concurrent,
Oid defaultPartOid);
693 List *old_constraints;
696 List *cookedDefaults;
706 const char *accessMethod = NULL;
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)
838 if (tablespaceId == GLOBALTABLESPACE_OID)
840 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
841 errmsg(
"only shared relations can be placed in pg_global tablespace")));
858 case RELKIND_PARTITIONED_TABLE:
865 if (
stmt->ofTypename)
885 stmt->relation->relpersistence,
886 stmt->partbound != NULL,
887 &old_constraints, &old_notnulls);
910 cookedDefaults =
NIL;
913 foreach(listptr,
stmt->tableElts)
932 rawDefaults =
lappend(rawDefaults, rawEnt);
933 attr->atthasdef =
true;
949 cookedDefaults =
lappend(cookedDefaults, cooked);
950 attr->atthasdef =
true;
958 if (
stmt->accessMethod != NULL)
960 accessMethod =
stmt->accessMethod;
964 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
965 errmsg(
"specifying a table access method is not supported on a partitioned table")));
967 else if (RELKIND_HAS_TABLE_AM(relkind))
971 if (accessMethod != NULL)
991 stmt->relation->relpersistence,
1030 true,
true,
false, queryString);
1038 if (
stmt->partbound)
1055 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1057 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1058 errmsg(
"\"%s\" is not partitioned",
1096 NULL,
false,
false);
1151 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1152 errmsg(
"cannot partition using more than %d columns",
1164 partattrs, &partexprs, partopclass,
1165 partcollation,
stmt->partspec->strategy);
1169 partopclass, partcollation);
1182 if (
stmt->partbound)
1196 foreach(cell, idxlist)
1203 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1207 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1208 errmsg(
"cannot create foreign partition of partitioned table \"%s\"",
1210 errdetail(
"Table \"%s\" contains indexes that are unique.",
1224 attmap, &constraintOid);
1231 false,
false,
false,
false,
false);
1259 if (
stmt->constraints)
1261 true,
true,
false, queryString);
1271 foreach(listptr, nncols)
1311 has_not_null =
false;
1339 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1340 errmsg(
"too many array dimensions"));
1344 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1345 errmsg(
"column \"%s\" cannot be declared SETOF",
1349 atttypid, atttypmod, attdim);
1359 att->attinhcount = entry->
inhcount;
1360 att->attidentity = entry->
identity;
1364 att->attstorage = entry->
storage;
1378 constr->
check = NULL;
1405 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1411 (
errmsg(
"schema \"%s\" does not exist, skipping",
1419 if (rentry->
kind == rightkind)
1449 if (rentry->
kind == rightkind)
1454 if (wentry->
kind == wrongkind)
1459 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1490 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1491 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1494 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1495 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1508 relkind = RELKIND_RELATION;
1512 relkind = RELKIND_INDEX;
1516 relkind = RELKIND_SEQUENCE;
1520 relkind = RELKIND_VIEW;
1524 relkind = RELKIND_MATVIEW;
1528 relkind = RELKIND_FOREIGN_TABLE;
1532 elog(
ERROR,
"unrecognized drop object type: %d",
1561 state.expected_relkind = relkind;
1584 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1596 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1598 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1599 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1609 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1611 state.heap_lockmode,
1615 obj.
classId = RelationRelationId;
1643 bool invalid_system_index =
false;
1678 is_partition = classform->relispartition;
1681 state->actual_relkind = classform->relkind;
1682 state->actual_relpersistence = classform->relpersistence;
1692 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1694 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1701 state->expected_relkind);
1716 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1730 indisvalid = indexform->indisvalid;
1735 invalid_system_index =
true;
1741 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1742 errmsg(
"permission denied: \"%s\" is a system catalog",
1756 relOid != oldRelOid)
1769 if (is_partition && relOid != oldRelOid)
1803 foreach(cell,
stmt->relations)
1807 bool recurse = rv->
inh;
1833 relids_logged =
lappend_oid(relids_logged, myrelid);
1842 foreach(child, children)
1881 relids_logged =
lappend_oid(relids_logged, childrelid);
1884 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1886 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1887 errmsg(
"cannot truncate only a partitioned table"),
1888 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1892 stmt->behavior,
stmt->restart_seqs,
false);
1919 List *relids_logged,
1921 bool run_as_table_owner)
1925 HTAB *ft_htab = NULL;
1951 if (newrelids ==
NIL)
1954 foreach(cell, newrelids)
1961 (
errmsg(
"truncate cascades to table \"%s\"",
1971 relids_logged =
lappend_oid(relids_logged, relid);
1981 #ifdef USE_ASSERT_CHECKING
2002 foreach(seqcell, seqlist)
2036 resultRelInfo = resultRelInfos;
2057 resultRelInfo = resultRelInfos;
2062 if (run_as_table_owner)
2066 if (run_as_table_owner)
2081 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2091 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2102 memset(&hctl, 0,
sizeof(
HASHCTL));
2107 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2167 toast_relid = rel->
rd_rel->reltoastrelid;
2174 toastrel->
rd_rel->relpersistence);
2220 foreach(cell, seq_relids)
2234 if (relids_logged !=
NIL)
2243 foreach(cell, relids_logged)
2266 resultRelInfo = resultRelInfos;
2271 if (run_as_table_owner)
2275 if (run_as_table_owner)
2314 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2321 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2322 errmsg(
"cannot truncate foreign table \"%s\"",
2325 else if (reltuple->relkind != RELKIND_RELATION &&
2326 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2328 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2341 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2342 errmsg(
"permission denied: \"%s\" is a system catalog",
2378 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2379 errmsg(
"cannot truncate temporary tables of other sessions")));
2397 case TYPSTORAGE_PLAIN:
2399 case TYPSTORAGE_EXTERNAL:
2401 case TYPSTORAGE_EXTENDED:
2403 case TYPSTORAGE_MAIN:
2478 bool is_partition,
List **supconstr,
List **supnotnulls)
2483 bool have_bogus_defaults =
false;
2485 static Node bogus_marker = {0};
2502 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2503 errmsg(
"tables can have at most %d columns",
2520 for (
int coldefpos = 0; coldefpos <
list_length(columns); coldefpos++)
2524 if (!is_partition && coldef->
typeName == NULL)
2533 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2534 errmsg(
"column \"%s\" does not exist",
2539 for (
int restpos = coldefpos + 1; restpos <
list_length(columns);)
2559 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2560 errmsg(
"column \"%s\" specified more than once",
2575 saved_columns = columns;
2591 List *inherited_defaults;
2592 List *cols_with_defaults;
2614 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !is_partition)
2616 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2617 errmsg(
"cannot inherit from partitioned table \"%s\"",
2619 if (relation->
rd_rel->relispartition && !is_partition)
2621 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2622 errmsg(
"cannot inherit from partition \"%s\"",
2625 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2626 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2627 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2629 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2630 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2638 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2639 relpersistence == RELPERSISTENCE_TEMP)
2641 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2642 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2646 if (relpersistence != RELPERSISTENCE_TEMP &&
2647 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2649 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2651 ?
"cannot inherit from temporary relation \"%s\""
2652 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2656 if (relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
2659 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2661 ?
"cannot inherit from temporary relation of another session"
2662 :
"cannot create as partition of temporary relation of another session")));
2673 constr = tupleDesc->
constr;
2683 inherited_defaults = cols_with_defaults =
NIL;
2695 foreach(lc1, nnconstrs)
2704 char *attributeName =
NameStr(attribute->attname);
2712 if (attribute->attisdropped)
2719 attribute->atttypmod, attribute->attcollation);
2720 newdef->
storage = attribute->attstorage;
2721 newdef->
generated = attribute->attgenerated;
2732 newdef->
identity = attribute->attidentity;
2739 if (exist_attno > 0)
2746 newattmap->
attnums[parent_attno - 1] = exist_attno;
2761 inh_columns =
lappend(inh_columns, newdef);
2763 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2781 if (!is_partition &&
2799 nnconstraints =
lappend(nnconstraints, nn);
2805 if (attribute->atthasdef)
2810 if (this_default == NULL)
2811 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2820 inherited_defaults =
lappend(inherited_defaults, this_default);
2821 cols_with_defaults =
lappend(cols_with_defaults, mergeddef);
2829 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2833 bool found_whole_row;
2847 if (found_whole_row)
2849 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2850 errmsg(
"cannot convert whole-row table reference"),
2851 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2867 have_bogus_defaults =
true;
2884 bool found_whole_row;
2887 if (check[
i].ccnoinherit)
2901 if (found_whole_row)
2903 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2904 errmsg(
"cannot convert whole-row table reference"),
2905 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2917 foreach(lc1, nnconstrs)
2927 nnconstraints =
lappend(nnconstraints, nn);
2946 if (inh_columns !=
NIL)
2948 int newcol_attno = 0;
2950 foreach(lc, columns)
2953 char *attributeName = newdef->
colname;
2968 if (exist_attno > 0)
2980 inh_columns =
lappend(inh_columns, newdef);
2984 columns = inh_columns;
2992 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2993 errmsg(
"tables can have at most %d columns",
3004 foreach(lc, saved_columns)
3029 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3030 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3034 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3035 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3042 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3043 errmsg(
"child column \"%s\" specifies generation expression",
3045 errhint(
"A child table column cannot be generated unless its parent column is.")));
3070 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3071 errmsg(
"column \"%s\" does not exist",
3080 if (have_bogus_defaults)
3082 foreach(lc, columns)
3090 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3091 errmsg(
"column \"%s\" inherits conflicting generation expressions",
3093 errhint(
"To resolve the conflict, specify a generation expression explicitly.")));
3096 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3097 errmsg(
"column \"%s\" inherits conflicting default values",
3099 errhint(
"To resolve the conflict, specify a default explicitly.")));
3104 *supconstr = constraints;
3105 *supnotnulls = nnconstraints;
3132 foreach(lc, constraints)
3148 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3149 errmsg(
"too many inheritance parents"));
3155 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3166 newcon->
expr = expr;
3168 return lappend(constraints, newcon);
3195 char *attributeName = newdef->
colname;
3204 if (exist_attno == newcol_attno)
3206 (
errmsg(
"merging column \"%s\" with inherited definition",
3210 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
3211 errdetail(
"User-specified column moved to the position of the inherited column.")));
3220 if (inhtypeid != newtypeid || inhtypmod != newtypmod)
3222 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3223 errmsg(
"column \"%s\" has a type conflict",
3234 if (inhcollid != newcollid)
3236 (
errcode(ERRCODE_COLLATION_MISMATCH),
3237 errmsg(
"column \"%s\" has a collation conflict",
3256 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3257 errmsg(
"column \"%s\" has a storage parameter conflict",
3272 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3273 errmsg(
"column \"%s\" has a compression method conflict",
3301 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3302 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3306 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3307 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3314 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3315 errmsg(
"child column \"%s\" specifies generation expression",
3317 errhint(
"A child table column cannot be generated unless its parent column is.")));
3358 char *attributeName = newdef->
colname;
3368 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
3377 if (prevtypeid != newtypeid || prevtypmod != newtypmod)
3379 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3380 errmsg(
"inherited column \"%s\" has a type conflict",
3391 if (prevcollid != newcollid)
3393 (
errcode(ERRCODE_COLLATION_MISMATCH),
3394 errmsg(
"inherited column \"%s\" has a collation conflict",
3407 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3408 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
3421 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3422 errmsg(
"column \"%s\" has a compression method conflict",
3431 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3432 errmsg(
"inherited column \"%s\" has a generation conflict",
3442 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3443 errmsg(
"too many inheritance parents"));
3456 bool child_is_partition)
3482 foreach(entry, supers)
3487 child_is_partition);
3501 bool child_is_partition)
3512 parentobject.
classId = RelationRelationId;
3515 childobject.
classId = RelationRelationId;
3549 foreach(lc, columns)
3586 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3589 if (classtuple->relhassubclass != relhassubclass)
3591 classtuple->relhassubclass = relhassubclass;
3617 Oid oldTableSpaceId;
3623 oldTableSpaceId = rel->
rd_rel->reltablespace;
3624 if (newTableSpaceId == oldTableSpaceId ||
3634 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3635 errmsg(
"cannot move system relation \"%s\"",
3639 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3641 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3642 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3650 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3651 errmsg(
"cannot move temporary tables of other sessions")));
3673 Oid newTableSpaceId,
3688 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3695 rd_rel->relfilenode = newRelFilenumber;
3702 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3704 rd_rel->reltablespace);
3716 char relkind = classform->relkind;
3718 if (classform->reloftype && !recursing)
3720 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3721 errmsg(
"cannot rename column of typed table")));
3730 if (relkind != RELKIND_RELATION &&
3731 relkind != RELKIND_VIEW &&
3732 relkind != RELKIND_MATVIEW &&
3733 relkind != RELKIND_COMPOSITE_TYPE &&
3734 relkind != RELKIND_INDEX &&
3735 relkind != RELKIND_PARTITIONED_INDEX &&
3736 relkind != RELKIND_FOREIGN_TABLE &&
3737 relkind != RELKIND_PARTITIONED_TABLE)
3739 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3740 errmsg(
"cannot rename columns of relation \"%s\"",
3752 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3753 errmsg(
"permission denied: \"%s\" is a system catalog",
3754 NameStr(classform->relname))));
3764 const char *oldattname,
3765 const char *newattname,
3768 int expected_parents,
3812 forboth(lo, child_oids, li, child_numparents)
3817 if (childrelid == myrelid)
3820 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3831 if (expected_parents == 0 &&
3834 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3835 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3840 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3849 foreach(lo, child_oids)
3858 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3859 errmsg(
"column \"%s\" does not exist",
3863 attnum = attform->attnum;
3866 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3867 errmsg(
"cannot rename system column \"%s\"",
3879 if (attform->attinhcount > expected_parents)
3881 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3882 errmsg(
"cannot rename inherited column \"%s\"",
3943 (
errmsg(
"relation \"%s\" does not exist, skipping",
3944 stmt->relation->relname)));
3952 stmt->relation->inh,
3968 const char *oldconname,
3969 const char *newconname,
3972 int expected_parents)
3980 Assert(!myrelid || !mytypid);
4001 elog(
ERROR,
"cache lookup failed for constraint %u",
4006 (con->contype == CONSTRAINT_CHECK ||
4007 con->contype == CONSTRAINT_NOTNULL) &&
4020 forboth(lo, child_oids, li, child_numparents)
4025 if (childrelid == myrelid)
4033 if (expected_parents == 0 &&
4036 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4037 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
4041 if (con->coninhcount > expected_parents)
4043 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4044 errmsg(
"cannot rename inherited constraint \"%s\"",
4049 && (con->contype == CONSTRAINT_PRIMARY
4050 || con->contype == CONSTRAINT_UNIQUE
4051 || con->contype == CONSTRAINT_EXCLUSION))
4089 elog(
ERROR,
"cache lookup failed for type %u", typid);
4104 (
errmsg(
"relation \"%s\" does not exist, skipping",
4105 stmt->relation->relname)));
4115 stmt->relation->inh),
4156 (
errmsg(
"relation \"%s\" does not exist, skipping",
4157 stmt->relation->relname)));
4168 obj_is_index = (relkind == RELKIND_INDEX ||
4169 relkind == RELKIND_PARTITIONED_INDEX);
4170 if (obj_is_index || is_index_stmt == obj_is_index)
4174 is_index_stmt = obj_is_index;
4217 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4222 (
errcode(ERRCODE_DUPLICATE_TABLE),
4223 errmsg(
"relation \"%s\" already exists",
4233 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4234 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
4255 newrelname, namespaceId);
4260 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4261 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
4292 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4334 int expected_refcnt;
4339 (
errcode(ERRCODE_OBJECT_IN_USE),
4341 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4344 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4345 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4348 (
errcode(ERRCODE_OBJECT_IN_USE),
4350 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4457 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4734 elog(
ERROR,
"unrecognized alter table type: %d",
4742 if (cmd_lockmode > lockmode)
4743 lockmode = cmd_lockmode;
4768 ATPrepCmd(&wqueue, rel, cmd, recurse,
false, lockmode, context);
4792 bool recurse,
bool recursing,
LOCKMODE lockmode,
4805 if (rel->
rd_rel->relispartition &&
4809 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4810 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4812 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
5015 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5016 errmsg(
"cannot change persistence setting twice")));
5030 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5031 errmsg(
"cannot change persistence setting twice")));
5049 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
5051 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
5052 errmsg(
"cannot change access method of a partitioned table")));
5057 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5058 errmsg(
"cannot have multiple SET ACCESS METHOD subcommands")));
5159 elog(
ERROR,
"unrecognized alter table type: %d",
5193 foreach(ltab, *wqueue)
5209 foreach(lcmd, subcmds)
5212 lockmode, pass, context);
5231 foreach(ltab, *wqueue)
5240 if (((tab->
relkind == RELKIND_RELATION ||
5241 tab->
relkind == RELKIND_PARTITIONED_TABLE) &&
5243 tab->
relkind == RELKIND_MATVIEW)
5265 lockmode, cur_pass, context);
5293 cmd->
recurse,
false, NULL, lockmode);
5349 cmd->
recurse,
false, lockmode);
5354 true,
true, lockmode);
5418 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
5419 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
5528 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
5540 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5549 elog(
ERROR,
"unrecognized alter table type: %d",
5609 foreach(lc, beforeStmts)
5618 foreach(lc, atstmt->
cmds)
5680 if (pass < cur_pass)
5683 elog(
ERROR,
"ALTER TABLE scheduling failure: too late for pass %d",
5686 else if (pass > cur_pass)
5703 elog(
ERROR,
"ALTER TABLE scheduling failure: bogus item for pass %d",
5724 foreach(ltab, *wqueue)
5729 if (!RELKIND_HAS_STORAGE(tab->
relkind))
5770 Oid NewAccessMethod;
5783 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5784 errmsg(
"cannot rewrite system relation \"%s\"",
5789 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5790 errmsg(
"cannot rewrite table \"%s\" used as a catalog table",
5799 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5800 errmsg(
"cannot rewrite temporary tables of other sessions")));
5809 NewTableSpace = OldHeap->
rd_rel->reltablespace;
5818 NewAccessMethod = OldHeap->
rd_rel->relam;
5861 persistence, lockmode);
5920 foreach(lc, seqlist)
5936 foreach(ltab, *wqueue)
5943 if (!RELKIND_HAS_STORAGE(tab->
relkind))
5981 foreach(ltab, *wqueue)
6008 bool needscan =
false;
6009 List *notnull_attrs;
6070 elog(
ERROR,
"unrecognized constraint type: %d",
6090 notnull_attrs =
NIL;
6099 for (
i = 0;
i < newTupDesc->
natts;
i++)
6103 if (attr->attnotnull && !attr->attisdropped)
6110 if (newrel || needscan)
6180 for (
i = 0;
i < newTupDesc->
natts;
i++)
6216 foreach(lc, dropped_attrs)
6270 insertslot = newslot;
6279 insertslot = oldslot;
6285 foreach(l, notnull_attrs)
6294 (
errcode(ERRCODE_NOT_NULL_VIOLATION),
6295 errmsg(
"column \"%s\" of relation \"%s\" contains null values",
6311 (
errcode(ERRCODE_CHECK_VIOLATION),
6312 errmsg(
"check constraint \"%s\" of relation \"%s\" is violated by some row",
6322 elog(
ERROR,
"unrecognized constraint type: %d",
6327 if (partqualstate && !
ExecCheck(partqualstate, econtext))
6331 (
errcode(ERRCODE_CHECK_VIOLATION),
6332 errmsg(
"updated partition constraint for default partition \"%s\" would be violated by some row",
6337 (
errcode(ERRCODE_CHECK_VIOLATION),
6338 errmsg(
"partition constraint of relation \"%s\" is violated by some row",
6346 ti_options, bistate);
6385 foreach(ltab, *wqueue)
6388 if (tab->
relid == relid)
6406 *wqueue =
lappend(*wqueue, tab);
6418 return "ADD COLUMN";
6421 return "ALTER COLUMN ... SET DEFAULT";
6423 return "ALTER COLUMN ... DROP NOT NULL";
6425 return "ALTER COLUMN ... SET NOT NULL";
6429 return "ALTER COLUMN ... SET EXPRESSION";
6431 return "ALTER COLUMN ... DROP EXPRESSION";
6433 return "ALTER COLUMN ... SET STATISTICS";
6435 return "ALTER COLUMN ... SET";
6437 return "ALTER COLUMN ... RESET";
6439 return "ALTER COLUMN ... SET STORAGE";
6441 return "ALTER COLUMN ... SET COMPRESSION";
6443 return "DROP COLUMN";
6451 return "ADD CONSTRAINT";
6453 return "ALTER CONSTRAINT";
6455 return "VALIDATE CONSTRAINT";
6457 return "DROP CONSTRAINT";
6461 return "ALTER COLUMN ... SET DATA TYPE";
6463 return "ALTER COLUMN ... OPTIONS";
6467 return "CLUSTER ON";
6469 return "SET WITHOUT CLUSTER";
6471 return "SET ACCESS METHOD";
6473 return "SET LOGGED";
6475 return "SET UNLOGGED";
6477 return "SET WITHOUT OIDS";
6479 return "SET TABLESPACE";
6487 return "ENABLE TRIGGER";
6489 return "ENABLE ALWAYS TRIGGER";
6491 return "ENABLE REPLICA TRIGGER";
6493 return "DISABLE TRIGGER";
6495 return "ENABLE TRIGGER ALL";
6497 return "DISABLE TRIGGER ALL";
6499 return "ENABLE TRIGGER USER";
6501 return "DISABLE TRIGGER USER";
6503 return "ENABLE RULE";
6505 return "ENABLE ALWAYS RULE";
6507 return "ENABLE REPLICA RULE";
6509 return "DISABLE RULE";
6513 return "NO INHERIT";
6519 return "REPLICA IDENTITY";
6521 return "ENABLE ROW SECURITY";
6523 return "DISABLE ROW SECURITY";
6525 return "FORCE ROW SECURITY";
6527 return "NO FORCE ROW SECURITY";
6531 return "ATTACH PARTITION";
6533 return "DETACH PARTITION";
6535 return "DETACH PARTITION ... FINALIZE";
6537 return "ALTER COLUMN ... ADD IDENTITY";
6539 return "ALTER COLUMN ... SET";
6541 return "ALTER COLUMN ... DROP IDENTITY";
6561 switch (rel->
rd_rel->relkind)
6563 case RELKIND_RELATION:
6564 case RELKIND_PARTITIONED_TABLE:
6570 case RELKIND_MATVIEW:
6576 case RELKIND_PARTITIONED_INDEX:
6579 case RELKIND_COMPOSITE_TYPE:
6582 case RELKIND_FOREIGN_TABLE:
6585 case RELKIND_SEQUENCE:
6594 if ((actual_target & allowed_targets) == 0)
6600 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6602 errmsg(
"ALTER action %s cannot be performed on relation \"%s\"",
6607 elog(
ERROR,
"invalid ALTER action attempted on relation \"%s\"",
6618 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6619 errmsg(
"permission denied: \"%s\" is a system catalog",
6640 if (recurse && rel->
rd_rel->relhassubclass)
6653 foreach(child, children)
6658 if (childrelid == relid)
6663 ATPrepCmd(wqueue, childrel, cmd,
false,
true, lockmode, context);
6679 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
6713 Assert(rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
6719 foreach(child, children)
6726 ATPrepCmd(wqueue, childrel, cmd,
true,
true, lockmode, context);
6753 const char *origTypeName)
6770 Anum_pg_depend_refclassid,
6774 Anum_pg_depend_refobjid,
6789 if (pg_depend->classid == TypeRelationId)
6798 origRelation, origTypeName);
6803 if (pg_depend->classid != RelationRelationId)
6822 if (pg_depend->objsubid > 0 && pg_depend->objsubid <= tupleDesc->
natts)
6827 for (
int attno = 1; attno <= tupleDesc->
natts; attno++)
6830 if (att->atttypid == typeOid && !att->attisdropped)
6851 if (RELKIND_HAS_STORAGE(rel->
rd_rel->relkind) ||
6852 RELKIND_HAS_PARTITIONS(rel->
rd_rel->relkind))
6856 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6857 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
6861 else if (origRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
6863 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6864 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
6868 else if (origRelation->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
6870 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6871 errmsg(
"cannot alter foreign table \"%s\" because column \"%s.%s\" uses its row type",
6877 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6878 errmsg(
"cannot alter table \"%s\" because column \"%s.%s\" uses its row type",
6890 origRelation, origTypeName);
6921 Anum_pg_class_reloftype,
6933 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
6934 errmsg(
"cannot alter type \"%s\" because it is the type of a typed table",
6936 errhint(
"Use ALTER ... CASCADE to alter the typed tables too.")));
6962 bool typeOk =
false;
6964 if (typ->typtype == TYPTYPE_COMPOSITE)
6970 typeOk = (typeRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
6981 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6982 errmsg(
"type %s is not a composite type",
7006 if (rel->
rd_rel->reloftype && !recursing)
7008 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7009 errmsg(
"cannot add column to typed table")));
7011 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
7014 if (recurse && !is_view)
7033 bool if_not_exists = (*cmd)->missing_ok;
7054 if (rel->
rd_rel->relispartition && !recursing)
7056 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7057 errmsg(
"cannot add column to a partition")));
7082 if (ctypeId != childatt->atttypid ||
7083 ctypmod != childatt->atttypmod)
7085 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7086 errmsg(
"child table \"%s\" has different type for column \"%s\"",
7089 if (ccollid != childatt->attcollation)
7091 (
errcode(ERRCODE_COLLATION_MISMATCH),
7092 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
7099 childatt->attinhcount++;
7100 if (childatt->attinhcount < 0)
7102 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
7103 errmsg(
"too many inheritance parents"));
7110 (
errmsg(
"merging definition of column \"%s\" for child \"%s\"",
7140 if (context != NULL && !recursing)
7159 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE &&
7162 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7163 errmsg(
"cannot recursively add identity column to table that has child tables")));
7169 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
7176 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
7177 errmsg(
"tables can have at most %d columns",
7188 attribute->attnum = newattnum;
7224 rawEnt->
attnum = attribute->attnum;
7241 false,
true,
false, NULL);
7287 if (RELKIND_HAS_STORAGE(relkind))
7298 nve->
typeId = attribute->atttypid;
7300 defval = (
Expr *) nve;
7314 baseTypeMod = attribute->atttypmod;
7321 attribute->atttypid,
7322 attribute->atttypmod,
7327 elog(
ERROR,
"failed to coerce base type to domain");
7335 newval->attnum = attribute->attnum;
7373 if (children && !recurse)
7375 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7376 errmsg(
"column must be added to child tables too")));
7389 foreach(child, children)
7404 &childcmd, recurse,
true,
7405 lockmode, cur_pass, context);
7445 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7446 errmsg(
"column name \"%s\" conflicts with a system column name",
7453 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7454 errmsg(
"column \"%s\" of relation \"%s\" already exists, skipping",
7460 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7461 errmsg(
"column \"%s\" of relation \"%s\" already exists",
7477 myself.
classId = RelationRelationId;
7480 referenced.
classId = TypeRelationId;
7498 myself.
classId = RelationRelationId;
7501 referenced.
classId = CollationRelationId;
7534 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7535 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7543 if (!attTup->attnotnull)
7552 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7553 errmsg(
"cannot alter system column \"%s\"",
7556 if (attTup->attidentity)
7558 (
errcode(ERRCODE_SYNTAX_ERROR),
7559 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
7568 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
7574 if (partdesc->
nparts > 0)
7576 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7577 errmsg(
"cannot remove constraint from only the partitioned table when partitions exist"),
7578 errhint(
"Do not specify the ONLY keyword."));
7580 else if (rel->
rd_rel->relhassubclass &&
7584 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7585 errmsg(
"not-null constraint on column \"%s\" must be removed in child tables too",
7587 errhint(
"Do not specify the ONLY keyword."));
7594 if (rel->
rd_rel->relispartition)
7601 parent_attnum =
get_attnum(parentId, colName);
7604 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7605 errmsg(
"column \"%s\" is marked NOT NULL in parent table",
7627 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7628 errmsg(
"column \"%s\" is in a primary key", colName));
7631 elog(
ERROR,
"could not find not-null constraint on column \"%s\", relation \"%s\"",
7637 false, &readyRels, lockmode);
7665 bool retval =
false;
7672 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
7675 if (!attForm->attnotnull)
7681 attForm->attnotnull =
true;
7707 foreach(lc, children)
7741 bool recurse,
bool recursing,
List **readyRels,
7753 bool is_no_inherit =
false;
7764 if (readyRels == NULL)
7783 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7784 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7790 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7791 errmsg(
"cannot alter system column \"%s\"",
7797 Anum_pg_constraint_conrelid,
7806 bool changed =
false;
7809 if (conForm->contype != CONSTRAINT_NOTNULL)
7825 conForm->coninhcount++;
7828 else if (!conForm->conislocal)
7830 conForm->conislocal =
true;
7861 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
7863 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7864 errmsg(
"constraint must be added to child tables too"),
7865 errhint(
"Do not specify the ONLY keyword."));
7867 is_no_inherit =
true;
7878 colName,
"not_null",
7884 constraint->
conname = conName;
7890 constraint->
inhcount = recursing ? 1 : 0;
7896 false, !recursing,
false, NULL);
7920 foreach(lc, children)
7927 conName, colName, recurse,
true,
7928 readyRels, lockmode);
7945 const char *colName,
LOCKMODE lockmode)
7953 errcode(ERRCODE_UNDEFINED_COLUMN),
7954 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7990 nnulltest->argisrow =
false;
7996 (
errmsg_internal(
"existing constraints on column \"%s.%s\" are sufficient to prove that it does not contain nulls",
8023 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8024 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8030 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8031 errmsg(
"cannot alter system column \"%s\"",
8036 (
errcode(ERRCODE_SYNTAX_ERROR),
8037 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
8040 newDefault ? 0 :
errhint(
"Use %s instead.",
8041 "ALTER TABLE ... ALTER COLUMN ... DROP IDENTITY")));
8045 (
errcode(ERRCODE_SYNTAX_ERROR),
8046 errmsg(
"column \"%s\" of relation \"%s\" is a generated column",
8050 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... SET EXPRESSION") :
8052 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... DROP EXPRESSION") : 0)));
8064 newDefault != NULL);
8082 false,
true,
false, NULL);
8126 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing)
8136 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8137 if (ispartitioned && !recurse)
8139 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8140 errmsg(
"cannot add identity to a column of only the partitioned table"),
8141 errhint(
"Do not specify the ONLY keyword.")));
8143 if (rel->
rd_rel->relispartition && !recursing)
8145 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8146 errmsg(
"cannot add identity to a column of a partition"));
8153 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8154 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8162 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8163 errmsg(
"cannot alter system column \"%s\"",
8171 if (!attTup->attnotnull)
8173 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8174 errmsg(
"column \"%s\" of relation \"%s\" must be declared NOT NULL before identity can be added",
8177 if (attTup->attidentity)
8179 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8180 errmsg(
"column \"%s\" of relation \"%s\" is already an identity column",
8183 if (attTup->atthasdef)
8185 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8186 errmsg(
"column \"%s\" of relation \"%s\" already has a default value",
8189 attTup->attidentity = cdef->
identity;
8205 if (recurse && ispartitioned)
8212 foreach(lc, children)
8232 LOCKMODE lockmode,
bool recurse,
bool recursing)
8243 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8244 if (ispartitioned && !recurse)
8246 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8247 errmsg(
"cannot change identity column of only the partitioned table"),
8248 errhint(
"Do not specify the ONLY keyword.")));
8250 if (rel->
rd_rel->relispartition && !recursing)
8252 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8253 errmsg(
"cannot change identity column of a partition"));
8259 if (strcmp(defel->
defname,
"generated") == 0)
8263 (
errcode(ERRCODE_SYNTAX_ERROR),
8264 errmsg(
"conflicting or redundant options")));
8265 generatedEl = defel;
8268 elog(
ERROR,
"option \"%s\" not recognized",
8282 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8283 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8291 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8292 errmsg(
"cannot alter system column \"%s\"",
8295 if (!attTup->attidentity)
8297 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8298 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8322 if (generatedEl && recurse && ispartitioned)
8329 foreach(lc, children)
8349 bool recurse,
bool recursing)
8360 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8361 if (ispartitioned && !recurse)
8363 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8364 errmsg(
"cannot drop identity from a column of only the partitioned table"),
8365 errhint(
"Do not specify the ONLY keyword.")));
8367 if (rel->
rd_rel->relispartition && !recursing)
8369 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8370 errmsg(
"cannot drop identity from a column of a partition"));
8376 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8377 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8385 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8386 errmsg(
"cannot alter system column \"%s\"",
8389 if (!attTup->attidentity)
8393 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8394 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8399 (
errmsg(
"column \"%s\" of relation \"%s\" is not an identity column, skipping",
8407 attTup->attidentity =
'\0';
8423 if (recurse && ispartitioned)
8430 foreach(lc, children)
8447 seqaddress.
classId = RelationRelationId;
8477 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8478 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8486 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8487 errmsg(
"cannot alter system column \"%s\"",
8490 if (attTup->attgenerated != ATTRIBUTE_GENERATED_STORED)
8492 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8493 errmsg(
"column \"%s\" of relation \"%s\" is not a generated column",
8520 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8540 rawEnt->
generated = ATTRIBUTE_GENERATED_STORED;
8544 false,
true,
false, NULL);
8555 newval->is_generated =
true;
8590 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8591 errmsg(
"ALTER TABLE / DROP EXPRESSION must be applied to child tables too")));
8604 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8605 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8610 if (attTup->attinhcount > 0)
8612 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8613 errmsg(
"cannot drop generation expression from inherited column")));
8634 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8635 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8643 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8644 errmsg(
"cannot alter system column \"%s\"",
8647 if (attTup->attgenerated != ATTRIBUTE_GENERATED_STORED)
8651 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8652 errmsg(
"column \"%s\" of relation \"%s\" is not a stored generated column",
8657 (
errmsg(
"column \"%s\" of relation \"%s\" is not a stored generated column, skipping",
8669 attTup->attgenerated =
'\0';
8686 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8715 bool newtarget_default;
8722 Datum repl_val[Natts_pg_attribute];
8723 bool repl_null[Natts_pg_attribute];
8724 bool repl_repl[Natts_pg_attribute];
8730 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
8731 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
8734 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8735 errmsg(
"cannot refer to non-index column by number")));
8738 if (newValue &&
intVal(newValue) != -1)
8740 newtarget =
intVal(newValue);
8741 newtarget_default =
false;
8744 newtarget_default =
true;
8746 if (!newtarget_default)
8754 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8755 errmsg(
"statistics target %d is too low",
8762 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8763 errmsg(
"lowering statistics target to %d",
8776 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8777 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8786 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8787 errmsg(
"column number %d of relation \"%s\" does not exist",
8793 attnum = attrtuple->attnum;
8796 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8797 errmsg(
"cannot alter system column \"%s\"",
8800 if (rel->
rd_rel->relkind == RELKIND_INDEX ||
8801 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
8805 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8806 errmsg(
"cannot alter statistics on included column \"%s\" of index \"%s\"",
8810 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8811 errmsg(
"cannot alter statistics on non-expression column \"%s\" of index \"%s\"",
8813 errhint(
"Alter statistics on table column instead.")));
8817 memset(repl_null,
false,
sizeof(repl_null));
8818 memset(repl_repl,
false,
sizeof(repl_repl));
8819 if (!newtarget_default)
8820 repl_val[Anum_pg_attribute_attstattarget - 1] = newtarget;
8822 repl_null[Anum_pg_attribute_attstattarget - 1] =
true;
8823 repl_repl[Anum_pg_attribute_attstattarget - 1] =
true;
8825 repl_val, repl_null, repl_repl);
8859 Datum repl_val[Natts_pg_attribute];
8860 bool repl_null[Natts_pg_attribute];
8861 bool repl_repl[Natts_pg_attribute];
8869 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8870 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8874 attnum = attrtuple->attnum;
8877 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8878 errmsg(
"cannot alter system column \"%s\"",
8891 memset(repl_null,
false,
sizeof(repl_null));
8892 memset(repl_repl,
false,
sizeof(repl_repl));
8893 if (newOptions != (
Datum) 0)
8894 repl_val[Anum_pg_attribute_attoptions - 1] = newOptions;
8896 repl_null[Anum_pg_attribute_attoptions - 1] =
true;
8897 repl_repl[Anum_pg_attribute_attoptions - 1] =
true;
8899 repl_val, repl_null, repl_repl);
8928 bool setstorage,
char newstorage,
8929 bool setcompression,
char newcompression,
8943 for (
int i = 0;
i < indrel->
rd_index->indnatts;
i++)
8965 attrtuple->attstorage = newstorage;
8968 attrtuple->attcompression = newcompression;
9003 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9004 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9008 attnum = attrtuple->attnum;
9011 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9012 errmsg(
"cannot alter system column \"%s\"",
9028 true, attrtuple->attstorage,
9056 if (rel->
rd_rel->reloftype && !recursing)
9058 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9059 errmsg(
"cannot drop column from typed table")));
9061 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
9082 bool recurse,
bool recursing,
9083 bool missing_ok,
LOCKMODE lockmode,
9098 Assert(!recursing || addrs != NULL);
9115 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9116 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9122 (
errmsg(
"column \"%s\" of relation \"%s\" does not exist, skipping",
9129 attnum = targetatt->attnum;
9134 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9135 errmsg(
"cannot drop system column \"%s\"",
9142 if (targetatt->attinhcount > 0 && !recursing)
9144 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9145 errmsg(
"cannot drop inherited column \"%s\"",
9157 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9158 errmsg(
"cannot drop column \"%s\" because it is part of the partition key of relation \"%s\"",
9180 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !recurse)
9182 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9183 errmsg(
"cannot drop column from only the partitioned table when partitions exist"),
9184 errhint(
"Do not specify the ONLY keyword.")));
9187 foreach(child, children)
9199 elog(
ERROR,
"cache lookup failed for attribute \"%s\" of relation %u",
9200 colName, childrelid);
9203 if (childatt->attinhcount <= 0)
9204 elog(
ERROR,
"relation %u has non-inherited attribute \"%s\"",
9205 childrelid, colName);
9214 if (childatt->attinhcount == 1 && !childatt->attislocal)
9218 behavior,
true,
true,
9219 false, lockmode, addrs);
9224 childatt->attinhcount--;
9239 childatt->attinhcount--;
9240 childatt->attislocal =
true;
9256 object.classId = RelationRelationId;
9258 object.objectSubId =
attnum;
9292 if (rel->
rd_rel->relkind != RELKIND_RELATION ||
9293 !rel->
rd_rel->relhassubclass)
9316 newconstrs =
lappend(newconstrs, nnconstr);
9319 foreach(lc, children)
9329 foreach(lc2, newconstrs)
9335 true,
false, lockmode, context);
9367 check_rights = !is_rebuild;
9439 Oid index_oid =
stmt->indexOid;
9443 char *constraintName;
9444 char constraintType;
9456 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
9458 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9459 errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables")));
9469 elog(
ERROR,
"index \"%s\" is not unique", indexName);
9478 constraintName =
stmt->idxname;
9479 if (constraintName == NULL)
9480 constraintName = indexName;
9481 else if (strcmp(constraintName, indexName) != 0)
9484 (
errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index \"%s\" to \"%s\"",
9485 indexName, constraintName)));
9495 constraintType = CONSTRAINT_PRIMARY;
9497 constraintType = CONSTRAINT_UNIQUE;
9529 Constraint *newConstraint,
bool recurse,
bool is_readd,
9541 switch (newConstraint->
contype)
9547 newConstraint, recurse,
false, is_readd,
9563 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
9582 elog(
ERROR,
"unrecognized constraint type: %d",
9583 (
int) newConstraint->
contype);
9609 foreach(lc, colnames)
9614 buf[buflen++] =
'_';
9621 buflen += strlen(
buf + buflen);
9645 Constraint *constr,
bool recurse,
bool recursing,
9673 recursing || is_readd,
9683 foreach(lcon, newcons)
9748 if (!recurse && children !=
NIL)
9750 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9751 errmsg(
"constraint must be added to child tables too")));
9759 foreach(child, children)
9778 constr, recurse,
true, is_readd, lockmode);
9804 bool recurse,
bool recursing,
LOCKMODE lockmode)
9838 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
9842 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9843 errmsg(
"cannot use ONLY for foreign key on partitioned table \"%s\" referencing relation \"%s\"",
9848 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9849 errmsg(
"cannot add NOT VALID foreign key on partitioned table \"%s\" referencing relation \"%s\"",
9852 errdetail(
"This feature is not yet supported on partitioned tables.")));
9855 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
9856 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
9858 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9859 errmsg(
"referenced relation \"%s\" is not a table",
9864 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9865 errmsg(
"permission denied: \"%s\" is a system catalog",
9876 switch (rel->
rd_rel->relpersistence)
9878 case RELPERSISTENCE_PERMANENT:
9881 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9882 errmsg(
"constraints on permanent tables may reference only permanent tables")));
9884 case RELPERSISTENCE_UNLOGGED:
9886 && pkrel->
rd_rel->relpersistence != RELPERSISTENCE_UNLOGGED)
9888 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9889 errmsg(
"constraints on unlogged tables may reference only permanent or unlogged tables")));
9891 case RELPERSISTENCE_TEMP:
9892 if (pkrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
9894 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9895 errmsg(
"constraints on temporary tables may reference only temporary tables")));
9898 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9899 errmsg(
"constraints on temporary tables must involve temporary tables of this session")));
9909 fkattnum, fktypoid);
9913 fkdelsetcols, NULL);
9915 numfkdelsetcols, fkdelsetcols,
9935 pkattnum, pktypoid);
9949 for (
i = 0;
i < numfks;
i++)
9962 (
errcode(ERRCODE_SYNTAX_ERROR),
9963 errmsg(
"invalid %s action for foreign key constraint containing generated column",
9968 (
errcode(ERRCODE_SYNTAX_ERROR),
9969 errmsg(
"invalid %s action for foreign key constraint containing generated column",
9982 if (numfks != numpks)
9984 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
9985 errmsg(
"number of referencing and referenced columns for foreign key disagree")));
9994 for (
i = 0;
i < numpks;
i++)
9996 Oid pktype = pktypoid[
i];
9997 Oid fktype = fktypoid[
i];
10013 elog(
ERROR,
"cache lookup failed for opclass %u", opclasses[
i]);
10015 amid = cla_tup->opcmethod;
10016 opfamily = cla_tup->opcfamily;
10017 opcintype = cla_tup->opcintype;
10027 if (amid != BTREE_AM_OID)
10028 elog(
ERROR,
"only b-tree indexes are supported for foreign keys");
10039 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
10040 eqstrategy, opcintype, opcintype, opfamily);
10052 pfeqop_right = fktyped;
10074 Oid input_typeids[2];
10075 Oid target_typeids[2];
10077 input_typeids[0] = pktype;
10078 input_typeids[1] = fktype;
10079 target_typeids[0] = opcintype;
10080 target_typeids[1] = opcintype;
10084 pfeqop = ffeqop = ppeqop;
10085 pfeqop_right = opcintype;
10091 (
errcode(ERRCODE_DATATYPE_MISMATCH),
10092 errmsg(
"foreign key constraint \"%s\" cannot be implemented",
10094 errdetail(
"Key columns \"%s\" and \"%s\" "
10095 "are of incompatible types: %s and %s.",
10109 old_check_ok = (pfeqop ==
lfirst_oid(old_pfeqop_item));
10129 old_fktype = attr->atttypid;
10130 new_fktype = fktype;
10168 old_check_ok = (new_pathtype == old_pathtype &&
10169 new_castfunc == old_castfunc &&
10170 (!IsPolymorphicType(pfeqop_right) ||
10171 new_fktype == old_fktype));
10174 pfeqoperators[
i] = pfeqop;
10175 ppeqoperators[
i] = ppeqop;
10176 ffeqoperators[
i] = ffeqop;
10228 int numfksetcols,
const int16 *fksetcolsattnums,
10231 for (
int i = 0;
i < numfksetcols;
i++)
10233 int16 setcol_attnum = fksetcolsattnums[
i];
10236 for (
int j = 0;
j < numfks;
j++)
10238 if (fkattnums[
j] == setcol_attnum)
10250 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
10251 errmsg(
"column \"%s\" referenced in ON DELETE SET action must be part of foreign key", col)));
10293 Oid *ppeqoperators,
Oid *ffeqoperators,
10294 int numfkdelsetcols,
int16 *fkdelsetcols,
10296 Oid parentDelTrigger,
Oid parentUpdTrigger)
10304 Oid deleteTriggerOid,
10311 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
10312 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
10314 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10315 errmsg(
"referenced relation \"%s\" is not a table",
10330 conname = fkconstraint->
conname;
10334 conislocal =
false;
10336 connoinherit =
false;
10346 connoinherit = rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE;
10354 CONSTRAINT_FOREIGN,
10409 constrOid, indexOid,
10410 parentDelTrigger, parentUpdTrigger,
10411 &deleteTriggerOid, &updateTriggerOid);
10418 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10441 for (
int j = 0;
j < numfks;
j++)
10442 mapped_pkattnum[
j] = map->
attnums[pkattnum[
j] - 1];
10445 mapped_pkattnum = pkattnum;
10450 elog(
ERROR,
"index for %u not found in partition %s",
10453 partIndexId, constrOid, numfks,
10454 mapped_pkattnum, fkattnum,
10455 pfeqoperators, ppeqoperators, ffeqoperators,
10456 numfkdelsetcols, fkdelsetcols,
10458 deleteTriggerOid, updateTriggerOid);
10464 pfree(mapped_pkattnum);
10512 int numfks,
int16 *pkattnum,
int16 *fkattnum,
10513 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
10514 int numfkdelsetcols,
int16 *fkdelsetcols,
10515 bool old_check_ok,
LOCKMODE lockmode,
10516 Oid parentInsTrigger,
Oid parentUpdTrigger)
10518 Oid insertTriggerOid,
10523 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
10525 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10526 errmsg(
"foreign key constraints are not supported on foreign tables")));
10539 parentInsTrigger, parentUpdTrigger,
10540 &insertTriggerOid, &updateTriggerOid);
10542 if (rel->
rd_rel->relkind == RELKIND_RELATION)
10563 newcon->
conid = parentConstr;
10564 newcon->
qual = (
Node *) fkconstraint;
10569 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10606 for (
int j = 0;
j < numfks;
j++)
10607 mapped_fkattnum[
j] = attmap->
attnums[fkattnum[
j] - 1];
10612 foreach(cell, partFKs)
10649 conname = fkconstraint->
conname;
10653 CONSTRAINT_FOREIGN,
10739 Assert(parentRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
10816 foreach(cell, clone)
10830 int numfkdelsetcols;
10833 Oid deleteTriggerOid,
10838 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
10870 indexOid = constrForm->conindid;
10881 for (
int i = 0;
i < numfks;
i++)
10882 mapped_confkey[
i] = attmap->
attnums[confkey[
i] - 1];
10885 fkconstraint->
contype = CONSTRAINT_FOREIGN;
10887 fkconstraint->
deferrable = constrForm->condeferrable;
10890 fkconstraint->
pktable = NULL;
10893 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
10903 for (
int i = 0;
i < numfks;
i++)
10920 elog(
ERROR,
"index for %u not found in partition %s",
10929 constrForm->confrelid, constrForm->conrelid,
10930 &deleteTriggerOid, &updateTriggerOid);
10994 if (partRel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
10996 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10997 errmsg(
"foreign key constraints are not supported on foreign tables")));
11017 foreach(cell, clone)
11030 int numfkdelsetcols;
11039 Oid insertTriggerOid,
11044 elog(
ERROR,
"cache lookup failed for constraint %u",
11060 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11065 conpfeqop, conppeqop, conffeqop,
11066 &numfkdelsetcols, confdelsetcols);
11067 for (
int i = 0;
i < numfks;
i++)
11068 mapped_conkey[
i] = attmap->
attnums[conkey[
i] - 1];
11080 constrForm->confrelid, constrForm->conrelid,
11081 &insertTriggerOid, &updateTriggerOid);
11091 foreach(lc, partFKs)
11119 fkconstraint->
contype = CONSTRAINT_FOREIGN;
11121 fkconstraint->
deferrable = constrForm->condeferrable;
11124 fkconstraint->
pktable = NULL;
11127 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
11135 for (
int i = 0;
i < numfks;
i++)
11140 mapped_conkey[
i] - 1);
11146 NameStr(constrForm->conname)))
11155 indexOid = constrForm->conindid;
11158 constrForm->connamespace,
11159 CONSTRAINT_FOREIGN,
11162 constrForm->convalidated,
11170 constrForm->confrelid,
11242 Oid parentConstrOid,
11247 Oid parentInsTrigger,
11248 Oid parentUpdTrigger,
11258 Oid insertTriggerOid,
11264 elog(
ERROR,
"cache lookup failed for constraint %u", parentConstrOid);
11271 if (fk->
confrelid != parentConstr->confrelid || fk->
nkeys != numfks)
11276 for (
int i = 0;
i < numfks;
i++)
11278 if (fk->conkey[
i] != mapped_conkey[
i] ||
11279 fk->confkey[
i] != confkey[
i] ||
11280 fk->conpfeqop[
i] != conpfeqop[
i])
11298 !partConstr->convalidated ||
11299 partConstr->condeferrable != parentConstr->condeferrable ||
11300 partConstr->condeferred != parentConstr->condeferred ||
11301 partConstr->confupdtype != parentConstr->confupdtype ||
11302 partConstr->confdeltype != parentConstr->confdeltype ||
11303 partConstr->confmatchtype != parentConstr->confmatchtype)
11321 Anum_pg_trigger_tgconstraint,
11331 if (trgform->tgconstrrelid != fk->
conrelid)
11365 &insertTriggerOid, &updateTriggerOid);
11384 Oid conoid,
Oid confrelid,
Oid conrelid,
11385 Oid *deleteTriggerOid,
11386 Oid *updateTriggerOid)
11392 *deleteTriggerOid = *updateTriggerOid =
InvalidOid;
11394 Anum_pg_trigger_tgconstraint,
11404 if (trgform->tgconstrrelid != conrelid)
11406 if (trgform->tgrelid != confrelid)
11411 if (TRIGGER_FOR_DELETE(trgform->tgtype))
11414 *deleteTriggerOid = trgform->oid;
11416 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
11419 *updateTriggerOid = trgform->oid;
11421 #ifndef USE_ASSERT_CHECKING
11429 elog(
ERROR,
"could not find ON DELETE action trigger of foreign key constraint %u",
11432 elog(
ERROR,
"could not find ON UPDATE action trigger of foreign key constraint %u",
11445 Oid conoid,
Oid confrelid,
Oid conrelid,
11446 Oid *insertTriggerOid,
11447 Oid *updateTriggerOid)
11453 *insertTriggerOid = *updateTriggerOid =
InvalidOid;
11455 Anum_pg_trigger_tgconstraint,
11465 if (trgform->tgconstrrelid != confrelid)
11467 if (trgform->tgrelid != conrelid)
11472 if (TRIGGER_FOR_INSERT(trgform->tgtype))
11475 *insertTriggerOid = trgform->oid;
11477 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
11480 *updateTriggerOid = trgform->oid;
11482 #ifndef USE_ASSERT_CHECKING
11490 elog(
ERROR,
"could not find ON INSERT check triggers of foreign key constraint %u",
11493 elog(
ERROR,
"could not find ON UPDATE check triggers of foreign key constraint %u",
11511 bool recursing,
LOCKMODE lockmode)
11533 Anum_pg_constraint_conrelid,
11537 Anum_pg_constraint_contypid,
11541 Anum_pg_constraint_conname,
11545 true, NULL, 3, skey);
11550 (
errcode(ERRCODE_UNDEFINED_OBJECT),
11551 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
11555 if (currcon->contype != CONSTRAINT_FOREIGN)
11557 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11558 errmsg(
"constraint \"%s\" of relation \"%s\" is not a foreign key constraint",
11573 Oid parent = currcon->conparentid;
11574 char *ancestorname = NULL;
11575 char *ancestortable = NULL;
11591 parent = contup->conparentid;
11596 (
errmsg(
"cannot alter constraint \"%s\" on relation \"%s\"",
11598 ancestorname && ancestortable ?
11599 errdetail(
"Constraint \"%s\" is derived from constraint \"%s\" of relation \"%s\".",
11600 cmdcon->
conname, ancestorname, ancestortable) : 0,
11601 errhint(
"You may alter the constraint it derives from instead.")));
11610 if (currcon->condeferrable != cmdcon->
deferrable ||
11612 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11615 &otherrelids, lockmode))
11624 foreach(lc, otherrelids)
11654 bool changed =
false;
11660 conoid = currcon->oid;
11661 refrelid = currcon->confrelid;
11669 if (currcon->condeferrable != cmdcon->
deferrable ||
11680 copy_con->condeferrable = cmdcon->
deferrable;
11698 Anum_pg_trigger_tgconstraint,
11725 if (tgform->tgfoid != F_RI_FKEY_NOACTION_DEL &&
11726 tgform->tgfoid != F_RI_FKEY_NOACTION_UPD &&
11727 tgform->tgfoid != F_RI_FKEY_CHECK_INS &&
11728 tgform->tgfoid != F_RI_FKEY_CHECK_UPD)
11754 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
11762 Anum_pg_constraint_conparentid,
11767 true, NULL, 1, &pkey);
11774 childrel =
table_open(childcon->conrelid, lockmode);
11776 otherrelids, lockmode);
11799 bool recurse,
bool recursing,
LOCKMODE lockmode)
11814 Anum_pg_constraint_conrelid,
11818 Anum_pg_constraint_contypid,
11822 Anum_pg_constraint_conname,
11826 true, NULL, 3, skey);
11831 (
errcode(ERRCODE_UNDEFINED_OBJECT),
11832 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
11836 if (con->contype != CONSTRAINT_FOREIGN &&
11837 con->contype != CONSTRAINT_CHECK)
11839 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11840 errmsg(
"constraint \"%s\" of relation \"%s\" is not a foreign key or check constraint",
11843 if (!con->convalidated)
11849 if (con->contype == CONSTRAINT_FOREIGN)
11857 fkconstraint->
conname = constrName;
11860 newcon->
name = constrName;
11862 newcon->
refrelid = con->confrelid;
11864 newcon->
conid = con->oid;
11865 newcon->
qual = (
Node *) fkconstraint;
11876 else if (con->contype == CONSTRAINT_CHECK)
11889 if (!recursing && !con->connoinherit)
11901 foreach(child, children)
11916 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
11917 errmsg(
"constraint must be validated on child tables too")));
11929 newcon->
name = constrName;
11933 newcon->
conid = con->oid;
11936 Anum_pg_constraint_conbin);
11956 copy_con->convalidated =
true;
11994 foreach(l, colList)
12003 (
errcode(ERRCODE_UNDEFINED_COLUMN),
12004 errmsg(
"column \"%s\" referenced in foreign key constraint does not exist",
12007 if (attform->attnum < 0)
12009 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12010 errmsg(
"system columns cannot be used in foreign keys")));
12013 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
12014 errmsg(
"cannot have more than %d keys in a foreign key",
12016 attnums[
attnum] = attform->attnum;
12017 if (atttypids != NULL)
12018 atttypids[
attnum] = attform->atttypid;
12040 List **attnamelist,
12044 List *indexoidlist;
12048 Datum indclassDatum;
12061 foreach(indexoidscan, indexoidlist)
12067 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
12069 if (indexStruct->indisprimary && indexStruct->indisvalid)
12076 if (!indexStruct->indimmediate)
12078 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12079 errmsg(
"cannot use a deferrable primary key for referenced table \"%s\"",
12082 *indexOid = indexoid;
12095 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12096 errmsg(
"there is no primary key for referenced table \"%s\"",
12101 Anum_pg_index_indclass);
12108 *attnamelist =
NIL;
12109 for (
i = 0;
i < indexStruct->indnkeyatts;
i++)
12111 int pkattno = indexStruct->indkey.values[
i];
12113 attnums[
i] = pkattno;
12115 opclasses[
i] = indclass->
values[
i];
12116 *attnamelist =
lappend(*attnamelist,
12139 int numattrs,
int16 *attnums,
12143 bool found =
false;
12144 bool found_deferrable =
false;
12145 List *indexoidlist;
12157 for (
i = 0;
i < numattrs;
i++)
12159 for (
j =
i + 1;
j < numattrs;
j++)
12161 if (attnums[
i] == attnums[
j])
12163 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
12164 errmsg(
"foreign key referenced-columns list must not contain duplicates")));
12175 foreach(indexoidscan, indexoidlist)
12183 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
12191 if (indexStruct->indnkeyatts == numattrs &&
12192 indexStruct->indisunique &&
12193 indexStruct->indisvalid &&
12197 Datum indclassDatum;
12202 Anum_pg_index_indclass);
12215 for (
i = 0;
i < numattrs;
i++)
12218 for (
j = 0;
j < numattrs;
j++)
12220 if (attnums[
i] == indexStruct->indkey.values[
j])
12222 opclasses[
i] = indclass->
values[
j];
12236 if (found && !indexStruct->indimmediate)
12242 found_deferrable =
true;
12253 if (found_deferrable)
12255 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12256 errmsg(
"cannot use a deferrable unique constraint for referenced table \"%s\"",
12260 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
12261 errmsg(
"there is no unique constraint matching given keys for referenced table \"%s\"",
12281 if (targetTypeId == sourceTypeId)
12292 elog(
ERROR,
"could not find cast from %u to %u",
12293 sourceTypeId, targetTypeId);
12318 for (
i = 0;
i < natts;
i++)
12349 (
errmsg_internal(
"validating foreign key constraint \"%s\"", conname)));
12382 "validateForeignKeyConstraint",
12403 trigdata.
type = T_TriggerData;
12410 fcinfo->context = (
Node *) &trigdata;
12433 Oid constraintOid,
Oid indexOid,
Oid parentTrigOid,
12451 fk_trigger->
trigname =
"RI_ConstraintTrigger_c";
12458 fk_trigger->
events = TRIGGER_TYPE_INSERT;
12463 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
12467 fk_trigger->
row =
true;
12468 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12476 trigAddress =
CreateTrigger(fk_trigger, NULL, myRelOid, refRelOid,
12478 parentTrigOid, NULL,
true,
false);
12496 Oid constraintOid,
Oid indexOid,
12497 Oid parentDelTrigger,
Oid parentUpdTrigger,
12498 Oid *deleteTrigOid,
Oid *updateTrigOid)
12510 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
12513 fk_trigger->
row =
true;
12514 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12515 fk_trigger->
events = TRIGGER_TYPE_DELETE;
12548 elog(
ERROR,
"unrecognized FK action type: %d",
12556 parentDelTrigger, NULL,
true,
false);
12558 *deleteTrigOid = trigAddress.
objectId;
12570 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
12573 fk_trigger->
row =
true;
12574 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12575 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
12608 elog(
ERROR,
"unrecognized FK action type: %d",
12616 parentUpdTrigger, NULL,
true,
false);
12618 *updateTrigOid = trigAddress.
objectId;
12633 Oid parentInsTrigger,
Oid parentUpdTrigger,
12634 Oid *insertTrigOid,
Oid *updateTrigOid)
12637 constraintOid, indexOid,
12638 parentInsTrigger,
true);
12640 constraintOid, indexOid,
12641 parentUpdTrigger,
false);
12652 bool missing_ok,
LOCKMODE lockmode)
12658 bool found =
false;
12666 Anum_pg_constraint_conrelid,
12670 Anum_pg_constraint_contypid,
12674 Anum_pg_constraint_conname,
12678 true, NULL, 3, skey);
12686 missing_ok, &readyRels, lockmode);
12696 errcode(ERRCODE_UNDEFINED_OBJECT),
12697 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12701 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist, skipping",
12718 bool recurse,
bool recursing,
bool missing_ok,
List **readyRels,
12726 bool is_no_inherit_constraint =
false;
12727 bool dropping_pk =
false;
12729 List *unconstrained_cols =
NIL;
12746 constrName =
NameStr(con->conname);
12749 if (con->coninhcount > 0 && !recursing)
12751 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12752 errmsg(
"cannot drop inherited constraint \"%s\" of relation \"%s\"",
12760 if (con->contype == CONSTRAINT_NOTNULL)
12767 else if (con->contype == CONSTRAINT_PRIMARY)
12775 dropping_pk =
true;
12777 adatum =
heap_getattr(constraintTup, Anum_pg_constraint_conkey,
12780 elog(
ERROR,
"null conkey for constraint %u", con->oid);
12787 elog(
ERROR,
"conkey is not a 1-D smallint array");
12790 for (
int i = 0;
i < numkeys;
i++)
12791 unconstrained_cols =
lappend_int(unconstrained_cols, attnums[
i]);
12794 is_no_inherit_constraint = con->connoinherit;
12803 if (con->contype == CONSTRAINT_FOREIGN &&
12825 if (unconstrained_cols)
12841 pkcols = dropping_pk ? NULL :
12846 foreach(lc, unconstrained_cols)
12859 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
12884 if (attForm->attidentity)
12886 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12887 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
12898 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12899 errmsg(
"column \"%s\" is in index used as replica identity",
12903 if (attForm->attnotnull)
12905 attForm->attnotnull =
false;
12916 if (con->contype != CONSTRAINT_CHECK &&
12917 con->contype != CONSTRAINT_NOTNULL &&
12918 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
12929 if (!is_no_inherit_constraint)
12939 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
12940 children !=
NIL && !recurse)
12942 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12943 errmsg(
"cannot remove constraint from only the partitioned table when partitions exist"),
12944 errhint(
"Do not specify the ONLY keyword.")));
12947 if (con->contype == CONSTRAINT_NOTNULL)
12953 foreach(child, children)
12971 if (con->contype == CONSTRAINT_NOTNULL)
12975 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation %u",
12984 Anum_pg_constraint_conrelid,
12988 Anum_pg_constraint_contypid,
12992 Anum_pg_constraint_conname,
12996 true, NULL, 3, skey);
13001 (
errcode(ERRCODE_UNDEFINED_OBJECT),
13002 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
13012 if (childcon->contype != CONSTRAINT_CHECK &&
13013 childcon->contype != CONSTRAINT_NOTNULL)
13014 elog(
ERROR,
"inherited constraint is not a CHECK or not-null constraint");
13016 if (childcon->coninhcount <= 0)
13017 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
13018 childrelid,
NameStr(childcon->conname));
13026 if (childcon->coninhcount == 1 && !childcon->conislocal)
13030 recurse,
true, missing_ok, readyRels,
13036 childcon->coninhcount--;
13051 childcon->coninhcount--;
13052 if (childcon->coninhcount == 0)
13053 childcon->conislocal =
true;
13072 if (con->contype == CONSTRAINT_PRIMARY &&
13073 rel->
rd_rel->relkind == RELKIND_RELATION &&
13074 rel->
rd_rel->relhassubclass)
13090 foreach(lc, unconstrained_cols)
13096 foreach(child, children)
13108 foreach(lc, colnames)
13111 char *colName =
lfirst(lc);
13114 if (contup == NULL)
13115 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\", relation \"%s\"",
13156 bool recurse,
bool recursing,
13160 char *colName = cmd->
name;
13168 int32 targettypmod;
13175 if (rel->
rd_rel->reloftype && !recursing)
13177 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
13178 errmsg(
"cannot alter column type of typed table")));
13184 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13185 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
13188 attnum = attTup->attnum;
13193 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13194 errmsg(
"cannot alter system column \"%s\"",
13202 if (attTup->attinhcount > 0 && !recursing)
13204 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13205 errmsg(
"cannot alter inherited column \"%s\"",
13213 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13214 errmsg(
"cannot alter column \"%s\" because it is part of the partition key of relation \"%s\"",
13232 if (tab->
relkind == RELKIND_RELATION ||
13233 tab->
relkind == RELKIND_PARTITIONED_TABLE)
13247 attTup->atttypid, attTup->atttypmod,
13248 attTup->attcollation,
13254 targettype, targettypmod,
13258 if (transform == NULL)
13263 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13264 errmsg(
"result of USING clause for column \"%s\""
13265 " cannot be cast automatically to type %s",
13267 errhint(
"You might need to add an explicit cast.")));
13270 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13271 errmsg(
"column \"%s\" cannot be cast automatically to type %s",
13274 errhint(
"You might need to specify \"USING %s::%s\".",
13293 newval->is_generated =
false;
13299 else if (transform)
13301 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
13302 errmsg(
"\"%s\" is not a table",
13305 if (!RELKIND_HAS_STORAGE(tab->
relkind))
13333 &child_numparents);
13340 forboth(lo, child_oids, li, child_numparents)
13348 if (childrelid == relid)
13365 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13366 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
13370 if (childattTup->attinhcount > numparents)
13372 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13373 errmsg(
"cannot alter inherited column \"%s\" of relation \"%s\"",
13385 bool found_whole_row;
13398 if (found_whole_row)
13400 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13401 errmsg(
"cannot convert whole-row table reference"),
13402 errdetail(
"USING expression contains a whole-row table reference.")));
13405 ATPrepCmd(wqueue, childrel, cmd,
false,
true, lockmode, context);
13409 else if (!recursing &&
13412 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13413 errmsg(
"type of inherited column \"%s\" must be changed in child tables too",
13416 if (tab->
relkind == RELKIND_COMPOSITE_TYPE)
13442 if (
IsA(expr,
Var) && ((
Var *) expr)->varattno == varattno)
13460 case F_TIMESTAMPTZ_TIMESTAMP:
13461 case F_TIMESTAMP_TIMESTAMPTZ:
13485 char *colName = cmd->
name;
13495 int32 targettypmod;
13526 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13527 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
13530 attnum = attTup->attnum;
13534 if (attTup->atttypid != attOldTup->atttypid ||
13535 attTup->atttypmod != attOldTup->atttypmod)
13537 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13538 errmsg(
"cannot alter type of column \"%s\" twice",
13542 typeTuple =
typenameType(NULL, typeName, &targettypmod);
13544 targettype = tform->oid;
13560 if (attTup->atthasdef)
13566 defaultexpr,
exprType(defaultexpr),
13567 targettype, targettypmod,
13571 if (defaultexpr == NULL)
13573 if (attTup->attgenerated)
13575 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13576 errmsg(
"generation expression for column \"%s\" cannot be cast automatically to type %s",
13580 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13581 errmsg(
"default for column \"%s\" cannot be cast automatically to type %s",
13586 defaultexpr = NULL;
13607 Anum_pg_depend_classid,
13611 Anum_pg_depend_objid,
13615 Anum_pg_depend_objsubid,
13627 foundObject.
classId = foundDep->refclassid;
13628 foundObject.
objectId = foundDep->refobjid;
13632 elog(
ERROR,
"found unexpected dependency type '%c'",
13633 foundDep->deptype);
13634 if (!(foundDep->refclassid == TypeRelationId &&
13635 foundDep->refobjid == attTup->atttypid) &&
13636 !(foundDep->refclassid == CollationRelationId &&
13637 foundDep->refobjid == attTup->attcollation))
13638 elog(
ERROR,
"found unexpected dependency for column: %s",
13653 if (attTup->atthasmissing)
13663 Anum_pg_attribute_attmissingval,
13664 attrelation->rd_att,
13680 Datum valuesAtt[Natts_pg_attribute] = {0};
13681 bool nullsAtt[Natts_pg_attribute] = {0};
13682 bool replacesAtt[Natts_pg_attribute] = {0};
13700 valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
13701 replacesAtt[Anum_pg_attribute_attmissingval - 1] =
true;
13702 nullsAtt[Anum_pg_attribute_attmissingval - 1] =
false;
13705 valuesAtt, nullsAtt, replacesAtt);
13712 attTup->atttypid = targettype;
13713 attTup->atttypmod = targettypmod;
13714 attTup->attcollation = targetcollid;
13717 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
13718 errmsg(
"too many array dimensions"));
13719 attTup->attndims =
list_length(typeName->arrayBounds);
13720 attTup->attlen = tform->typlen;
13721 attTup->attbyval = tform->typbyval;
13722 attTup->attalign = tform->typalign;
13723 attTup->attstorage = tform->typstorage;
13758 if (attTup->attgenerated)
13763 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
13812 Anum_pg_depend_refclassid,
13816 Anum_pg_depend_refobjid,
13820 Anum_pg_depend_refobjsubid,
13832 foundObject.
classId = foundDep->classid;
13833 foundObject.
objectId = foundDep->objid;
13842 if (relKind == RELKIND_INDEX ||
13843 relKind == RELKIND_PARTITIONED_INDEX)
13848 else if (relKind == RELKIND_SEQUENCE)
13859 elog(
ERROR,
"unexpected object depending on column: %s",
13874 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13875 errmsg(
"cannot alter type of a column used by a view or rule"),
13876 errdetail(
"%s depends on column \"%s\"",
13894 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13895 errmsg(
"cannot alter type of a column used in a trigger definition"),
13896 errdetail(
"%s depends on column \"%s\"",
13913 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13914 errmsg(
"cannot alter type of a column used in a policy definition"),
13915 errdetail(
"%s depends on column \"%s\"",
13944 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13945 errmsg(
"cannot alter type of a column used by a generated column"),
13946 errdetail(
"Column \"%s\" is used by generated column \"%s\".",
14003 elog(
ERROR,
"unexpected object depending on column: %s",
14029 elog(
ERROR,
"relation %u has multiple indexes marked as replica identity", tab->
relid);
14044 elog(
ERROR,
"relation %u has multiple clustered indexes", tab->
relid);
14214 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
14217 relid = con->conrelid;
14223 elog(
ERROR,
"could not identify relation associated with constraint %u", oldId);
14225 confrelid = con->confrelid;
14226 contype = con->contype;
14227 conislocal = con->conislocal;
14249 if (relid != tab->
relid && contype == CONSTRAINT_FOREIGN)
14253 (
char *)
lfirst(def_item),
14254 wqueue, lockmode, tab->
rewrite);
14256 forboth(oid_item, tab->changedIndexOids,
14257 def_item, tab->changedIndexDefs)
14264 (
char *)
lfirst(def_item),
14265 wqueue, lockmode, tab->rewrite);
14272 forboth(oid_item, tab->changedStatisticsOids,
14273 def_item, tab->changedStatisticsDefs)
14280 (
char *)
lfirst(def_item),
14281 wqueue, lockmode, tab->rewrite);
14290 if (tab->replicaIdentityIndex)
14296 subcmd->
name = tab->replicaIdentityIndex;
14308 if (tab->clusterOnIndex)
14313 cmd->
name = tab->clusterOnIndex;
14346 List *raw_parsetree_list;
14347 List *querytree_list;
14358 querytree_list =
NIL;
14359 foreach(list_item, raw_parsetree_list)
14365 querytree_list =
lappend(querytree_list,
14379 querytree_list =
list_concat(querytree_list, beforeStmts);
14381 querytree_list =
list_concat(querytree_list, afterStmts);
14384 querytree_list =
lappend(querytree_list,
14403 foreach(list_item, querytree_list)
14417 stmt->reset_default_tblspc =
true;
14432 foreach(lcmd,
stmt->cmds)
14448 RelationRelationId, 0);
14470 !rewrite && tab->
rewrite == 0)
14496 elog(
ERROR,
"unexpected statement subtype: %d",
14504 if (
stmt->subtype ==
'C')
14523 elog(
ERROR,
"unexpected statement subtype: %d",
14524 (
int)
stmt->subtype);
14532 stmt->stxcomment =
GetComment(oldId, StatisticExtRelationId, 0);
14541 elog(
ERROR,
"unexpected statement type: %d",
14561 const char *conname)
14568 comment_str =
GetComment(objid, ConstraintRelationId, 0);
14569 if (comment_str == NULL)
14606 stmt->accessMethod,
14608 stmt->excludeOpNames,
14609 stmt->iswithoutoverlaps))
14614 if (irel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
14646 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
14649 Anum_pg_constraint_conpfeqop);
14656 elog(
ERROR,
"conpfeqop is not a 1-D Oid array");
14660 for (
i = 0;
i < numkeys;
i++)
14673 const char *colName,
14684 Datum repl_val[Natts_pg_attribute];
14685 bool repl_null[Natts_pg_attribute];
14686 bool repl_repl[Natts_pg_attribute];
14701 (
errcode(ERRCODE_UNDEFINED_OBJECT),
14702 errmsg(
"foreign table \"%s\" does not exist",
14715 (
errcode(ERRCODE_UNDEFINED_COLUMN),
14716 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
14721 attnum = atttableform->attnum;
14724 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14725 errmsg(
"cannot alter system column \"%s\"", colName)));
14729 memset(repl_val, 0,
sizeof(repl_val));
14730 memset(repl_null,
false,
sizeof(repl_null));
14731 memset(repl_repl,
false,
sizeof(repl_repl));
14736 Anum_pg_attribute_attfdwoptions,
14748 repl_val[Anum_pg_attribute_attfdwoptions - 1] = datum;
14750 repl_null[Anum_pg_attribute_attfdwoptions - 1] =
true;
14752 repl_repl[Anum_pg_attribute_attfdwoptions - 1] =
true;
14757 repl_val, repl_null, repl_repl);
14763 atttableform->attnum);
14807 elog(
ERROR,
"cache lookup failed for relation %u", relationOid);
14811 switch (tuple_class->relkind)
14813 case RELKIND_RELATION:
14815 case RELKIND_MATVIEW:
14816 case RELKIND_FOREIGN_TABLE:
14817 case RELKIND_PARTITIONED_TABLE:
14820 case RELKIND_INDEX:
14830 if (tuple_class->relowner != newOwnerId)
14832 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14833 errmsg(
"cannot change owner of index \"%s\"",
14834 NameStr(tuple_class->relname)),
14835 errhint(
"Change the ownership of the index's table instead.")));
14837 newOwnerId = tuple_class->relowner;
14840 case RELKIND_PARTITIONED_INDEX:
14844 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14845 errmsg(
"cannot change owner of index \"%s\"",
14846 NameStr(tuple_class->relname)),
14847 errhint(
"Change the ownership of the index's table instead.")));
14849 case RELKIND_SEQUENCE:
14851 tuple_class->relowner != newOwnerId)
14860 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14861 errmsg(
"cannot change owner of sequence \"%s\"",
14862 NameStr(tuple_class->relname)),
14863 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
14864 NameStr(tuple_class->relname),
14868 case RELKIND_COMPOSITE_TYPE:
14872 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14873 errmsg(
"\"%s\" is a composite type",
14874 NameStr(tuple_class->relname)),
14879 case RELKIND_TOASTVALUE:
14885 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14886 errmsg(
"cannot change owner of relation \"%s\"",
14887 NameStr(tuple_class->relname)),
14895 if (tuple_class->relowner != newOwnerId)
14897 Datum repl_val[Natts_pg_class];
14898 bool repl_null[Natts_pg_class];
14899 bool repl_repl[Natts_pg_class];
14911 Oid namespaceOid = tuple_class->relnamespace;
14923 aclresult =
object_aclcheck(NamespaceRelationId, namespaceOid, newOwnerId,
14931 memset(repl_null,
false,
sizeof(repl_null));
14932 memset(repl_repl,
false,
sizeof(repl_repl));
14934 repl_repl[Anum_pg_class_relowner - 1] =
true;
14942 Anum_pg_class_relacl,
14947 tuple_class->relowner, newOwnerId);
14948 repl_repl[Anum_pg_class_relacl - 1] =
true;
14963 tuple_class->relowner,
14971 if (tuple_class->relkind != RELKIND_COMPOSITE_TYPE &&
14972 tuple_class->relkind != RELKIND_INDEX &&
14973 tuple_class->relkind != RELKIND_PARTITIONED_INDEX &&
14974 tuple_class->relkind != RELKIND_TOASTVALUE)
14989 if (tuple_class->relkind == RELKIND_RELATION ||
14990 tuple_class->relkind == RELKIND_PARTITIONED_TABLE ||
14991 tuple_class->relkind == RELKIND_MATVIEW ||
14992 tuple_class->relkind == RELKIND_TOASTVALUE)
14994 List *index_oid_list;
15001 foreach(
i, index_oid_list)
15008 if (tuple_class->reltoastrelid !=
InvalidOid)
15039 Anum_pg_attribute_attrelid,
15043 true, NULL, 1,
key);
15047 Datum repl_val[Natts_pg_attribute];
15048 bool repl_null[Natts_pg_attribute];
15049 bool repl_repl[Natts_pg_attribute];
15056 if (att->attisdropped)
15060 Anum_pg_attribute_attacl,
15067 memset(repl_null,
false,
sizeof(repl_null));
15068 memset(repl_repl,
false,
sizeof(repl_repl));
15071 oldOwnerId, newOwnerId);
15072 repl_repl[Anum_pg_attribute_attacl - 1] =
true;
15077 repl_val, repl_null, repl_repl);
15109 Anum_pg_depend_refclassid,
15113 Anum_pg_depend_refobjid,
15127 if (depForm->refobjsubid == 0 ||
15128 depForm->classid != RelationRelationId ||
15129 depForm->objsubid != 0 ||
15173 (
errcode(ERRCODE_UNDEFINED_OBJECT),
15174 errmsg(
"index \"%s\" for table \"%s\" does not exist",
15184 RelationRelationId, indexOid);
15217 if (rel->
rd_rel->relam == amoid)
15249 (
errcode(ERRCODE_SYNTAX_ERROR),
15250 errmsg(
"cannot have multiple SET TABLESPACE subcommands")));
15269 Datum repl_val[Natts_pg_class];
15270 bool repl_null[Natts_pg_class];
15271 bool repl_repl[Natts_pg_class];
15283 elog(
ERROR,
"cache lookup failed for relation %u", relid);
15303 defList, NULL, validnsps,
false,
15307 switch (rel->
rd_rel->relkind)
15309 case RELKIND_RELATION:
15310 case RELKIND_TOASTVALUE:
15311 case RELKIND_MATVIEW:
15314 case RELKIND_PARTITIONED_TABLE:
15320 case RELKIND_INDEX:
15321 case RELKIND_PARTITIONED_INDEX:
15326 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15327 errmsg(
"cannot set options for relation \"%s\"",
15334 if (rel->
rd_rel->relkind == RELKIND_VIEW)
15339 bool check_option =
false;
15341 foreach(cell, view_options)
15345 if (strcmp(defel->
defname,
"check_option") == 0)
15346 check_option =
true;
15355 const char *view_updatable_error =
15358 if (view_updatable_error)
15360 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15361 errmsg(
"WITH CHECK OPTION is supported only on automatically updatable views"),
15362 errhint(
"%s",
_(view_updatable_error))));
15370 memset(repl_val, 0,
sizeof(repl_val));
15371 memset(repl_null,
false,
sizeof(repl_null));
15372 memset(repl_repl,
false,
sizeof(repl_repl));
15374 if (newOptions != (
Datum) 0)
15375 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
15377 repl_null[Anum_pg_class_reloptions - 1] =
true;
15379 repl_repl[Anum_pg_class_reloptions - 1] =
true;
15382 repl_val, repl_null, repl_repl);
15396 Oid toastid = rel->
rd_rel->reltoastrelid;
15403 elog(
ERROR,
"cache lookup failed for relation %u", toastid);
15422 defList,
"toast", validnsps,
false,
15427 memset(repl_val, 0,
sizeof(repl_val));
15428 memset(repl_null,
false,
sizeof(repl_null));
15429 memset(repl_repl,
false,
sizeof(repl_repl));
15431 if (newOptions != (
Datum) 0)
15432 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
15434 repl_null[Anum_pg_class_reloptions - 1] =
true;
15436 repl_repl[Anum_pg_class_reloptions - 1] =
true;
15439 repl_val, repl_null, repl_repl);
15485 reltoastrelid = rel->
rd_rel->reltoastrelid;
15500 rel->
rd_rel->relpersistence);
15504 newrlocator.
relNumber = newrelfilenumber;
15505 newrlocator.
spcOid = newTableSpace;
15508 if (rel->
rd_rel->relkind == RELKIND_INDEX)
15540 foreach(lc, reltoastidxids)
15602 Oid orig_tablespaceoid;
15603 Oid new_tablespaceoid;
15610 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15611 errmsg(
"only tables, indexes, and materialized views exist in tablespaces")));
15619 if (orig_tablespaceoid == GLOBALTABLESPACE_OID ||
15620 new_tablespaceoid == GLOBALTABLESPACE_OID)
15622 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15623 errmsg(
"cannot move relations in to or out of pg_global tablespace")));
15652 if (orig_tablespaceoid == new_tablespaceoid)
15653 return new_tablespaceoid;
15660 Anum_pg_class_reltablespace,
15669 Oid relOid = relForm->oid;
15680 relForm->relisshared ||
15687 relForm->relkind != RELKIND_RELATION &&
15688 relForm->relkind != RELKIND_PARTITIONED_TABLE) ||
15690 relForm->relkind != RELKIND_INDEX &&
15691 relForm->relkind != RELKIND_PARTITIONED_INDEX) ||
15693 relForm->relkind != RELKIND_MATVIEW))
15711 if (
stmt->nowait &&
15714 (
errcode(ERRCODE_OBJECT_IN_USE),
15715 errmsg(
"aborting because lock on relation \"%s.%s\" is not available",
15717 NameStr(relForm->relname))));
15728 if (relations ==
NIL)
15730 (
errcode(ERRCODE_NO_DATA_FOUND),
15731 errmsg(
"no matching relations in tablespace \"%s\" found",
15732 orig_tablespaceoid ==
InvalidOid ?
"(database default)" :
15736 foreach(l, relations)
15742 cmd->
name =
stmt->new_tablespacename;
15752 return new_tablespaceoid;
15779 rel->
rd_rel->relpersistence);
15794 (rel->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
15798 rel->
rd_rel->relpersistence);
15814 char fires_when,
bool skip_system,
bool recurse,
15818 fires_when, skip_system, recurse,
15832 char fires_when,
LOCKMODE lockmode)
15850 if (child_rel->
rd_rel->reloftype)
15852 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15853 errmsg(
"cannot change inheritance of typed table")));
15855 if (child_rel->
rd_rel->relispartition)
15857 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15858 errmsg(
"cannot change inheritance of a partition")));
15860 if (child_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
15862 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15863 errmsg(
"cannot change inheritance of partitioned table")));
15875 const char *trigger_name;
15890 if (parent_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
15891 child_rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
15893 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15894 errmsg(
"cannot inherit from temporary relation \"%s\"",
15898 if (parent_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
15901 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15902 errmsg(
"cannot inherit from temporary relation of another session")));
15905 if (child_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
15908 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15909 errmsg(
"cannot inherit to temporary relation of another session")));
15912 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
15914 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15915 errmsg(
"cannot inherit from partitioned table \"%s\"",
15919 if (parent_rel->
rd_rel->relispartition)
15921 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15922 errmsg(
"cannot inherit from a partition")));
15943 (
errcode(ERRCODE_DUPLICATE_TABLE),
15944 errmsg(
"circular inheritance not allowed"),
15945 errdetail(
"\"%s\" is already a child of \"%s\".",
15955 if (trigger_name != NULL)
15957 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15958 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming an inheritance child",
15960 errdetail(
"ROW triggers with transition tables are not supported in inheritance hierarchies.")));
16010 Anum_pg_inherits_inhrelid,
16014 true, NULL, 1, &
key);
16024 (
errcode(ERRCODE_DUPLICATE_TABLE),
16025 errmsg(
"relation \"%s\" would be inherited from more than once",
16028 if (inh->inhseqno > inhseqno)
16029 inhseqno = inh->inhseqno;
16046 parent_rel->
rd_rel->relkind ==
16047 RELKIND_PARTITIONED_TABLE);
16066 attr =
heap_getattr(contup, Anum_pg_constraint_conbin, tupdesc, &isnull);
16068 elog(
ERROR,
"null conbin for constraint %u", con->oid);
16088 if (acon->condeferrable != bcon->condeferrable ||
16089 acon->condeferred != bcon->condeferred ||
16120 for (
AttrNumber parent_attno = 1; parent_attno <= parent_desc->
natts; parent_attno++)
16123 char *parent_attname =
NameStr(parent_att->attname);
16127 if (parent_att->attisdropped)
16136 if (parent_att->atttypid != child_att->atttypid ||
16137 parent_att->atttypmod != child_att->atttypmod)
16139 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16140 errmsg(
"child table \"%s\" has different type for column \"%s\"",
16143 if (parent_att->attcollation != child_att->attcollation)
16145 (
errcode(ERRCODE_COLLATION_MISMATCH),
16146 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
16155 if (parent_att->attnotnull && !child_att->attnotnull)
16160 parent_att->attnum);
16164 errcode(ERRCODE_DATATYPE_MISMATCH),
16165 errmsg(
"column \"%s\" in child table must be marked NOT NULL",
16172 if (parent_att->attgenerated && !child_att->attgenerated)
16174 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16175 errmsg(
"column \"%s\" in child table must be a generated column", parent_attname)));
16176 if (child_att->attgenerated && !parent_att->attgenerated)
16178 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16179 errmsg(
"column \"%s\" in child table must not be a generated column", parent_attname)));
16187 child_att->attidentity = parent_att->attidentity;
16193 child_att->attinhcount++;
16194 if (child_att->attinhcount < 0)
16196 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
16197 errmsg(
"too many inheritance parents"));
16204 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
16206 Assert(child_att->attinhcount == 1);
16207 child_att->attislocal =
false;
16216 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16217 errmsg(
"child table is missing column \"%s\"", parent_attname)));
16254 Anum_pg_constraint_conrelid,
16258 true, NULL, 1, &parent_key);
16266 bool found =
false;
16268 if (parent_con->contype != CONSTRAINT_CHECK &&
16269 parent_con->contype != CONSTRAINT_NOTNULL)
16273 if (parent_con->connoinherit)
16278 Anum_pg_constraint_conrelid,
16282 true, NULL, 1, &child_key);
16289 if (child_con->contype != parent_con->contype)
16296 if (child_con->contype == CONSTRAINT_CHECK)
16298 if (strcmp(
NameStr(parent_con->conname),
16299 NameStr(child_con->conname)) != 0)
16302 else if (child_con->contype == CONSTRAINT_NOTNULL)
16307 if (strcmp(
get_attname(parent_relid, parent_attno,
false),
16313 if (child_con->contype == CONSTRAINT_CHECK &&
16316 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16317 errmsg(
"child table \"%s\" has different definition for check constraint \"%s\"",
16331 if (child_con->contype == CONSTRAINT_CHECK &&
16332 child_con->connoinherit)
16334 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
16335 errmsg(
"constraint \"%s\" conflicts with non-inherited constraint on child table \"%s\"",
16342 if (parent_con->convalidated && !child_con->convalidated)
16344 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
16345 errmsg(
"constraint \"%s\" conflicts with NOT VALID constraint on child table \"%s\"",
16354 child_con->coninhcount++;
16355 if (child_con->coninhcount < 0)
16357 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
16358 errmsg(
"too many inheritance parents"));
16359 if (child_con->contype == CONSTRAINT_NOTNULL &&
16360 child_con->connoinherit)
16361 child_con->connoinherit =
false;
16368 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
16370 Assert(child_con->coninhcount == 1);
16371 child_con->conislocal =
false;
16385 if (parent_con->contype == CONSTRAINT_NOTNULL)
16387 errcode(ERRCODE_DATATYPE_MISMATCH),
16388 errmsg(
"column \"%s\" in child table must be marked NOT NULL",
16394 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16395 errmsg(
"child table is missing constraint \"%s\"",
16396 NameStr(parent_con->conname))));
16415 if (rel->
rd_rel->relispartition)
16417 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16418 errmsg(
"cannot change inheritance of a partition")));
16470 bool found =
false;
16472 Assert(parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
16480 Anum_pg_inherits_inhparent,
16484 true, NULL, 1, &
key);
16491 if (inhForm->inhdetachpending)
16493 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
16494 errmsg(
"partition \"%s\" already pending detach in partitioned table \"%s.%s\"",
16498 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
16523 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
16557 bool is_partitioning;
16559 is_partitioning = (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
16567 if (is_partitioning)
16570 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
16576 errmsg(
"relation \"%s\" is not a parent of relation \"%s\"",
16586 Anum_pg_attribute_attrelid,
16590 true, NULL, 1,
key);
16596 if (att->attisdropped)
16598 if (att->attinhcount <= 0)
16608 copy_att->attinhcount--;
16609 if (copy_att->attinhcount == 0)
16610 copy_att->attislocal =
true;
16629 Anum_pg_constraint_conrelid,
16633 true, NULL, 1,
key);
16642 if (con->contype == CONSTRAINT_CHECK)
16644 if (con->contype == CONSTRAINT_NOTNULL)
16652 Anum_pg_constraint_conrelid,
16656 true, NULL, 1,
key);
16661 bool match =
false;
16668 if (con->contype == CONSTRAINT_CHECK)
16670 foreach(lc, connames)
16672 if (con->contype == CONSTRAINT_CHECK &&
16680 else if (con->contype == CONSTRAINT_NOTNULL)
16684 foreach(lc, nncolumns)
16702 if (copy_con->coninhcount <= 0)
16703 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
16706 copy_con->coninhcount--;
16707 if (copy_con->coninhcount == 0)
16708 copy_con->conislocal =
true;
16719 RelationRelationId,
16749 if (!parent_rel->
rd_rel->relhasindex)
16754 if (pkattnos != NULL)
16800 Anum_pg_depend_classid,
16804 Anum_pg_depend_objid,
16808 Anum_pg_depend_objsubid,
16819 if (dep->refclassid == refclassid &&
16820 dep->refobjid == refobjid &&
16821 dep->refobjsubid == 0 &&
16822 dep->deptype == deptype)
16863 typeid = typeform->oid;
16868 Anum_pg_inherits_inhrelid,
16872 true, NULL, 1, &
key);
16875 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16876 errmsg(
"typed tables cannot inherit")));
16887 for (type_attno = 1; type_attno <= typeTupleDesc->
natts; type_attno++)
16891 const char *type_attname,
16896 if (type_attr->attisdropped)
16898 type_attname =
NameStr(type_attr->attname);
16903 if (table_attno > tableTupleDesc->
natts)
16905 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16906 errmsg(
"table is missing column \"%s\"",
16908 table_attr =
TupleDescAttr(tableTupleDesc, table_attno - 1);
16910 }
while (table_attr->attisdropped);
16911 table_attname =
NameStr(table_attr->attname);
16914 if (strncmp(table_attname, type_attname,
NAMEDATALEN) != 0)
16916 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16917 errmsg(
"table has column \"%s\" where type requires \"%s\"",
16918 table_attname, type_attname)));
16921 if (table_attr->atttypid != type_attr->atttypid ||
16922 table_attr->atttypmod != type_attr->atttypmod ||
16923 table_attr->attcollation != type_attr->attcollation)
16925 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16926 errmsg(
"table \"%s\" has different type for column \"%s\"",
16932 for (; table_attno <= tableTupleDesc->
natts; table_attno++)
16937 if (!table_attr->attisdropped)
16939 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16940 errmsg(
"table has extra column \"%s\"",
16941 NameStr(table_attr->attname))));
16945 if (rel->
rd_rel->reloftype)
16950 tableobj.
classId = RelationRelationId;
16953 typeobj.
classId = TypeRelationId;
16962 elog(
ERROR,
"cache lookup failed for relation %u", relid);
16991 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16992 errmsg(
"\"%s\" is not a typed table",
17007 elog(
ERROR,
"cache lookup failed for relation %u", relid);
17045 elog(
ERROR,
"cache lookup failed for relation \"%s\"",
17048 if (pg_class_form->relreplident != ri_type)
17050 pg_class_form->relreplident = ri_type;
17063 bool dirty =
false;
17068 elog(
ERROR,
"cache lookup failed for index %u", thisIndexOid);
17071 if (thisIndexOid == indexOid)
17074 if (!pg_index_form->indisreplident)
17077 pg_index_form->indisreplident =
true;
17083 if (pg_index_form->indisreplident)
17086 pg_index_form->indisreplident =
false;
17121 if (
stmt->identity_type == REPLICA_IDENTITY_DEFAULT)
17126 else if (
stmt->identity_type == REPLICA_IDENTITY_FULL)
17131 else if (
stmt->identity_type == REPLICA_IDENTITY_NOTHING)
17136 else if (
stmt->identity_type == REPLICA_IDENTITY_INDEX)
17141 elog(
ERROR,
"unexpected identity type %u",
stmt->identity_type);
17147 (
errcode(ERRCODE_UNDEFINED_OBJECT),
17148 errmsg(
"index \"%s\" for table \"%s\" does not exist",
17157 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17158 errmsg(
"\"%s\" is not an index for table \"%s\"",
17165 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17166 errmsg(
"cannot use non-unique index \"%s\" as replica identity",
17169 if (!indexRel->
rd_index->indimmediate)
17171 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17172 errmsg(
"cannot use non-immediate index \"%s\" as replica identity",
17177 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17178 errmsg(
"cannot use expression index \"%s\" as replica identity",
17183 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17184 errmsg(
"cannot use partial index \"%s\" as replica identity",
17200 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
17201 errmsg(
"index \"%s\" cannot be used as replica identity because column %d is a system column",
17205 if (!attr->attnotnull)
17207 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17208 errmsg(
"index \"%s\" cannot be used as replica identity because column \"%s\" is nullable",
17237 elog(
ERROR,
"cache lookup failed for relation %u", relid);
17266 elog(
ERROR,
"cache lookup failed for relation %u", relid);
17289 Datum repl_val[Natts_pg_foreign_table];
17290 bool repl_null[Natts_pg_foreign_table];
17291 bool repl_repl[Natts_pg_foreign_table];
17304 (
errcode(ERRCODE_UNDEFINED_OBJECT),
17305 errmsg(
"foreign table \"%s\" does not exist",
17311 memset(repl_val, 0,
sizeof(repl_val));
17312 memset(repl_null,
false,
sizeof(repl_null));
17313 memset(repl_repl,
false,
sizeof(repl_repl));
17318 Anum_pg_foreign_table_ftoptions,
17330 repl_val[Anum_pg_foreign_table_ftoptions - 1] = datum;
17332 repl_null[Anum_pg_foreign_table_ftoptions - 1] =
true;
17334 repl_repl[Anum_pg_foreign_table_ftoptions - 1] =
true;
17339 repl_val, repl_null, repl_repl);
17364 const char *column,
17376 compression =
strVal(newValue);
17384 (
errcode(ERRCODE_UNDEFINED_COLUMN),
17385 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
17390 attnum = atttableform->attnum;
17393 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17394 errmsg(
"cannot alter system column \"%s\"", column)));
17403 atttableform->attcompression = cmethod;
17455 switch (rel->
rd_rel->relpersistence)
17457 case RELPERSISTENCE_TEMP:
17459 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17460 errmsg(
"cannot change logged status of table \"%s\" because it is temporary",
17464 case RELPERSISTENCE_PERMANENT:
17469 case RELPERSISTENCE_UNLOGGED:
17483 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
17484 errmsg(
"cannot change table \"%s\" to unlogged because it is part of a publication",
17486 errdetail(
"Unlogged relations cannot be replicated.")));
17500 toLogged ? Anum_pg_constraint_conrelid :
17501 Anum_pg_constraint_confrelid,
17505 toLogged ? ConstraintRelidTypidNameIndexId :
InvalidOid,
17506 true, NULL, 1, skey);
17512 if (con->contype == CONSTRAINT_FOREIGN)
17518 foreignrelid = toLogged ? con->confrelid : con->conrelid;
17530 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17531 errmsg(
"could not change table \"%s\" to logged because it references unlogged table \"%s\"",
17540 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17541 errmsg(
"could not change table \"%s\" to unlogged because it references logged table \"%s\"",
17580 (
errmsg(
"relation \"%s\" does not exist, skipping",
17581 stmt->relation->relname)));
17590 if (rel->
rd_rel->relkind == RELKIND_SEQUENCE)
17598 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17599 errmsg(
"cannot move an owned sequence into another schema"),
17600 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
17619 *oldschema = oldNspOid;
17638 Assert(objsMoved != NULL);
17644 nspOid,
true, objsMoved);
17649 nspOid,
false,
false, objsMoved);
17652 if (rel->
rd_rel->relkind == RELKIND_RELATION ||
17653 rel->
rd_rel->relkind == RELKIND_MATVIEW ||
17654 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
17673 Oid oldNspOid,
Oid newNspOid,
17674 bool hasDependEntry,
17680 bool already_done =
false;
17684 elog(
ERROR,
"cache lookup failed for relation %u", relOid);
17687 Assert(classForm->relnamespace == oldNspOid);
17689 thisobj.
classId = RelationRelationId;
17699 if (!already_done && oldNspOid != newNspOid)
17705 (
errcode(ERRCODE_DUPLICATE_TABLE),
17706 errmsg(
"relation \"%s\" already exists in schema \"%s\"",
17711 classForm->relnamespace = newNspOid;
17716 if (hasDependEntry &&
17719 NamespaceRelationId,
17722 elog(
ERROR,
"could not change schema dependency for relation \"%s\"",
17723 NameStr(classForm->relname));
17750 foreach(l, indexList)
17755 thisobj.
classId = RelationRelationId;
17770 oldNspOid, newNspOid,
17803 Anum_pg_depend_refclassid,
17807 Anum_pg_depend_refobjid,
17821 if (depForm->refobjsubid == 0 ||
17822 depForm->classid != RelationRelationId ||
17823 depForm->objsubid != 0 ||
17840 oldNspOid, newNspOid,
17916 if (oc->
relid == relid)
17934 List *oids_to_truncate =
NIL;
17975 if (oids_to_truncate !=
NIL)
17978 if (oids_to_drop !=
NIL)
17982 foreach(l, oids_to_drop)
17986 object.
classId = RelationRelationId;
17988 object.objectSubId = 0;
18010 #ifdef USE_ASSERT_CHECKING
18123 if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE &&
18124 relkind != RELKIND_MATVIEW && relkind != RELKIND_PARTITIONED_TABLE)
18126 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18127 errmsg(
"\"%s\" is not a table or materialized view", relation->
relname)));
18152 elog(
ERROR,
"cache lookup failed for relation %u", relId);
18176 elog(
ERROR,
"cache lookup failed for relation %u", relId);
18185 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
18186 errmsg(
"permission denied: \"%s\" is a system catalog",
18211 relkind = classform->relkind;
18220 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
18221 errmsg(
"permission denied: \"%s\" is a system catalog",
18232 aclresult =
object_aclcheck(NamespaceRelationId, classform->relnamespace,
18259 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18262 if (reltype ==
OBJECT_VIEW && relkind != RELKIND_VIEW)
18264 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18269 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18270 errmsg(
"\"%s\" is not a materialized view", rv->
relname)));
18274 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18277 if (reltype ==
OBJECT_TYPE && relkind != RELKIND_COMPOSITE_TYPE)
18279 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18282 if (reltype ==
OBJECT_INDEX && relkind != RELKIND_INDEX &&
18283 relkind != RELKIND_PARTITIONED_INDEX
18286 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18293 if (reltype !=
OBJECT_TYPE && relkind == RELKIND_COMPOSITE_TYPE)
18295 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18307 if (relkind == RELKIND_INDEX || relkind == RELKIND_PARTITIONED_INDEX)
18309 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18310 errmsg(
"cannot change schema of index \"%s\"",
18312 errhint(
"Change the schema of the table instead.")));
18313 else if (relkind == RELKIND_COMPOSITE_TYPE)
18315 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18316 errmsg(
"cannot change schema of composite type \"%s\"",
18321 else if (relkind == RELKIND_TOASTVALUE)
18323 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18324 errmsg(
"cannot change schema of TOAST table \"%s\"",
18326 errhint(
"Change the schema of the table instead.")));
18355 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18356 errmsg(
"cannot use \"list\" partition strategy with more than one column")));
18364 NULL,
false,
true);
18397 List **partexprs,
Oid *partopclass,
Oid *partcollation,
18405 foreach(lc, partParams)
18411 if (pelem->
name != NULL)
18421 (
errcode(ERRCODE_UNDEFINED_COLUMN),
18422 errmsg(
"column \"%s\" named in partition key does not exist",
18427 if (attform->attnum <= 0)
18429 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18430 errmsg(
"cannot use system column \"%s\" in partition key",
18438 if (attform->attgenerated)
18440 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18441 errmsg(
"cannot use generated column in partition key"),
18442 errdetail(
"Column \"%s\" is a generated column.",
18446 partattrs[attn] = attform->attnum;
18447 atttype = attform->atttypid;
18448 attcollation = attform->attcollation;
18455 char partattname[16];
18467 snprintf(partattname,
sizeof(partattname),
"%d", attn + 1);
18469 atttype, attcollation,
18480 ((
Var *) expr)->varattno > 0)
18486 partattrs[attn] = ((
Var *) expr)->varattno;
18493 partattrs[attn] = 0;
18494 *partexprs =
lappend(*partexprs, expr);
18513 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18514 errmsg(
"partition key expressions cannot contain system column references")));
18530 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18531 errmsg(
"cannot use generated column in partition key"),
18532 errdetail(
"Column \"%s\" is a generated column.",
18560 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18561 errmsg(
"functions in partition key expression must be marked IMMUTABLE")));
18569 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18570 errmsg(
"cannot use constant expression as partition key")));
18590 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
18591 errmsg(
"could not determine which collation to use for partition expression"),
18592 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
18598 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18599 errmsg(
"collations are not supported by type %s",
18603 partcollation[attn] = attcollation;
18611 am_oid = HASH_AM_OID;
18613 am_oid = BTREE_AM_OID;
18623 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18624 errmsg(
"data type %s has no default operator class for access method \"%s\"",
18626 errhint(
"You must specify a hash operator class or define a default hash operator class for the data type.")));
18629 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18630 errmsg(
"data type %s has no default operator class for access method \"%s\"",
18632 errhint(
"You must specify a btree operator class or define a default btree operator class for the data type.")));
18638 am_oid == HASH_AM_OID ?
"hash" :
"btree",
18655 List *partConstraint)
18665 for (
i = 1;
i <= natts;
i++)
18669 if (att->attnotnull && !att->attisdropped)
18686 ntest->argisrow =
false;
18688 existConstraint =
lappend(existConstraint, ntest);
18714 num_check = (constr != NULL) ? constr->
num_check : 0;
18715 for (
i = 0;
i < num_check;
i++)
18765 List *partConstraint,
18766 bool validate_default)
18774 if (!validate_default)
18776 (
errmsg_internal(
"partition constraint for table \"%s\" is implied by existing constraints",
18780 (
errmsg_internal(
"updated partition constraint for default partition \"%s\" is implied by existing constraints",
18790 if (scanrel->
rd_rel->relkind == RELKIND_RELATION)
18800 else if (scanrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
18808 List *thisPartConstraint;
18819 thisPartConstraint =
18821 part_rel, scanrel);
18824 thisPartConstraint,
18842 List *attachrel_children;
18843 List *partConstraint;
18850 const char *trigger_name;
18851 Oid defaultPartOid;
18852 List *partBoundConstraint;
18880 if (attachrel->
rd_rel->relispartition)
18882 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18883 errmsg(
"\"%s\" is already a partition",
18888 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18889 errmsg(
"cannot attach a typed table as partition")));
18897 Anum_pg_inherits_inhrelid,
18904 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18905 errmsg(
"cannot attach inheritance child as partition")));
18910 Anum_pg_inherits_inhparent,
18916 attachrel->
rd_rel->relkind == RELKIND_RELATION)
18918 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18919 errmsg(
"cannot attach inheritance parent as partition")));
18942 (
errcode(ERRCODE_DUPLICATE_TABLE),
18943 errmsg(
"circular inheritance not allowed"),
18944 errdetail(
"\"%s\" is already a child of \"%s\".",
18949 if (rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
18950 attachrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
18952 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18953 errmsg(
"cannot attach a temporary relation as partition of permanent relation \"%s\"",
18957 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
18958 attachrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
18960 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18961 errmsg(
"cannot attach a permanent relation as partition of temporary relation \"%s\"",
18965 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
18968 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18969 errmsg(
"cannot attach as partition of temporary relation of another session")));
18972 if (attachrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
18975 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18976 errmsg(
"cannot attach temporary relation of another session as partition")));
18983 natts = tupleDesc->
natts;
18984 for (attno = 1; attno <= natts; attno++)
18987 char *attributeName =
NameStr(attribute->attname);
18990 if (attribute->attisdropped)
18993 if (attribute->attidentity)
18995 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
18996 errmsg(
"table \"%s\" being attached contains an identity column \"%s\"",
18998 errdetail(
"The new partition may not contain an identity column."));
19005 (
errcode(ERRCODE_DATATYPE_MISMATCH),
19006 errmsg(
"table \"%s\" contains column \"%s\" not found in parent \"%s\"",
19009 errdetail(
"The new partition may contain only the columns present in parent.")));
19018 if (trigger_name != NULL)
19020 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19021 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming a partition",
19023 errdetail(
"ROW triggers with transition tables are not supported on partitions.")));
19031 cmd->
bound, pstate);
19057 partConstraint =
list_concat(partBoundConstraint,
19061 if (partConstraint)
19070 (
Node *) partConstraint);
19097 List *defPartConstraint;
19103 defPartConstraint =
19110 defPartConstraint =
19112 1, defaultrel, rel);
19114 defPartConstraint,
true);
19128 if (attachrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
19132 foreach(l, attachrel_children)
19156 List *attachRelIdxs;
19164 "AttachPartitionEnsureIndexes",
19174 foreach(cell, attachRelIdxs)
19189 if (attachrel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
19191 foreach(cell, idxes)
19196 if (idxRel->
rd_index->indisunique ||
19199 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19200 errmsg(
"cannot attach foreign table \"%s\" as partition of partitioned table \"%s\"",
19203 errdetail(
"Partitioned table \"%s\" contains unique indexes.",
19215 foreach(cell, idxes)
19221 bool found =
false;
19228 if (idxRel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
19252 if (attachrelIdxRels[
i]->rd_rel->relispartition)
19256 if (!attachrelIdxRels[
i]->rd_index->indisvalid)
19260 attachrelIdxRels[
i]->rd_indcollation,
19332 true,
false,
false,
false,
false);
19364 true, NULL, 1, &
key);
19383 if (!TRIGGER_FOR_ROW(trigForm->tgtype))
19390 if (trigForm->tgisinternal)
19396 if (!TRIGGER_FOR_BEFORE(trigForm->tgtype) &&
19397 !TRIGGER_FOR_AFTER(trigForm->tgtype))
19398 elog(
ERROR,
"unexpected trigger \"%s\" found",
19414 partition, parent);
19416 partition, parent);
19423 if (trigForm->tgattr.dim1 > 0)
19427 for (
i = 0;
i < trigForm->tgattr.dim1;
i++)
19432 trigForm->tgattr.values[
i] - 1);
19439 if (trigForm->tgnargs > 0)
19446 elog(
ERROR,
"tgargs is null for trigger \"%s\" in partition \"%s\"",
19451 for (
int i = 0;
i < trigForm->tgnargs;
i++)
19454 p += strlen(p) + 1;
19464 trigStmt->
args = trigargs;
19465 trigStmt->
row =
true;
19466 trigStmt->
timing = trigForm->tgtype & TRIGGER_TYPE_TIMING_MASK;
19467 trigStmt->
events = trigForm->tgtype & TRIGGER_TYPE_EVENT_MASK;
19471 trigStmt->
deferrable = trigForm->tgdeferrable;
19477 trigForm->tgfoid, trigForm->oid, qual,
19478 false,
true, trigForm->tgenabled);
19514 Oid defaultPartOid;
19541 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19542 errmsg(
"cannot detach partitions concurrently when a default partition exists")));
19584 char *parentrelname;
19646 if (partRel != NULL)
19647 elog(
WARNING,
"dangling partition \"%s\" remains, can't fix",
19650 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19651 errmsg(
"partitioned table \"%s\" was removed concurrently",
19654 if (partRel == NULL)
19656 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19657 errmsg(
"partition \"%s\" was removed concurrently", partrelname)));
19681 Oid defaultPartOid)
19687 Datum new_val[Natts_pg_class];
19688 bool new_null[Natts_pg_class],
19689 new_repl[Natts_pg_class];
19719 Oid insertTriggerOid,
19728 if (conform->contype != CONSTRAINT_FOREIGN ||
19744 &insertTriggerOid, &updateTriggerOid);
19758 fkconstraint->
contype = CONSTRAINT_FOREIGN;
19760 fkconstraint->
deferrable = conform->condeferrable;
19763 fkconstraint->
pktable = NULL;
19776 fkconstraint, fk->
conoid,
19800 ConstraintRelationId,
19810 foreach(cell, indexes)
19839 elog(
ERROR,
"cache lookup failed for relation %u",
19844 memset(new_val, 0,
sizeof(new_val));
19845 memset(new_null,
false,
sizeof(new_null));
19846 memset(new_repl,
false,
sizeof(new_repl));
19847 new_val[Anum_pg_class_relpartbound - 1] = (
Datum) 0;
19848 new_null[Anum_pg_class_relpartbound - 1] =
true;
19849 new_repl[Anum_pg_class_relpartbound - 1] =
true;
19851 new_val, new_null, new_repl);
19865 if (!attr->attisdropped && attr->attidentity)
19899 if (partRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
19905 foreach(cell, children)
19956 List *constraintExpr;
20012 true, NULL, 1, &skey);
20038 RelationRelationId,
20077 if (!
state->lockedParentTbl)
20080 state->lockedParentTbl =
true;
20103 if (classform->relkind != RELKIND_PARTITIONED_INDEX &&
20104 classform->relkind != RELKIND_INDEX)
20106 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
20141 state.lockedParentTbl =
false;
20149 (
errcode(ERRCODE_UNDEFINED_OBJECT),
20150 errmsg(
"index \"%s\" does not exist",
name->relname)));
20162 currParent = partIdx->
rd_rel->relispartition ?
20183 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20184 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20187 errdetail(
"Index \"%s\" is already attached to another index.",
20195 if (partDesc->
oids[
i] ==
state.partitionOid)
20203 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20204 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20207 errdetail(
"Index \"%s\" is not an index on any partition of table \"%s\".",
20224 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
20225 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20228 errdetail(
"The index definitions do not match.")));
20243 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
20244 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20247 errdetail(
"The index \"%s\" belongs to a constraint in table \"%s\" but no constraint exists for index \"%s\".",
20257 if (parentIdx->
rd_index->indisprimary)
20292 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20293 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20296 errdetail(
"Another index is already attached for partition \"%s\".",
20314 bool updated =
false;
20316 Assert(partedIdx->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX);
20338 elog(
ERROR,
"cache lookup failed for index %u", inhForm->inhrelid);
20340 if (indexForm->indisvalid)
20363 elog(
ERROR,
"cache lookup failed for index %u",
20367 indexForm->indisvalid =
true;
20380 if (updated && partedIdx->
rd_rel->relispartition)
20416 if (!att->attnotnull)
20418 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
20419 errmsg(
"invalid primary key definition"),
20420 errdetail(
"Column \"%s\" of relation \"%s\" is not marked NOT NULL.",
20469 constraints =
lappend_oid(constraints, constrForm->oid);
20475 return constraints;
20491 foreach(cell, constraints)
20501 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
20537 if (compression == NULL || strcmp(compression,
"default") == 0)
20554 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20555 errmsg(
"column data type %s does not support compression",
20561 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20562 errmsg(
"invalid compression method \"%s\"", compression)));
20576 cstorage = TYPSTORAGE_PLAIN;
20578 cstorage = TYPSTORAGE_EXTERNAL;
20580 cstorage = TYPSTORAGE_EXTENDED;
20582 cstorage = TYPSTORAGE_MAIN;
20587 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20588 errmsg(
"invalid storage type \"%s\"",
20597 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20598 errmsg(
"column data type %s can only have storage PLAIN",
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)
#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)
Bitmapset * bms_add_member(Bitmapset *a, int x)
void FlushRelationBuffers(Relation rel)
#define TextDatumGetCString(d)
#define InvalidSubTransactionId
#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)
ObjectClass getObjectClass(const ObjectAddress *object)
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
@ OCLASS_PUBLICATION_NAMESPACE
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)
List * AddRelationNotNullConstraints(Relation rel, List *constraints, List *old_notnulls)
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)
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)
bool CheckIndexCompatible(Oid oldId, const char *accessMethodName, const List *attributeList, const List *exclusionOpNames, bool isWithoutOverlaps)
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
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)
#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)
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)
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)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
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
#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)
HeapTuple findNotNullConstraint(Oid relid, const char *colname)
bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)
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 conPeriod, bool is_internal)
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)
List * RelationGetNotNullConstraints(Oid relid, bool cooked)
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 AdjustNotNullInheritance(Oid relid, Bitmapset *columns, int count)
HeapTuple findNotNullConstraintAttnum(Oid relid, AttrNumber attnum)
void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, Oid newNspId, bool isType, ObjectAddresses *objsMoved)
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
AttrNumber extractNotNullColumn(HeapTuple constrTup)
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 get_index_constraint(Oid indexId)
Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
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)
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 list_nth_node(type, list, n)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make1_int(x1)
#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)
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
@ INDEX_ATTR_BITMAP_PRIMARY_KEY
@ INDEX_ATTR_BITMAP_IDENTITY_KEY
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
AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS]
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
TupleTableSlot * tg_trigslot
bool has_generated_stored
struct AttrMissing * missing
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 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)
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 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)
static ObjectAddress ATExecDropNotNull(Relation rel, const char *colName, bool recurse, LOCKMODE lockmode)
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 ObjectAddress ATExecSetNotNull(List **wqueue, Relation rel, char *constrname, char *colName, bool recurse, bool recursing, List **readyRels, LOCKMODE lockmode)
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 ObjectAddress ATExecSetAttNotNull(List **wqueue, Relation rel, const char *colName, LOCKMODE lockmode)
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 verifyPartitionIndexNotNull(IndexInfo *iinfo, Relation partIdx)
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 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 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 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 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 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 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 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 ObjectAddress ATAddCheckNNConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *constr, bool recurse, bool recursing, bool is_readd, LOCKMODE lockmode)
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 ObjectAddress dropconstraint_internal(Relation rel, HeapTuple constraintTup, DropBehavior behavior, bool recurse, bool recursing, bool missing_ok, List **readyRels, LOCKMODE lockmode)
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 ATInheritAdjustNotNulls(Relation parent_rel, Relation child_rel, int inhcount)
static void AttachPartitionEnsureIndexes(List **wqueue, Relation rel, Relation attachrel)
static void StoreCatalogInheritance(Oid relationId, List *supers, bool child_is_partition)
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)
static void ATPrepAddPrimaryKey(List **wqueue, Relation rel, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
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 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)
static bool set_attnotnull(List **wqueue, Relation rel, AttrNumber attnum, bool recurse, 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 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 ATExecDropConstraint(Relation rel, const char *constrName, DropBehavior behavior, bool recurse, bool missing_ok, LOCKMODE lockmode)
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 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 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 List * MergeAttributes(List *columns, const List *supers, char relpersistence, bool is_partition, List **supconstr, List **supnotnulls)
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
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)
Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid, bool isImplicitArray, bool errorOnTableType, ObjectAddresses *objsMoved)
void checkDomainOwner(HeapTuple tup)
void SwitchToUntrustedUser(Oid userid, UserContext *context)
void RestoreUserContext(UserContext *context)
void ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
#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)