100#include "utils/fmgroids.h"
167#define AT_NUM_PASSES (AT_PASS_MISC + 1)
266 gettext_noop(
"sequence \"%s\" does not exist, skipping"),
268 gettext_noop(
"Use DROP SEQUENCE to remove a sequence.")},
277 gettext_noop(
"materialized view \"%s\" does not exist"),
278 gettext_noop(
"materialized view \"%s\" does not exist, skipping"),
280 gettext_noop(
"Use DROP MATERIALIZED VIEW to remove a materialized view.")},
282 ERRCODE_UNDEFINED_OBJECT,
287 {RELKIND_COMPOSITE_TYPE,
288 ERRCODE_UNDEFINED_OBJECT,
293 {RELKIND_FOREIGN_TABLE,
294 ERRCODE_UNDEFINED_OBJECT,
296 gettext_noop(
"foreign table \"%s\" does not exist, skipping"),
298 gettext_noop(
"Use DROP FOREIGN TABLE to remove a foreign table.")},
299 {RELKIND_PARTITIONED_TABLE,
305 {RELKIND_PARTITIONED_INDEX,
306 ERRCODE_UNDEFINED_OBJECT,
311 {
'\0', 0, NULL, NULL, NULL, NULL}
329#define ATT_TABLE 0x0001
330#define ATT_VIEW 0x0002
331#define ATT_MATVIEW 0x0004
332#define ATT_INDEX 0x0008
333#define ATT_COMPOSITE_TYPE 0x0010
334#define ATT_FOREIGN_TABLE 0x0020
335#define ATT_PARTITIONED_INDEX 0x0040
336#define ATT_SEQUENCE 0x0080
337#define ATT_PARTITIONED_TABLE 0x0100
366#define child_dependency_type(child_is_partition) \
367 ((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
375 bool is_partition,
List **supconstr,
383 bool child_is_partition);
386 bool child_is_partition);
403 Oid ReferencedParentDelTrigger,
404 Oid ReferencedParentUpdTrigger,
405 Oid ReferencingParentInsTrigger,
406 Oid ReferencingParentUpdTrigger);
415 bool deferrable,
bool initdeferred,
421 Oid ReferencedParentDelTrigger,
422 Oid ReferencedParentUpdTrigger,
423 Oid ReferencingParentInsTrigger,
424 Oid ReferencingParentUpdTrigger);
433 bool recurse,
bool recursing,
LOCKMODE lockmode);
438 bool recurse,
bool recursing,
LOCKMODE lockmode);
440 HeapTuple contuple,
bool recurse,
bool recursing,
447 Oid *opclasses,
bool *pk_has_without_overlaps);
449 int numattrs,
int16 *attnums,
450 bool with_period,
Oid *opclasses,
451 bool *pk_has_without_overlaps);
457 Oid pkindOid,
Oid constraintOid,
bool hasperiod);
463 bool recurse,
bool recursing,
LOCKMODE lockmode,
495 bool recurse,
bool recursing,
505 bool is_valid,
bool queue_validation);
507 char *conName,
char *colName,
508 bool recurse,
bool recursing,
512 List *testConstraint,
List *provenConstraint);
518 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
520 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
522 bool recurse,
bool recursing);
538 bool recurse,
bool recursing,
551 Constraint *newConstraint,
bool recurse,
bool is_readd,
559 bool recurse,
bool recursing,
bool is_readd,
563 bool recurse,
bool recursing,
566 int numfksetcols,
int16 *fksetcolsattnums,
569 char *constraintname,
574 Oid *pfeqoperators,
Oid *ppeqoperators,
575 Oid *ffeqoperators,
int numfkdelsetcols,
576 int16 *fkdelsetcols,
bool is_internal,
581 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
582 int numfkdelsetcols,
int16 *fkdelsetcols,
584 Oid parentDelTrigger,
Oid parentUpdTrigger,
589 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
590 int numfkdelsetcols,
int16 *fkdelsetcols,
591 bool old_check_ok,
LOCKMODE lockmode,
592 Oid parentInsTrigger,
Oid parentUpdTrigger,
602 Oid parentInsTrigger,
Oid parentUpdTrigger,
603 Oid *insertTrigOid,
Oid *updateTrigOid);
607 Oid parentDelTrigger,
Oid parentUpdTrigger,
608 Oid *deleteTrigOid,
Oid *updateTrigOid);
612 Oid parentConstrOid,
int numfks,
615 Oid parentInsTrigger,
616 Oid parentUpdTrigger,
619 Oid partConstrOid,
Oid parentConstrOid,
620 Oid parentInsTrigger,
Oid parentUpdTrigger,
623 Oid conoid,
Oid conrelid);
625 Oid confrelid,
Oid conrelid);
628 Oid *deleteTriggerOid,
629 Oid *updateTriggerOid);
632 Oid *insertTriggerOid,
633 Oid *updateTriggerOid);
636 bool missing_ok,
LOCKMODE lockmode);
639 bool recurse,
bool recursing,
640 bool missing_ok,
LOCKMODE lockmode);
643 bool recurse,
bool recursing,
661 const char *conname);
667 Oid oldOwnerId,
Oid newOwnerId);
678 const char *tablespacename,
LOCKMODE lockmode);
685 char fires_when,
bool skip_system,
bool recurse,
688 char fires_when,
LOCKMODE lockmode);
707 Oid oldRelOid,
void *
arg);
712 List **partexprs,
Oid *partopclass,
Oid *partcollation,
716 bool expect_detached);
722 List *partConstraint,
723 bool validate_default);
730 bool concurrent,
Oid defaultPartOid);
779 List *old_constraints;
782 List *cookedDefaults;
804 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
806 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
807 errmsg(
"ON COMMIT can only be used on temporary tables")));
809 if (
stmt->partspec != NULL)
811 if (relkind != RELKIND_RELATION)
812 elog(
ERROR,
"unexpected relkind: %d", (
int) relkind);
814 relkind = RELKIND_PARTITIONED_TABLE;
820 if (relkind == RELKIND_PARTITIONED_TABLE &&
821 stmt->relation->relpersistence == RELPERSISTENCE_UNLOGGED)
823 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
824 errmsg(
"partitioned tables cannot be unlogged")));
840 if (
stmt->relation->relpersistence == RELPERSISTENCE_TEMP
843 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
844 errmsg(
"cannot create temporary table within security-restricted operation")));
867 foreach(listptr,
stmt->inhRelations)
879 (
errcode(ERRCODE_DUPLICATE_TABLE),
880 errmsg(
"relation \"%s\" would be inherited from more than once",
890 if (
stmt->tablespacename)
896 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
897 errmsg(
"cannot specify default tablespace for partitioned relations")));
899 else if (
stmt->partbound)
925 if (tablespaceId == GLOBALTABLESPACE_OID)
927 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
928 errmsg(
"only shared relations can be placed in pg_global tablespace")));
945 case RELKIND_PARTITIONED_TABLE:
952 if (
stmt->ofTypename)
972 stmt->relation->relpersistence,
973 stmt->partbound != NULL,
974 &old_constraints, &old_notnulls);
993 cookedDefaults =
NIL;
996 foreach(listptr,
stmt->tableElts)
1011 rawDefaults =
lappend(rawDefaults, rawEnt);
1020 cooked->
name = NULL;
1028 cookedDefaults =
lappend(cookedDefaults, cooked);
1037 if (
stmt->accessMethod != NULL)
1039 Assert(RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE);
1042 else if (RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE)
1044 if (
stmt->partbound)
1050 if (RELKIND_HAS_TABLE_AM(relkind) && !
OidIsValid(accessMethodId))
1071 stmt->relation->relpersistence,
1110 true,
true,
false, queryString);
1118 if (
stmt->partbound)
1135 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1137 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1138 errmsg(
"\"%s\" is not partitioned",
1176 NULL,
false,
false);
1231 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1232 errmsg(
"cannot partition using more than %d columns",
1244 partattrs, &partexprs, partopclass,
1245 partcollation,
stmt->partspec->strategy);
1249 partopclass, partcollation);
1262 if (
stmt->partbound)
1276 foreach(cell, idxlist)
1283 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1287 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1288 errmsg(
"cannot create foreign partition of partitioned table \"%s\"",
1290 errdetail(
"Table \"%s\" contains indexes that are unique.",
1304 attmap, &constraintOid);
1311 false,
false,
false,
false,
false);
1339 if (
stmt->constraints)
1341 true,
true,
false, queryString);
1419 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1420 errmsg(
"too many array dimensions"));
1424 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1425 errmsg(
"column \"%s\" cannot be declared SETOF",
1429 atttypid, atttypmod, attdim);
1438 att->attinhcount = entry->
inhcount;
1439 att->attidentity = entry->
identity;
1443 att->attstorage = entry->
storage;
1468 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1474 (
errmsg(
"schema \"%s\" does not exist, skipping",
1482 if (rentry->
kind == rightkind)
1512 if (rentry->
kind == rightkind)
1517 if (wentry->
kind == wrongkind)
1522 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1553 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1554 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1557 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1558 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1571 relkind = RELKIND_RELATION;
1575 relkind = RELKIND_INDEX;
1579 relkind = RELKIND_SEQUENCE;
1583 relkind = RELKIND_VIEW;
1587 relkind = RELKIND_MATVIEW;
1591 relkind = RELKIND_FOREIGN_TABLE;
1595 elog(
ERROR,
"unrecognized drop object type: %d",
1624 state.expected_relkind = relkind;
1647 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1659 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1661 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1662 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1672 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1674 state.heap_lockmode,
1678 obj.
classId = RelationRelationId;
1706 bool invalid_system_index =
false;
1741 is_partition = classform->relispartition;
1744 state->actual_relkind = classform->relkind;
1745 state->actual_relpersistence = classform->relpersistence;
1755 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1757 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1764 state->expected_relkind);
1779 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1793 indisvalid = indexform->indisvalid;
1798 invalid_system_index =
true;
1804 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1805 errmsg(
"permission denied: \"%s\" is a system catalog",
1819 relOid != oldRelOid)
1832 if (is_partition && relOid != oldRelOid)
1866 foreach(cell,
stmt->relations)
1870 bool recurse = rv->
inh;
1896 relids_logged =
lappend_oid(relids_logged, myrelid);
1905 foreach(child, children)
1944 relids_logged =
lappend_oid(relids_logged, childrelid);
1947 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1949 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1950 errmsg(
"cannot truncate only a partitioned table"),
1951 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1955 stmt->behavior,
stmt->restart_seqs,
false);
1982 List *relids_logged,
1984 bool run_as_table_owner)
1988 HTAB *ft_htab = NULL;
2014 if (newrelids ==
NIL)
2017 foreach(cell, newrelids)
2024 (
errmsg(
"truncate cascades to table \"%s\"",
2034 relids_logged =
lappend_oid(relids_logged, relid);
2044#ifdef USE_ASSERT_CHECKING
2065 foreach(seqcell, seqlist)
2099 resultRelInfo = resultRelInfos;
2120 resultRelInfo = resultRelInfos;
2125 if (run_as_table_owner)
2129 if (run_as_table_owner)
2144 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2154 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2165 memset(&hctl, 0,
sizeof(
HASHCTL));
2170 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2230 toast_relid = rel->
rd_rel->reltoastrelid;
2237 toastrel->
rd_rel->relpersistence);
2283 foreach(cell, seq_relids)
2297 if (relids_logged !=
NIL)
2306 foreach(cell, relids_logged)
2329 resultRelInfo = resultRelInfos;
2334 if (run_as_table_owner)
2338 if (run_as_table_owner)
2377 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2384 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2385 errmsg(
"cannot truncate foreign table \"%s\"",
2388 else if (reltuple->relkind != RELKIND_RELATION &&
2389 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2391 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2404 (relid != LargeObjectRelationId &&
2405 relid != LargeObjectMetadataRelationId)))
2407 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2408 errmsg(
"permission denied: \"%s\" is a system catalog",
2444 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2445 errmsg(
"cannot truncate temporary tables of other sessions")));
2463 case TYPSTORAGE_PLAIN:
2465 case TYPSTORAGE_EXTERNAL:
2467 case TYPSTORAGE_EXTENDED:
2469 case TYPSTORAGE_MAIN:
2545 bool is_partition,
List **supconstr,
List **supnotnulls)
2550 bool have_bogus_defaults =
false;
2552 static Node bogus_marker = {0};
2569 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2570 errmsg(
"tables can have at most %d columns",
2587 for (
int coldefpos = 0; coldefpos <
list_length(columns); coldefpos++)
2591 if (!is_partition && coldef->
typeName == NULL)
2600 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2601 errmsg(
"column \"%s\" does not exist",
2606 for (
int restpos = coldefpos + 1; restpos <
list_length(columns);)
2626 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2627 errmsg(
"column \"%s\" specified more than once",
2642 saved_columns = columns;
2658 List *inherited_defaults;
2659 List *cols_with_defaults;
2680 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !is_partition)
2682 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2683 errmsg(
"cannot inherit from partitioned table \"%s\"",
2685 if (relation->
rd_rel->relispartition && !is_partition)
2687 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2688 errmsg(
"cannot inherit from partition \"%s\"",
2691 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2692 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2693 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2695 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2696 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2704 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2705 relpersistence == RELPERSISTENCE_TEMP)
2707 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2708 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2712 if (relpersistence != RELPERSISTENCE_TEMP &&
2713 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2715 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2717 ?
"cannot inherit from temporary relation \"%s\""
2718 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2724 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2726 ?
"cannot inherit from temporary relation of another session"
2727 :
"cannot create as partition of temporary relation of another session")));
2738 constr = tupleDesc->
constr;
2748 inherited_defaults = cols_with_defaults =
NIL;
2764 char *attributeName =
NameStr(attribute->attname);
2772 if (attribute->attisdropped)
2779 attribute->atttypmod, attribute->attcollation);
2780 newdef->
storage = attribute->attstorage;
2781 newdef->
generated = attribute->attgenerated;
2792 newdef->
identity = attribute->attidentity;
2799 if (exist_attno > 0)
2806 newattmap->
attnums[parent_attno - 1] = exist_attno;
2821 inh_columns =
lappend(inh_columns, newdef);
2823 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2836 if (attribute->atthasdef)
2841 if (this_default == NULL)
2842 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2851 inherited_defaults =
lappend(inherited_defaults, this_default);
2852 cols_with_defaults =
lappend(cols_with_defaults, mergeddef);
2860 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2864 bool found_whole_row;
2878 if (found_whole_row)
2880 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2881 errmsg(
"cannot convert whole-row table reference"),
2882 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2898 have_bogus_defaults =
true;
2915 bool found_whole_row;
2918 if (check[
i].ccnoinherit)
2932 if (found_whole_row)
2934 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2935 errmsg(
"cannot convert whole-row table reference"),
2936 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2941 check[
i].ccenforced);
2953 nn->attnum = newattmap->
attnums[nn->attnum - 1];
2955 nnconstraints =
lappend(nnconstraints, nn);
2974 if (inh_columns !=
NIL)
2976 int newcol_attno = 0;
2978 foreach(lc, columns)
2981 char *attributeName = newdef->
colname;
2996 if (exist_attno > 0)
3008 inh_columns =
lappend(inh_columns, newdef);
3012 columns = inh_columns;
3020 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
3021 errmsg(
"tables can have at most %d columns",
3032 foreach(lc, saved_columns)
3057 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3058 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3062 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3063 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3070 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3071 errmsg(
"child column \"%s\" specifies generation expression",
3073 errhint(
"A child table column cannot be generated unless its parent column is.")));
3078 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3079 errmsg(
"column \"%s\" inherits from generated column of different kind",
3081 errdetail(
"Parent column is %s, child column is %s.",
3082 coldef->
generated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL",
3083 restdef->
generated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL")));
3107 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3108 errmsg(
"column \"%s\" does not exist",
3117 if (have_bogus_defaults)
3119 foreach(lc, columns)
3127 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3128 errmsg(
"column \"%s\" inherits conflicting generation expressions",
3130 errhint(
"To resolve the conflict, specify a generation expression explicitly.")));
3133 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3134 errmsg(
"column \"%s\" inherits conflicting default values",
3136 errhint(
"To resolve the conflict, specify a default explicitly.")));
3141 *supconstr = constraints;
3142 *supnotnulls = nnconstraints;
3169 foreach(lc, constraints)
3185 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3186 errmsg(
"too many inheritance parents"));
3203 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3214 newcon->
expr = expr;
3218 return lappend(constraints, newcon);
3245 char *attributeName = newdef->
colname;
3254 if (exist_attno == newcol_attno)
3256 (
errmsg(
"merging column \"%s\" with inherited definition",
3260 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
3261 errdetail(
"User-specified column moved to the position of the inherited column.")));
3270 if (inhtypeid != newtypeid || inhtypmod != newtypmod)
3272 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3273 errmsg(
"column \"%s\" has a type conflict",
3284 if (inhcollid != newcollid)
3286 (
errcode(ERRCODE_COLLATION_MISMATCH),
3287 errmsg(
"column \"%s\" has a collation conflict",
3306 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3307 errmsg(
"column \"%s\" has a storage parameter conflict",
3322 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3323 errmsg(
"column \"%s\" has a compression method conflict",
3351 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3352 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3356 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3357 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3364 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3365 errmsg(
"child column \"%s\" specifies generation expression",
3367 errhint(
"A child table column cannot be generated unless its parent column is.")));
3372 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3373 errmsg(
"column \"%s\" inherits from generated column of different kind",
3375 errdetail(
"Parent column is %s, child column is %s.",
3376 inhdef->
generated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL",
3377 newdef->
generated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL")));
3417 char *attributeName = newdef->
colname;
3427 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
3436 if (prevtypeid != newtypeid || prevtypmod != newtypmod)
3438 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3439 errmsg(
"inherited column \"%s\" has a type conflict",
3450 if (prevcollid != newcollid)
3452 (
errcode(ERRCODE_COLLATION_MISMATCH),
3453 errmsg(
"inherited column \"%s\" has a collation conflict",
3466 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3467 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
3482 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3483 errmsg(
"column \"%s\" has a compression method conflict",
3494 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3495 errmsg(
"inherited column \"%s\" has a generation conflict",
3505 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3506 errmsg(
"too many inheritance parents"));
3519 bool child_is_partition)
3545 foreach(entry, supers)
3550 child_is_partition);
3564 bool child_is_partition)
3575 parentobject.
classId = RelationRelationId;
3578 childobject.
classId = RelationRelationId;
3612 foreach(lc, columns)
3661 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3664 if (classtuple->relhassubclass != relhassubclass)
3666 classtuple->relhassubclass = relhassubclass;
3692 Oid oldTableSpaceId;
3698 oldTableSpaceId = rel->
rd_rel->reltablespace;
3699 if (newTableSpaceId == oldTableSpaceId ||
3709 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3710 errmsg(
"cannot move system relation \"%s\"",
3714 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3716 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3717 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3725 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3726 errmsg(
"cannot move temporary tables of other sessions")));
3748 Oid newTableSpaceId,
3764 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3772 rd_rel->relfilenode = newRelFilenumber;
3780 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3782 rd_rel->reltablespace);
3794 char relkind = classform->relkind;
3796 if (classform->reloftype && !recursing)
3798 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3799 errmsg(
"cannot rename column of typed table")));
3808 if (relkind != RELKIND_RELATION &&
3809 relkind != RELKIND_VIEW &&
3810 relkind != RELKIND_MATVIEW &&
3811 relkind != RELKIND_COMPOSITE_TYPE &&
3812 relkind != RELKIND_INDEX &&
3813 relkind != RELKIND_PARTITIONED_INDEX &&
3814 relkind != RELKIND_FOREIGN_TABLE &&
3815 relkind != RELKIND_PARTITIONED_TABLE)
3817 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3818 errmsg(
"cannot rename columns of relation \"%s\"",
3830 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3831 errmsg(
"permission denied: \"%s\" is a system catalog",
3832 NameStr(classform->relname))));
3842 const char *oldattname,
3843 const char *newattname,
3846 int expected_parents,
3890 forboth(lo, child_oids, li, child_numparents)
3895 if (childrelid == myrelid)
3898 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3909 if (expected_parents == 0 &&
3912 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3913 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3918 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3927 foreach(lo, child_oids)
3936 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3937 errmsg(
"column \"%s\" does not exist",
3941 attnum = attform->attnum;
3944 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3945 errmsg(
"cannot rename system column \"%s\"",
3957 if (attform->attinhcount > expected_parents)
3959 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3960 errmsg(
"cannot rename inherited column \"%s\"",
4021 (
errmsg(
"relation \"%s\" does not exist, skipping",
4022 stmt->relation->relname)));
4030 stmt->relation->inh,
4046 const char *oldconname,
4047 const char *newconname,
4050 int expected_parents)
4058 Assert(!myrelid || !mytypid);
4079 elog(
ERROR,
"cache lookup failed for constraint %u",
4084 (con->contype == CONSTRAINT_CHECK ||
4085 con->contype == CONSTRAINT_NOTNULL) &&
4098 forboth(lo, child_oids, li, child_numparents)
4103 if (childrelid == myrelid)
4111 if (expected_parents == 0 &&
4114 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4115 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
4119 if (con->coninhcount > expected_parents)
4121 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4122 errmsg(
"cannot rename inherited constraint \"%s\"",
4127 && (con->contype == CONSTRAINT_PRIMARY
4128 || con->contype == CONSTRAINT_UNIQUE
4129 || con->contype == CONSTRAINT_EXCLUSION))
4167 elog(
ERROR,
"cache lookup failed for type %u", typid);
4182 (
errmsg(
"relation \"%s\" does not exist, skipping",
4183 stmt->relation->relname)));
4193 stmt->relation->inh),
4234 (
errmsg(
"relation \"%s\" does not exist, skipping",
4235 stmt->relation->relname)));
4246 obj_is_index = (relkind == RELKIND_INDEX ||
4247 relkind == RELKIND_PARTITIONED_INDEX);
4248 if (obj_is_index || is_index_stmt == obj_is_index)
4252 is_index_stmt = obj_is_index;
4296 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4302 (
errcode(ERRCODE_DUPLICATE_TABLE),
4303 errmsg(
"relation \"%s\" already exists",
4313 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4314 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
4336 newrelname, namespaceId);
4341 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4342 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
4373 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4415 int expected_refcnt;
4420 (
errcode(ERRCODE_OBJECT_IN_USE),
4422 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4425 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4426 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4429 (
errcode(ERRCODE_OBJECT_IN_USE),
4431 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4456 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4457 errmsg(
"cannot alter temporary tables of other sessions")));
4569 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4850 elog(
ERROR,
"unrecognized alter table type: %d",
4858 if (cmd_lockmode > lockmode)
4859 lockmode = cmd_lockmode;
4884 ATPrepCmd(&wqueue, rel, cmd, recurse,
false, lockmode, context);
4908 bool recurse,
bool recursing,
LOCKMODE lockmode,
4921 if (rel->
rd_rel->relispartition &&
4925 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4926 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4928 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
5154 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5155 errmsg(
"cannot change persistence setting twice")));
5171 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5172 errmsg(
"cannot have multiple SET ACCESS METHOD subcommands")));
5291 elog(
ERROR,
"unrecognized alter table type: %d",
5325 foreach(ltab, *wqueue)
5341 foreach(lcmd, subcmds)
5344 lockmode, pass, context);
5363 foreach(ltab, *wqueue)
5372 if (((tab->
relkind == RELKIND_RELATION ||
5373 tab->
relkind == RELKIND_PARTITIONED_TABLE) &&
5375 tab->
relkind == RELKIND_MATVIEW)
5397 lockmode, cur_pass, context);
5425 cmd->
recurse,
false, lockmode);
5478 cmd->
recurse,
false, lockmode);
5483 true,
true, lockmode);
5545 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
5556 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
5557 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
5666 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
5678 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5690 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5698 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5703 elog(
ERROR,
"unrecognized alter table type: %d",
5763 foreach(lc, beforeStmts)
5772 foreach(lc, atstmt->
cmds)
5824 if (pass < cur_pass)
5827 elog(
ERROR,
"ALTER TABLE scheduling failure: too late for pass %d",
5830 else if (pass > cur_pass)
5847 elog(
ERROR,
"ALTER TABLE scheduling failure: bogus item for pass %d",
5868 foreach(ltab, *wqueue)
5873 if (!RELKIND_HAS_STORAGE(tab->
relkind))
5914 Oid NewAccessMethod;
5927 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5928 errmsg(
"cannot rewrite system relation \"%s\"",
5933 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5934 errmsg(
"cannot rewrite table \"%s\" used as a catalog table",
5945 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5946 errmsg(
"cannot rewrite temporary tables of other sessions")));
5955 NewTableSpace = OldHeap->
rd_rel->reltablespace;
5964 NewAccessMethod = OldHeap->
rd_rel->relam;
6007 persistence, lockmode);
6066 foreach(lc, seqlist)
6082 foreach(ltab, *wqueue)
6089 if (!RELKIND_HAS_STORAGE(tab->
relkind))
6128 foreach(ltab, *wqueue)
6156 bool needscan =
false;
6157 List *notnull_attrs;
6158 List *notnull_virtual_attrs;
6223 elog(
ERROR,
"unrecognized constraint type: %d",
6243 notnull_attrs = notnull_virtual_attrs =
NIL;
6256 for (
i = 0;
i < newTupDesc->
natts;
i++)
6265 if (wholeatt->attgenerated != ATTRIBUTE_GENERATED_VIRTUAL)
6266 notnull_attrs =
lappend_int(notnull_attrs, wholeatt->attnum);
6268 notnull_virtual_attrs =
lappend_int(notnull_virtual_attrs,
6272 if (notnull_attrs || notnull_virtual_attrs)
6276 if (newrel || needscan)
6294 if (notnull_virtual_attrs !=
NIL)
6369 for (
i = 0;
i < newTupDesc->
natts;
i++)
6405 foreach(lc, dropped_attrs)
6459 insertslot = newslot;
6468 insertslot = oldslot;
6481 (
errcode(ERRCODE_NOT_NULL_VIOLATION),
6482 errmsg(
"column \"%s\" of relation \"%s\" contains null values",
6489 if (notnull_virtual_attrs !=
NIL)
6495 notnull_virtual_attrs);
6501 errcode(ERRCODE_NOT_NULL_VIOLATION),
6502 errmsg(
"column \"%s\" of relation \"%s\" contains null values",
6518 (
errcode(ERRCODE_CHECK_VIOLATION),
6519 errmsg(
"check constraint \"%s\" of relation \"%s\" is violated by some row",
6529 elog(
ERROR,
"unrecognized constraint type: %d",
6534 if (partqualstate && !
ExecCheck(partqualstate, econtext))
6538 (
errcode(ERRCODE_CHECK_VIOLATION),
6539 errmsg(
"updated partition constraint for default partition \"%s\" would be violated by some row",
6544 (
errcode(ERRCODE_CHECK_VIOLATION),
6545 errmsg(
"partition constraint of relation \"%s\" is violated by some row",
6553 ti_options, bistate);
6592 foreach(ltab, *wqueue)
6595 if (tab->
relid == relid)
6614 *wqueue =
lappend(*wqueue, tab);
6626 return "ADD COLUMN";
6629 return "ALTER COLUMN ... SET DEFAULT";
6631 return "ALTER COLUMN ... DROP NOT NULL";
6633 return "ALTER COLUMN ... SET NOT NULL";
6635 return "ALTER COLUMN ... SET EXPRESSION";
6637 return "ALTER COLUMN ... DROP EXPRESSION";
6639 return "ALTER COLUMN ... SET STATISTICS";
6641 return "ALTER COLUMN ... SET";
6643 return "ALTER COLUMN ... RESET";
6645 return "ALTER COLUMN ... SET STORAGE";
6647 return "ALTER COLUMN ... SET COMPRESSION";
6649 return "DROP COLUMN";
6657 return "ADD CONSTRAINT";
6659 return "ALTER CONSTRAINT";
6661 return "VALIDATE CONSTRAINT";
6663 return "DROP CONSTRAINT";
6667 return "ALTER COLUMN ... SET DATA TYPE";
6669 return "ALTER COLUMN ... OPTIONS";
6673 return "CLUSTER ON";
6675 return "SET WITHOUT CLUSTER";
6677 return "SET ACCESS METHOD";
6679 return "SET LOGGED";
6681 return "SET UNLOGGED";
6683 return "SET WITHOUT OIDS";
6685 return "SET TABLESPACE";
6693 return "ENABLE TRIGGER";
6695 return "ENABLE ALWAYS TRIGGER";
6697 return "ENABLE REPLICA TRIGGER";
6699 return "DISABLE TRIGGER";
6701 return "ENABLE TRIGGER ALL";
6703 return "DISABLE TRIGGER ALL";
6705 return "ENABLE TRIGGER USER";
6707 return "DISABLE TRIGGER USER";
6709 return "ENABLE RULE";
6711 return "ENABLE ALWAYS RULE";
6713 return "ENABLE REPLICA RULE";
6715 return "DISABLE RULE";
6719 return "NO INHERIT";
6725 return "REPLICA IDENTITY";
6727 return "ENABLE ROW SECURITY";
6729 return "DISABLE ROW SECURITY";
6731 return "FORCE ROW SECURITY";
6733 return "NO FORCE ROW SECURITY";
6737 return "ATTACH PARTITION";
6739 return "DETACH PARTITION";
6741 return "DETACH PARTITION ... FINALIZE";
6743 return "MERGE PARTITIONS";
6745 return "SPLIT PARTITION";
6747 return "ALTER COLUMN ... ADD IDENTITY";
6749 return "ALTER COLUMN ... SET";
6751 return "ALTER COLUMN ... DROP IDENTITY";
6771 switch (rel->
rd_rel->relkind)
6773 case RELKIND_RELATION:
6776 case RELKIND_PARTITIONED_TABLE:
6782 case RELKIND_MATVIEW:
6788 case RELKIND_PARTITIONED_INDEX:
6791 case RELKIND_COMPOSITE_TYPE:
6794 case RELKIND_FOREIGN_TABLE:
6797 case RELKIND_SEQUENCE:
6806 if ((actual_target & allowed_targets) == 0)
6812 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6814 errmsg(
"ALTER action %s cannot be performed on relation \"%s\"",
6819 elog(
ERROR,
"invalid ALTER action attempted on relation \"%s\"",
6830 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6831 errmsg(
"permission denied: \"%s\" is a system catalog",
6852 if (recurse && rel->
rd_rel->relhassubclass)
6865 foreach(child, children)
6870 if (childrelid == relid)
6875 ATPrepCmd(wqueue, childrel, cmd,
false,
true, lockmode, context);
6891 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
6925 Assert(rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
6931 foreach(child, children)
6938 ATPrepCmd(wqueue, childrel, cmd,
true,
true, lockmode, context);
6965 const char *origTypeName)
6982 Anum_pg_depend_refclassid,
6986 Anum_pg_depend_refobjid,
7001 if (pg_depend->classid == TypeRelationId)
7010 origRelation, origTypeName);
7015 if (pg_depend->classid != RelationRelationId)
7034 if (pg_depend->objsubid > 0 && pg_depend->objsubid <= tupleDesc->
natts)
7039 for (
int attno = 1; attno <= tupleDesc->
natts; attno++)
7042 if (att->atttypid == typeOid && !att->attisdropped)
7063 if (RELKIND_HAS_STORAGE(rel->
rd_rel->relkind) ||
7064 RELKIND_HAS_PARTITIONS(rel->
rd_rel->relkind))
7068 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7069 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
7073 else if (origRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
7075 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7076 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
7080 else if (origRelation->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
7082 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7083 errmsg(
"cannot alter foreign table \"%s\" because column \"%s.%s\" uses its row type",
7089 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7090 errmsg(
"cannot alter table \"%s\" because column \"%s.%s\" uses its row type",
7102 origRelation, origTypeName);
7133 Anum_pg_class_reloftype,
7145 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
7146 errmsg(
"cannot alter type \"%s\" because it is the type of a typed table",
7148 errhint(
"Use ALTER ... CASCADE to alter the typed tables too.")));
7174 bool typeOk =
false;
7176 if (typ->typtype == TYPTYPE_COMPOSITE)
7182 typeOk = (typeRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
7193 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7194 errmsg(
"type %s is the row type of another table",
7196 errdetail(
"A typed table must use a stand-alone composite type created with CREATE TYPE.")));
7200 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7201 errmsg(
"type %s is not a composite type",
7225 if (rel->
rd_rel->reloftype && !recursing)
7227 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7228 errmsg(
"cannot add column to typed table")));
7230 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
7233 if (recurse && !is_view)
7252 bool if_not_exists = (*cmd)->missing_ok;
7275 if (rel->
rd_rel->relispartition && !recursing)
7277 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7278 errmsg(
"cannot add column to a partition")));
7303 if (ctypeId != childatt->atttypid ||
7304 ctypmod != childatt->atttypmod)
7306 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7307 errmsg(
"child table \"%s\" has different type for column \"%s\"",
7310 if (ccollid != childatt->attcollation)
7312 (
errcode(ERRCODE_COLLATION_MISMATCH),
7313 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
7321 &childatt->attinhcount))
7323 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
7324 errmsg(
"too many inheritance parents"));
7331 (
errmsg(
"merging definition of column \"%s\" for child \"%s\"",
7361 if (context != NULL && !recursing)
7380 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE &&
7383 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7384 errmsg(
"cannot recursively add identity column to table that has child tables")));
7390 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
7392 relkind = relform->relkind;
7395 newattnum = relform->relnatts + 1;
7398 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
7399 errmsg(
"tables can have at most %d columns",
7410 attribute->attnum = newattnum;
7424 relform->relnatts = newattnum;
7446 rawEnt->
attnum = attribute->attnum;
7455 false,
true,
false, NULL);
7493 if (RELKIND_HAS_STORAGE(relkind))
7495 bool has_domain_constraints;
7496 bool has_missing =
false;
7507 nve->
typeId = attribute->atttypid;
7509 defval = (
Expr *) nve;
7516 if (!defval && has_domain_constraints)
7522 baseTypeMod = attribute->atttypmod;
7529 attribute->atttypid,
7530 attribute->atttypmod,
7535 elog(
ERROR,
"failed to coerce base type to domain");
7547 newval->attnum = attribute->attnum;
7562 if (rel->
rd_rel->relkind == RELKIND_RELATION &&
7564 !has_domain_constraints &&
7595 if (colDef->
generated != ATTRIBUTE_GENERATED_VIRTUAL)
7628 if (children && !recurse)
7630 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7631 errmsg(
"column must be added to child tables too")));
7644 foreach(child, children)
7659 &childcmd, recurse,
true,
7660 lockmode, cur_pass, context);
7700 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7701 errmsg(
"column name \"%s\" conflicts with a system column name",
7708 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7709 errmsg(
"column \"%s\" of relation \"%s\" already exists, skipping",
7715 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7716 errmsg(
"column \"%s\" of relation \"%s\" already exists",
7732 myself.
classId = RelationRelationId;
7735 referenced.
classId = TypeRelationId;
7753 myself.
classId = RelationRelationId;
7756 referenced.
classId = CollationRelationId;
7788 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7789 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7797 if (!attTup->attnotnull)
7806 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7807 errmsg(
"cannot alter system column \"%s\"",
7810 if (attTup->attidentity)
7812 (
errcode(ERRCODE_SYNTAX_ERROR),
7813 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
7819 if (rel->
rd_rel->relispartition)
7826 parent_attnum =
get_attnum(parentId, colName);
7829 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7830 errmsg(
"column \"%s\" is marked NOT NULL in parent table",
7841 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation \"%s\"",
7869 bool is_valid,
bool queue_validation)
7874 Assert(!queue_validation || wqueue);
7883 if (attr->attisdropped)
7886 if (!attr->attnotnull)
7895 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
7903 attr->attnotnull =
true;
7910 if (queue_validation && wqueue &&
7942 bool recurse,
bool recursing,
LOCKMODE lockmode)
7950 bool is_no_inherit =
false;
7966 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7967 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7973 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7974 errmsg(
"cannot alter system column \"%s\"",
7982 bool changed =
false;
7987 if (conForm->connoinherit && recurse)
7989 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7990 errmsg(
"cannot change NO INHERIT status of NOT NULL constraint \"%s\" on relation \"%s\"",
8002 &conForm->coninhcount))
8004 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
8005 errmsg(
"too many inheritance parents"));
8008 else if (!conForm->conislocal)
8010 conForm->conislocal =
true;
8013 else if (!conForm->convalidated)
8020 recurse, recursing, lockmode);
8049 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
8051 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8052 errmsg(
"constraint must be added to child tables too"),
8053 errhint(
"Do not specify the ONLY keyword."));
8055 is_no_inherit =
true;
8066 colName,
"not_null",
8073 constraint->
conname = conName;
8077 false, !recursing,
false, NULL);
8104 recurse,
true, lockmode);
8134 nnulltest->argisrow =
false;
8140 (
errmsg_internal(
"existing constraints on column \"%s.%s\" are sufficient to prove that it does not contain nulls",
8167 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8168 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8174 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8175 errmsg(
"cannot alter system column \"%s\"",
8180 (
errcode(ERRCODE_SYNTAX_ERROR),
8181 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
8184 newDefault ? 0 :
errhint(
"Use %s instead.",
8185 "ALTER TABLE ... ALTER COLUMN ... DROP IDENTITY")));
8189 (
errcode(ERRCODE_SYNTAX_ERROR),
8190 errmsg(
"column \"%s\" of relation \"%s\" is a generated column",
8194 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... SET EXPRESSION") :
8196 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... DROP EXPRESSION") : 0)));
8208 newDefault != NULL);
8225 false,
true,
false, NULL);
8269 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing)
8279 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8280 if (ispartitioned && !recurse)
8282 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8283 errmsg(
"cannot add identity to a column of only the partitioned table"),
8284 errhint(
"Do not specify the ONLY keyword.")));
8286 if (rel->
rd_rel->relispartition && !recursing)
8288 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8289 errmsg(
"cannot add identity to a column of a partition"));
8296 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8297 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8305 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8306 errmsg(
"cannot alter system column \"%s\"",
8314 if (!attTup->attnotnull)
8316 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8317 errmsg(
"column \"%s\" of relation \"%s\" must be declared NOT NULL before identity can be added",
8324 if (attTup->attnotnull)
8332 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation \"%s\"",
8336 if (!conForm->convalidated)
8338 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8339 errmsg(
"incompatible NOT VALID constraint \"%s\" on relation \"%s\"",
8341 errhint(
"You might need to validate it using %s.",
8342 "ALTER TABLE ... VALIDATE CONSTRAINT"));
8345 if (attTup->attidentity)
8347 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8348 errmsg(
"column \"%s\" of relation \"%s\" is already an identity column",
8351 if (attTup->atthasdef)
8353 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8354 errmsg(
"column \"%s\" of relation \"%s\" already has a default value",
8357 attTup->attidentity = cdef->
identity;
8373 if (recurse && ispartitioned)
8380 foreach(lc, children)
8400 LOCKMODE lockmode,
bool recurse,
bool recursing)
8411 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8412 if (ispartitioned && !recurse)
8414 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8415 errmsg(
"cannot change identity column of only the partitioned table"),
8416 errhint(
"Do not specify the ONLY keyword.")));
8418 if (rel->
rd_rel->relispartition && !recursing)
8420 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8421 errmsg(
"cannot change identity column of a partition"));
8427 if (strcmp(defel->
defname,
"generated") == 0)
8431 (
errcode(ERRCODE_SYNTAX_ERROR),
8432 errmsg(
"conflicting or redundant options")));
8433 generatedEl = defel;
8436 elog(
ERROR,
"option \"%s\" not recognized",
8450 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8451 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8459 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8460 errmsg(
"cannot alter system column \"%s\"",
8463 if (!attTup->attidentity)
8465 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8466 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8490 if (generatedEl && recurse && ispartitioned)
8497 foreach(lc, children)
8517 bool recurse,
bool recursing)
8528 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8529 if (ispartitioned && !recurse)
8531 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8532 errmsg(
"cannot drop identity from a column of only the partitioned table"),
8533 errhint(
"Do not specify the ONLY keyword.")));
8535 if (rel->
rd_rel->relispartition && !recursing)
8537 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8538 errmsg(
"cannot drop identity from a column of a partition"));
8544 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8545 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8553 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8554 errmsg(
"cannot alter system column \"%s\"",
8557 if (!attTup->attidentity)
8561 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8562 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8567 (
errmsg(
"column \"%s\" of relation \"%s\" is not an identity column, skipping",
8575 attTup->attidentity =
'\0';
8591 if (recurse && ispartitioned)
8598 foreach(lc, children)
8615 seqaddress.
classId = RelationRelationId;
8647 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8648 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8656 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8657 errmsg(
"cannot alter system column \"%s\"",
8660 attgenerated = attTup->attgenerated;
8663 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8664 errmsg(
"column \"%s\" of relation \"%s\" is not a generated column",
8671 if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL &&
8674 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8675 errmsg(
"ALTER TABLE / SET EXPRESSION is not supported for virtual generated columns in tables with check constraints"),
8676 errdetail(
"Column \"%s\" of relation \"%s\" is a virtual generated column.",
8679 if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL && attTup->attnotnull)
8689 if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL &&
8692 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8693 errmsg(
"ALTER TABLE / SET EXPRESSION is not supported for virtual generated columns in tables that are part of a publication"),
8694 errdetail(
"Column \"%s\" of relation \"%s\" is a virtual generated column.",
8697 rewrite = (attgenerated == ATTRIBUTE_GENERATED_STORED);
8727 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8750 false,
true,
false, NULL);
8763 newval->is_generated =
true;
8799 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8800 errmsg(
"ALTER TABLE / DROP EXPRESSION must be applied to child tables too")));
8813 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8814 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8819 if (attTup->attinhcount > 0)
8821 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8822 errmsg(
"cannot drop generation expression from inherited column")));
8843 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8844 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8852 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8853 errmsg(
"cannot alter system column \"%s\"",
8862 if (attTup->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
8864 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8865 errmsg(
"ALTER TABLE / DROP EXPRESSION is not supported for virtual generated columns"),
8866 errdetail(
"Column \"%s\" of relation \"%s\" is a virtual generated column.",
8869 if (!attTup->attgenerated)
8873 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8874 errmsg(
"column \"%s\" of relation \"%s\" is not a generated column",
8879 (
errmsg(
"column \"%s\" of relation \"%s\" is not a generated column, skipping",
8891 attTup->attgenerated =
'\0';
8908 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8937 bool newtarget_default;
8944 Datum repl_val[Natts_pg_attribute];
8945 bool repl_null[Natts_pg_attribute];
8946 bool repl_repl[Natts_pg_attribute];
8952 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
8953 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
8956 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8957 errmsg(
"cannot refer to non-index column by number")));
8960 if (newValue &&
intVal(newValue) != -1)
8962 newtarget =
intVal(newValue);
8963 newtarget_default =
false;
8966 newtarget_default =
true;
8968 if (!newtarget_default)
8976 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8977 errmsg(
"statistics target %d is too low",
8984 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8985 errmsg(
"lowering statistics target to %d",
8998 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8999 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9008 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9009 errmsg(
"column number %d of relation \"%s\" does not exist",
9015 attnum = attrtuple->attnum;
9018 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9019 errmsg(
"cannot alter system column \"%s\"",
9026 if (attrtuple->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
9028 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9029 errmsg(
"cannot alter statistics on virtual generated column \"%s\"",
9032 if (rel->
rd_rel->relkind == RELKIND_INDEX ||
9033 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
9037 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9038 errmsg(
"cannot alter statistics on included column \"%s\" of index \"%s\"",
9042 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9043 errmsg(
"cannot alter statistics on non-expression column \"%s\" of index \"%s\"",
9045 errhint(
"Alter statistics on table column instead.")));
9049 memset(repl_null,
false,
sizeof(repl_null));
9050 memset(repl_repl,
false,
sizeof(repl_repl));
9051 if (!newtarget_default)
9052 repl_val[Anum_pg_attribute_attstattarget - 1] =
Int16GetDatum(newtarget);
9054 repl_null[Anum_pg_attribute_attstattarget - 1] =
true;
9055 repl_repl[Anum_pg_attribute_attstattarget - 1] =
true;
9057 repl_val, repl_null, repl_repl);
9091 Datum repl_val[Natts_pg_attribute];
9092 bool repl_null[Natts_pg_attribute];
9093 bool repl_repl[Natts_pg_attribute];
9101 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9102 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9106 attnum = attrtuple->attnum;
9109 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9110 errmsg(
"cannot alter system column \"%s\"",
9123 memset(repl_null,
false,
sizeof(repl_null));
9124 memset(repl_repl,
false,
sizeof(repl_repl));
9125 if (newOptions != (
Datum) 0)
9126 repl_val[Anum_pg_attribute_attoptions - 1] = newOptions;
9128 repl_null[Anum_pg_attribute_attoptions - 1] =
true;
9129 repl_repl[Anum_pg_attribute_attoptions - 1] =
true;
9131 repl_val, repl_null, repl_repl);
9160 bool setstorage,
char newstorage,
9161 bool setcompression,
char newcompression,
9175 for (
int i = 0;
i < indrel->
rd_index->indnatts;
i++)
9197 attrtuple->attstorage = newstorage;
9200 attrtuple->attcompression = newcompression;
9235 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9236 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9240 attnum = attrtuple->attnum;
9243 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9244 errmsg(
"cannot alter system column \"%s\"",
9260 true, attrtuple->attstorage,
9288 if (rel->
rd_rel->reloftype && !recursing)
9290 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9291 errmsg(
"cannot drop column from typed table")));
9293 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
9314 bool recurse,
bool recursing,
9315 bool missing_ok,
LOCKMODE lockmode,
9331 Assert(!recursing || addrs != NULL);
9348 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9349 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9355 (
errmsg(
"column \"%s\" of relation \"%s\" does not exist, skipping",
9362 attnum = targetatt->attnum;
9367 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9368 errmsg(
"cannot drop system column \"%s\"",
9375 if (targetatt->attinhcount > 0 && !recursing)
9377 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9378 errmsg(
"cannot drop inherited column \"%s\"",
9390 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9391 errmsg(
"cannot drop column \"%s\" because it is part of the partition key of relation \"%s\"",
9413 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !recurse)
9415 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9416 errmsg(
"cannot drop column from only the partitioned table when partitions exist"),
9417 errhint(
"Do not specify the ONLY keyword.")));
9420 foreach(child, children)
9432 elog(
ERROR,
"cache lookup failed for attribute \"%s\" of relation %u",
9433 colName, childrelid);
9436 if (childatt->attinhcount <= 0)
9437 elog(
ERROR,
"relation %u has non-inherited attribute \"%s\"",
9438 childrelid, colName);
9447 if (childatt->attinhcount == 1 && !childatt->attislocal)
9451 behavior,
true,
true,
9452 false, lockmode, addrs);
9457 childatt->attinhcount--;
9472 childatt->attinhcount--;
9473 childatt->attislocal =
true;
9489 object.classId = RelationRelationId;
9491 object.objectSubId =
attnum;
9533 bool got_children =
false;
9571 got_children =
true;
9581 errmsg(
"column \"%s\" of table \"%s\" is not marked NOT NULL",
9595 newcmd->
def = (
Node *) nnconstr;
9597 ATPrepCmd(wqueue, rel, newcmd,
true,
false, lockmode, context);
9610 if (conForm->contype != CONSTRAINT_NOTNULL)
9611 elog(
ERROR,
"constraint %u is not a not-null constraint", conForm->oid);
9614 if (conForm->connoinherit)
9616 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
9617 errmsg(
"cannot create primary key on column \"%s\"", colname),
9619 errdetail(
"The constraint \"%s\" on column \"%s\" of table \"%s\", marked %s, is incompatible with a primary key.",
9620 NameStr(conForm->conname), colname,
9622 errhint(
"You might need to make the existing constraint inheritable using %s.",
9623 "ALTER TABLE ... ALTER CONSTRAINT ... INHERIT"));
9626 if (!conForm->convalidated)
9628 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
9629 errmsg(
"cannot create primary key on column \"%s\"", colname),
9631 errdetail(
"The constraint \"%s\" on column \"%s\" of table \"%s\", marked %s, is incompatible with a primary key.",
9632 NameStr(conForm->conname), colname,
9634 errhint(
"You might need to validate it using %s.",
9635 "ALTER TABLE ... VALIDATE CONSTRAINT"));
9663 check_rights = !is_rebuild;
9735 Oid index_oid =
stmt->indexOid;
9739 char *constraintName;
9740 char constraintType;
9752 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
9754 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9755 errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables")));
9765 elog(
ERROR,
"index \"%s\" is not unique", indexName);
9774 constraintName =
stmt->idxname;
9775 if (constraintName == NULL)
9776 constraintName = indexName;
9777 else if (strcmp(constraintName, indexName) != 0)
9780 (
errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index \"%s\" to \"%s\"",
9781 indexName, constraintName)));
9791 constraintType = CONSTRAINT_PRIMARY;
9793 constraintType = CONSTRAINT_UNIQUE;
9825 Constraint *newConstraint,
bool recurse,
bool is_readd,
9837 switch (newConstraint->
contype)
9843 newConstraint, recurse,
false, is_readd,
9859 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
9878 elog(
ERROR,
"unrecognized constraint type: %d",
9879 (
int) newConstraint->
contype);
9905 foreach(lc, colnames)
9910 buf[buflen++] =
'_';
9917 buflen += strlen(
buf + buflen);
9941 Constraint *constr,
bool recurse,
bool recursing,
9970 recursing || is_readd,
9980 foreach(lcon, newcons)
10026 if (newcons ==
NIL)
10048 if (!recurse && children !=
NIL)
10050 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
10051 errmsg(
"constraint must be added to child tables too")));
10056 foreach(child, children)
10071 constr, recurse,
true, is_readd, lockmode);
10097 bool recurse,
bool recursing,
LOCKMODE lockmode)
10112 bool pk_has_without_overlaps;
10135 if (!recurse && rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10137 errcode(ERRCODE_WRONG_OBJECT_TYPE),
10138 errmsg(
"cannot use ONLY for foreign key on partitioned table \"%s\" referencing relation \"%s\"",
10142 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
10143 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
10145 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10146 errmsg(
"referenced relation \"%s\" is not a table",
10151 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
10152 errmsg(
"permission denied: \"%s\" is a system catalog",
10163 switch (rel->
rd_rel->relpersistence)
10165 case RELPERSISTENCE_PERMANENT:
10168 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
10169 errmsg(
"constraints on permanent tables may reference only permanent tables")));
10171 case RELPERSISTENCE_UNLOGGED:
10173 && pkrel->
rd_rel->relpersistence != RELPERSISTENCE_UNLOGGED)
10175 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
10176 errmsg(
"constraints on unlogged tables may reference only permanent or unlogged tables")));
10178 case RELPERSISTENCE_TEMP:
10179 if (pkrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
10181 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
10182 errmsg(
"constraints on temporary tables may reference only temporary tables")));
10185 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
10186 errmsg(
"constraints on temporary tables must involve temporary tables of this session")));
10196 fkattnum, fktypoid, fkcolloid);
10200 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10201 errmsg(
"foreign key uses PERIOD on the referenced table but not the referencing table"));
10205 fkdelsetcols, NULL, NULL);
10222 pkattnum, pktypoid, pkcolloid,
10223 opclasses, &pk_has_without_overlaps);
10228 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10229 errmsg(
"foreign key uses PERIOD on the referenced table but not the referencing table"));
10235 pkattnum, pktypoid, pkcolloid);
10240 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10241 errmsg(
"foreign key uses PERIOD on the referencing table but not the referenced table"));
10245 with_period, opclasses, &pk_has_without_overlaps);
10252 if (pk_has_without_overlaps && !with_period)
10254 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10255 errmsg(
"foreign key must use PERIOD when referencing a primary key using WITHOUT OVERLAPS"));
10265 for (
i = 0;
i < numfks;
i++)
10278 (
errcode(ERRCODE_SYNTAX_ERROR),
10279 errmsg(
"invalid %s action for foreign key constraint containing generated column",
10284 (
errcode(ERRCODE_SYNTAX_ERROR),
10285 errmsg(
"invalid %s action for foreign key constraint containing generated column",
10297 if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
10299 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10300 errmsg(
"foreign key constraints on virtual generated columns are not supported")));
10313 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10314 errmsg(
"unsupported %s action for foreign key constraint using PERIOD",
10322 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10323 errmsg(
"unsupported %s action for foreign key constraint using PERIOD",
10335 if (numfks != numpks)
10337 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
10338 errmsg(
"number of referencing and referenced columns for foreign key disagree")));
10347 for (
i = 0;
i < numpks;
i++)
10349 Oid pktype = pktypoid[
i];
10350 Oid fktype = fktypoid[
i];
10352 Oid pkcoll = pkcolloid[
i];
10353 Oid fkcoll = fkcolloid[
i];
10370 elog(
ERROR,
"cache lookup failed for opclass %u", opclasses[
i]);
10372 amid = cla_tup->opcmethod;
10373 opfamily = cla_tup->opcfamily;
10374 opcintype = cla_tup->opcintype;
10387 for_overlaps = with_period &&
i == numpks - 1;
10392 errcode(ERRCODE_UNDEFINED_OBJECT),
10394 ?
errmsg(
"could not identify an overlaps operator for foreign key")
10395 :
errmsg(
"could not identify an equality operator for foreign key"),
10396 errdetail(
"Could not translate compare type %d for operator family \"%s\" of access method \"%s\".",
10407 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
10408 eqstrategy, opcintype, opcintype, opfamily);
10420 pfeqop_right = fktyped;
10442 Oid input_typeids[2];
10443 Oid target_typeids[2];
10445 input_typeids[0] = pktype;
10446 input_typeids[1] = fktype;
10447 target_typeids[0] = opcintype;
10448 target_typeids[1] = opcintype;
10452 pfeqop = ffeqop = ppeqop;
10453 pfeqop_right = opcintype;
10459 (
errcode(ERRCODE_DATATYPE_MISMATCH),
10460 errmsg(
"foreign key constraint \"%s\" cannot be implemented",
10462 errdetail(
"Key columns \"%s\" of the referencing table and \"%s\" of the referenced table "
10463 "are of incompatible types: %s and %s.",
10474 elog(
ERROR,
"key columns are not both collatable");
10491 if ((!pkcolldet || !fkcolldet) && pkcoll != fkcoll)
10493 (
errcode(ERRCODE_COLLATION_MISMATCH),
10494 errmsg(
"foreign key constraint \"%s\" cannot be implemented", fkconstraint->
conname),
10495 errdetail(
"Key columns \"%s\" of the referencing table and \"%s\" of the referenced table "
10496 "have incompatible collations: \"%s\" and \"%s\". "
10497 "If either collation is nondeterministic, then both collations have to be the same.",
10512 old_check_ok = (pfeqop ==
lfirst_oid(old_pfeqop_item));
10534 old_fktype = attr->atttypid;
10535 new_fktype = fktype;
10541 old_fkcoll = attr->attcollation;
10542 new_fkcoll = fkcoll;
10577 old_check_ok = (new_pathtype == old_pathtype &&
10578 new_castfunc == old_castfunc &&
10579 (!IsPolymorphicType(pfeqop_right) ||
10580 new_fktype == old_fktype) &&
10581 (new_fkcoll == old_fkcoll ||
10585 pfeqoperators[
i] = pfeqop;
10586 ppeqoperators[
i] = ppeqop;
10587 ffeqoperators[
i] = ffeqop;
10601 Oid aggedperiodoperoid;
10602 Oid intersectoperoid;
10605 &intersectoperoid);
10610 fkconstraint->
conname, fkconstraint, rel, pkrel,
10675 int numfksetcols,
int16 *fksetcolsattnums,
10678 int numcolsout = 0;
10680 for (
int i = 0;
i < numfksetcols;
i++)
10682 int16 setcol_attnum = fksetcolsattnums[
i];
10686 for (
int j = 0;
j < numfks;
j++)
10688 if (fkattnums[
j] == setcol_attnum)
10700 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
10701 errmsg(
"column \"%s\" referenced in ON DELETE SET action must be part of foreign key", col)));
10706 for (
int j = 0;
j < numcolsout;
j++)
10708 if (fksetcolsattnums[
j] == setcol_attnum)
10715 fksetcolsattnums[numcolsout++] = setcol_attnum;
10751 char *constraintname,
Constraint *fkconstraint,
10753 int numfks,
int16 *pkattnum,
10754 int16 *fkattnum,
Oid *pfeqoperators,
Oid *ppeqoperators,
10755 Oid *ffeqoperators,
int numfkdelsetcols,
int16 *fkdelsetcols,
10756 bool is_internal,
bool with_period)
10769 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
10770 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
10772 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10773 errmsg(
"referenced relation \"%s\" is not a table",
10790 conname = constraintname;
10792 if (fkconstraint->
conname == NULL)
10797 conislocal =
false;
10799 connoinherit =
false;
10809 connoinherit = rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE;
10817 CONSTRAINT_FOREIGN,
10932 Oid *ppeqoperators,
Oid *ffeqoperators,
10933 int numfkdelsetcols,
int16 *fkdelsetcols,
10935 Oid parentDelTrigger,
Oid parentUpdTrigger,
10952 parentConstr, indexOid,
10953 parentDelTrigger, parentUpdTrigger,
10954 &deleteTriggerOid, &updateTriggerOid);
10961 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10986 for (
int j = 0;
j < numfks;
j++)
10987 mapped_pkattnum[
j] = map->
attnums[pkattnum[
j] - 1];
10990 mapped_pkattnum = pkattnum;
10995 elog(
ERROR,
"index for %u not found in partition %s",
11000 fkconstraint->
conname, fkconstraint, rel,
11001 partRel, partIndexId, parentConstr,
11002 numfks, mapped_pkattnum,
11003 fkattnum, pfeqoperators, ppeqoperators,
11004 ffeqoperators, numfkdelsetcols,
11005 fkdelsetcols,
true, with_period);
11008 partIndexId, address.
objectId, numfks,
11009 mapped_pkattnum, fkattnum,
11010 pfeqoperators, ppeqoperators, ffeqoperators,
11011 numfkdelsetcols, fkdelsetcols,
11013 deleteTriggerOid, updateTriggerOid,
11020 pfree(mapped_pkattnum);
11068 int numfks,
int16 *pkattnum,
int16 *fkattnum,
11069 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
11070 int numfkdelsetcols,
int16 *fkdelsetcols,
11071 bool old_check_ok,
LOCKMODE lockmode,
11072 Oid parentInsTrigger,
Oid parentUpdTrigger,
11082 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
11084 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11085 errmsg(
"foreign key constraints are not supported on foreign tables")));
11099 parentInsTrigger, parentUpdTrigger,
11100 &insertTriggerOid, &updateTriggerOid);
11102 if (rel->
rd_rel->relkind == RELKIND_RELATION)
11125 newcon->
conid = parentConstr;
11127 newcon->
qual = (
Node *) fkconstraint;
11132 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11164 for (
int j = 0;
j < numfks;
j++)
11165 mapped_fkattnum[
j] = attmap->
attnums[fkattnum[
j] - 1];
11198 fkconstraint->
conname, fkconstraint,
11199 partition, pkrel, indexOid, parentConstr,
11201 mapped_fkattnum, pfeqoperators,
11202 ppeqoperators, ffeqoperators,
11203 numfkdelsetcols, fkdelsetcols,
true,
11249 Assert(parentRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
11324 foreach(cell, clone)
11338 int numfkdelsetcols;
11347 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
11363 indexOid = constrForm->conindid;
11374 for (
int i = 0;
i < numfks;
i++)
11375 mapped_confkey[
i] = attmap->
attnums[confkey[
i] - 1];
11378 fkconstraint->
contype = CONSTRAINT_FOREIGN;
11380 fkconstraint->
deferrable = constrForm->condeferrable;
11383 fkconstraint->
pktable = NULL;
11386 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
11392 fkconstraint->
is_enforced = constrForm->conenforced;
11397 for (
int i = 0;
i < numfks;
i++)
11414 elog(
ERROR,
"index for %u not found in partition %s",
11422 if (constrForm->conenforced)
11424 constrForm->confrelid, constrForm->conrelid,
11425 &deleteTriggerOid, &updateTriggerOid);
11429 fkconstraint->
conname, fkconstraint, fkRel,
11430 partitionRel, partIndexId, constrOid,
11431 numfks, mapped_confkey,
11432 conkey, conpfeqop, conppeqop, conffeqop,
11433 numfkdelsetcols, confdelsetcols,
false,
11434 constrForm->conperiod);
11452 constrForm->conperiod);
11500 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11501 errmsg(
"cannot attach table \"%s\" as a partition because it is referenced by foreign key \"%s\"",
11515 if (partRel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
11517 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11518 errmsg(
"foreign key constraints are not supported on foreign tables")));
11538 foreach(cell, clone)
11551 int numfkdelsetcols;
11564 elog(
ERROR,
"cache lookup failed for constraint %u",
11580 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11585 conpfeqop, conppeqop, conffeqop,
11586 &numfkdelsetcols, confdelsetcols);
11587 for (
int i = 0;
i < numfks;
i++)
11588 mapped_conkey[
i] = attmap->
attnums[conkey[
i] - 1];
11599 if (constrForm->conenforced)
11601 constrForm->confrelid, constrForm->conrelid,
11602 &insertTriggerOid, &updateTriggerOid);
11612 foreach(lc, partFKs)
11641 fkconstraint->
contype = CONSTRAINT_FOREIGN;
11643 fkconstraint->
deferrable = constrForm->condeferrable;
11646 fkconstraint->
pktable = NULL;
11649 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
11655 fkconstraint->
is_enforced = constrForm->conenforced;
11658 for (
int i = 0;
i < numfks;
i++)
11663 mapped_conkey[
i] - 1);
11668 indexOid = constrForm->conindid;
11669 with_period = constrForm->conperiod;
11673 NameStr(constrForm->conname), fkconstraint,
11674 partRel, pkrel, indexOid, parentConstrOid,
11676 mapped_conkey, conpfeqop,
11677 conppeqop, conffeqop,
11678 numfkdelsetcols, confdelsetcols,
11679 false, with_period);
11725 Oid parentConstrOid,
11730 Oid parentInsTrigger,
11731 Oid parentUpdTrigger,
11742 elog(
ERROR,
"cache lookup failed for constraint %u", parentConstrOid);
11749 if (fk->
confrelid != parentConstr->confrelid || fk->
nkeys != numfks)
11754 for (
int i = 0;
i < numfks;
i++)
11756 if (fk->conkey[
i] != mapped_conkey[
i] ||
11757 fk->confkey[
i] != confkey[
i] ||
11758 fk->conpfeqop[
i] != conpfeqop[
i])
11779 if (partConstr->conenforced != parentConstr->conenforced)
11781 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
11782 errmsg(
"constraint \"%s\" enforceability conflicts with constraint \"%s\" on relation \"%s\"",
11783 NameStr(parentConstr->conname),
11784 NameStr(partConstr->conname),
11788 partConstr->condeferrable != parentConstr->condeferrable ||
11789 partConstr->condeferred != parentConstr->condeferred ||
11790 partConstr->confupdtype != parentConstr->confupdtype ||
11791 partConstr->confdeltype != parentConstr->confdeltype ||
11792 partConstr->confmatchtype != parentConstr->confmatchtype)
11804 parentConstrOid, parentInsTrigger,
11805 parentUpdTrigger, trigrel);
11821 Oid parentConstrOid,
11822 Oid parentInsTrigger,
11823 Oid parentUpdTrigger,
11830 bool queueValidation;
11831 Oid partConstrFrelid;
11832 Oid partConstrRelid;
11833 bool parentConstrIsEnforced;
11839 elog(
ERROR,
"cache lookup failed for constraint %u", parentConstrOid);
11841 parentConstrIsEnforced = parentConstr->conenforced;
11847 elog(
ERROR,
"cache lookup failed for constraint %u", partConstrOid);
11849 partConstrFrelid = partConstr->confrelid;
11850 partConstrRelid = partConstr->conrelid;
11872 queueValidation = parentConstr->convalidated && !partConstr->convalidated;
11894 if (parentConstrIsEnforced)
11896 Oid insertTriggerOid,
11900 partConstrOid, partConstrFrelid, partConstrRelid,
11901 &insertTriggerOid, &updateTriggerOid);
11921 if (queueValidation)
11930 elog(
ERROR,
"cache lookup failed for constraint %u", partConstrOid);
11959 Anum_pg_constraint_conrelid,
11964 ConstraintRelidTypidNameIndexId,
11965 true, NULL, 1, &
key);
11971 if (conform->conparentid != conoid)
11990 ConstraintRelationId,
11999 Anum_pg_trigger_tgconstraint,
12003 true, NULL, 1, &key2);
12039 Anum_pg_trigger_tgconstraint,
12052 if (
OidIsValid(conrelid) && trgform->tgconstrrelid != conrelid)
12054 if (
OidIsValid(confrelid) && trgform->tgrelid != confrelid)
12058 Assert(trgform->tgfoid == F_RI_FKEY_CHECK_INS ||
12059 trgform->tgfoid == F_RI_FKEY_CHECK_UPD ||
12060 trgform->tgfoid == F_RI_FKEY_CASCADE_DEL ||
12061 trgform->tgfoid == F_RI_FKEY_CASCADE_UPD ||
12062 trgform->tgfoid == F_RI_FKEY_RESTRICT_DEL ||
12063 trgform->tgfoid == F_RI_FKEY_RESTRICT_UPD ||
12064 trgform->tgfoid == F_RI_FKEY_SETNULL_DEL ||
12065 trgform->tgfoid == F_RI_FKEY_SETNULL_UPD ||
12066 trgform->tgfoid == F_RI_FKEY_SETDEFAULT_DEL ||
12067 trgform->tgfoid == F_RI_FKEY_SETDEFAULT_UPD ||
12068 trgform->tgfoid == F_RI_FKEY_NOACTION_DEL ||
12069 trgform->tgfoid == F_RI_FKEY_NOACTION_UPD);
12100 Oid conoid,
Oid confrelid,
Oid conrelid,
12101 Oid *deleteTriggerOid,
12102 Oid *updateTriggerOid)
12108 *deleteTriggerOid = *updateTriggerOid =
InvalidOid;
12110 Anum_pg_trigger_tgconstraint,
12120 if (trgform->tgconstrrelid != conrelid)
12122 if (trgform->tgrelid != confrelid)
12127 if (TRIGGER_FOR_DELETE(trgform->tgtype))
12130 *deleteTriggerOid = trgform->oid;
12132 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
12135 *updateTriggerOid = trgform->oid;
12137#ifndef USE_ASSERT_CHECKING
12145 elog(
ERROR,
"could not find ON DELETE action trigger of foreign key constraint %u",
12148 elog(
ERROR,
"could not find ON UPDATE action trigger of foreign key constraint %u",
12161 Oid conoid,
Oid confrelid,
Oid conrelid,
12162 Oid *insertTriggerOid,
12163 Oid *updateTriggerOid)
12169 *insertTriggerOid = *updateTriggerOid =
InvalidOid;
12171 Anum_pg_trigger_tgconstraint,
12181 if (trgform->tgconstrrelid != confrelid)
12183 if (trgform->tgrelid != conrelid)
12188 if (TRIGGER_FOR_INSERT(trgform->tgtype))
12191 *insertTriggerOid = trgform->oid;
12193 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
12196 *updateTriggerOid = trgform->oid;
12198#ifndef USE_ASSERT_CHECKING
12206 elog(
ERROR,
"could not find ON INSERT check triggers of foreign key constraint %u",
12209 elog(
ERROR,
"could not find ON UPDATE check triggers of foreign key constraint %u",
12241 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !recurse)
12243 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12244 errmsg(
"constraint must be altered in child tables too"),
12245 errhint(
"Do not specify the ONLY keyword."));
12255 Anum_pg_constraint_conrelid,
12259 Anum_pg_constraint_contypid,
12263 Anum_pg_constraint_conname,
12267 true, NULL, 3, skey);
12272 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12273 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12279 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
12280 errmsg(
"constraint \"%s\" of relation \"%s\" is not a foreign key constraint",
12284 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
12285 errmsg(
"cannot alter enforceability of constraint \"%s\" of relation \"%s\"",
12288 currcon->contype != CONSTRAINT_NOTNULL)
12290 errcode(ERRCODE_WRONG_OBJECT_TYPE),
12291 errmsg(
"constraint \"%s\" of relation \"%s\" is not a not-null constraint",
12296 cmdcon->
noinherit && currcon->coninhcount > 0)
12298 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12299 errmsg(
"cannot alter inherited constraint \"%s\" on relation \"%s\"",
12315 Oid parent = currcon->conparentid;
12316 char *ancestorname = NULL;
12317 char *ancestortable = NULL;
12333 parent = contup->conparentid;
12338 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12339 errmsg(
"cannot alter constraint \"%s\" on relation \"%s\"",
12341 ancestorname && ancestortable ?
12342 errdetail(
"Constraint \"%s\" is derived from constraint \"%s\" of relation \"%s\".",
12343 cmdcon->
conname, ancestorname, ancestortable) : 0,
12344 errhint(
"You may alter the constraint it derives from instead.")));
12353 contuple, recurse, lockmode))
12375 bool changed =
false;
12394 currcon->conrelid, currcon->confrelid,
12401 contuple, recurse, &otherrelids,
12442 Oid fkrelid,
Oid pkrelid,
12444 Oid ReferencedParentDelTrigger,
12445 Oid ReferencedParentUpdTrigger,
12446 Oid ReferencingParentInsTrigger,
12447 Oid ReferencingParentUpdTrigger)
12452 bool changed =
false;
12460 conoid = currcon->oid;
12463 Assert(currcon->contype == CONSTRAINT_FOREIGN);
12465 rel =
table_open(currcon->conrelid, lockmode);
12481 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
12484 fkrelid, pkrelid, contuple,
12507 if (currcon->conrelid == fkrelid)
12509 currcon->confrelid,
12513 ReferencedParentDelTrigger,
12514 ReferencedParentUpdTrigger,
12515 &ReferencedDelTriggerOid,
12516 &ReferencedUpdTriggerOid);
12519 if (currcon->confrelid == pkrelid)
12525 ReferencingParentInsTrigger,
12526 ReferencingParentUpdTrigger,
12527 &ReferencingInsTriggerOid,
12528 &ReferencingUpdTriggerOid);
12536 if (rel->
rd_rel->relkind == RELKIND_RELATION &&
12537 currcon->confrelid == pkrelid)
12545 newcon->
refrelid = currcon->confrelid;
12546 newcon->
refindid = currcon->conindid;
12547 newcon->
conid = currcon->oid;
12548 newcon->
qual = (
Node *) fkconstraint;
12560 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
12563 fkrelid, pkrelid, contuple,
12564 lockmode, ReferencedDelTriggerOid,
12565 ReferencedUpdTriggerOid,
12566 ReferencingInsTriggerOid,
12567 ReferencingUpdTriggerOid);
12593 bool changed =
false;
12601 refrelid = currcon->confrelid;
12604 Assert(currcon->contype == CONSTRAINT_FOREIGN);
12610 if (currcon->condeferrable != cmdcon->
deferrable ||
12629 if (recurse && changed &&
12630 (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
12633 contuple, recurse, otherrelids,
12657 Assert(currcon->contype == CONSTRAINT_NOTNULL);
12663 if (cmdcon->
noinherit == currcon->connoinherit)
12671 colName =
get_attname(currcon->conrelid, colNum,
false);
12690 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation %u",
12691 colName, childoid);
12693 Assert(childcon->coninhcount > 0);
12694 childcon->coninhcount--;
12695 childcon->conislocal =
true;
12704 colName,
true,
true, lockmode);
12723 bool deferrable,
bool initdeferred,
12724 List **otherrelids)
12731 Anum_pg_trigger_tgconstraint,
12758 if (tgform->tgfoid != F_RI_FKEY_NOACTION_DEL &&
12759 tgform->tgfoid != F_RI_FKEY_NOACTION_UPD &&
12760 tgform->tgfoid != F_RI_FKEY_CHECK_INS &&
12761 tgform->tgfoid != F_RI_FKEY_CHECK_UPD)
12767 copy_tg->tgdeferrable = deferrable;
12768 copy_tg->tginitdeferred = initdeferred;
12793 Oid fkrelid,
Oid pkrelid,
12795 Oid ReferencedParentDelTrigger,
12796 Oid ReferencedParentUpdTrigger,
12797 Oid ReferencingParentInsTrigger,
12798 Oid ReferencingParentUpdTrigger)
12807 conoid = currcon->oid;
12810 Anum_pg_constraint_conparentid,
12815 true, NULL, 1, &pkey);
12819 pkrelid, childtup, lockmode,
12820 ReferencedParentDelTrigger,
12821 ReferencedParentUpdTrigger,
12822 ReferencingParentInsTrigger,
12823 ReferencingParentUpdTrigger);
12852 conoid = currcon->oid;
12855 Anum_pg_constraint_conparentid,
12860 true, NULL, 1, &pkey);
12867 childrel =
table_open(childcon->conrelid, lockmode);
12870 childtup, recurse, otherrelids, lockmode);
12909 copy_con->condeferrable = cmdcon->
deferrable;
12913 copy_con->connoinherit = cmdcon->
noinherit;
12937 bool recurse,
bool recursing,
LOCKMODE lockmode)
12952 Anum_pg_constraint_conrelid,
12956 Anum_pg_constraint_contypid,
12960 Anum_pg_constraint_conname,
12964 true, NULL, 3, skey);
12969 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12970 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12974 if (con->contype != CONSTRAINT_FOREIGN &&
12975 con->contype != CONSTRAINT_CHECK &&
12976 con->contype != CONSTRAINT_NOTNULL)
12978 errcode(ERRCODE_WRONG_OBJECT_TYPE),
12979 errmsg(
"cannot validate constraint \"%s\" of relation \"%s\"",
12981 errdetail(
"This operation is not supported for this type of constraint."));
12983 if (!con->conenforced)
12985 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12986 errmsg(
"cannot validate NOT ENFORCED constraint")));
12988 if (!con->convalidated)
12990 if (con->contype == CONSTRAINT_FOREIGN)
12995 else if (con->contype == CONSTRAINT_CHECK)
12998 tuple, recurse, recursing, lockmode);
13000 else if (con->contype == CONSTRAINT_NOTNULL)
13003 tuple, recurse, recursing, lockmode);
13035 Assert(con->contype == CONSTRAINT_FOREIGN);
13036 Assert(!con->convalidated);
13047 if (fkrel->
rd_rel->relkind == RELKIND_RELATION &&
13048 con->confrelid == pkrelid)
13061 newcon->
refrelid = con->confrelid;
13063 newcon->
conid = con->oid;
13064 newcon->
qual = (
Node *) fkconstraint;
13076 if (fkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
13084 Anum_pg_constraint_conparentid,
13089 true, NULL, 1, &pkey);
13103 if (childcon->convalidated)
13106 childrel =
table_open(childcon->conrelid, lockmode);
13113 childtup, lockmode);
13129 copy_con->convalidated =
true;
13147 bool recurse,
bool recursing,
LOCKMODE lockmode)
13161 Assert(con->contype == CONSTRAINT_CHECK);
13168 if (!recursing && !con->connoinherit)
13179 foreach(child, children)
13194 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13195 errmsg(
"constraint must be validated on child tables too")));
13207 newcon->
name = constrName;
13211 newcon->
conid = con->oid;
13214 Anum_pg_constraint_conbin);
13232 copy_con->convalidated =
true;
13249 HeapTuple contuple,
bool recurse,
bool recursing,
13261 Assert(con->contype == CONSTRAINT_NOTNULL);
13273 if (!recursing && !con->connoinherit)
13294 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13295 errmsg(
"constraint must be validated on child tables too"));
13303 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation \"%s\"",
13306 if (childcon->convalidated)
13315 false,
true, lockmode);
13335 copy_con->convalidated =
true;
13362 foreach(l, colList)
13371 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13372 errmsg(
"column \"%s\" referenced in foreign key constraint does not exist",
13375 if (attform->attnum < 0)
13377 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13378 errmsg(
"system columns cannot be used in foreign keys")));
13381 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
13382 errmsg(
"cannot have more than %d keys in a foreign key",
13384 attnums[
attnum] = attform->attnum;
13385 if (atttypids != NULL)
13386 atttypids[
attnum] = attform->atttypid;
13387 if (attcollids != NULL)
13388 attcollids[
attnum] = attform->attcollation;
13411 List **attnamelist,
13413 Oid *opclasses,
bool *pk_has_without_overlaps)
13415 List *indexoidlist;
13419 Datum indclassDatum;
13432 foreach(indexoidscan, indexoidlist)
13438 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
13440 if (indexStruct->indisprimary && indexStruct->indisvalid)
13447 if (!indexStruct->indimmediate)
13449 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
13450 errmsg(
"cannot use a deferrable primary key for referenced table \"%s\"",
13453 *indexOid = indexoid;
13466 (
errcode(ERRCODE_UNDEFINED_OBJECT),
13467 errmsg(
"there is no primary key for referenced table \"%s\"",
13472 Anum_pg_index_indclass);
13479 *attnamelist =
NIL;
13480 for (
i = 0;
i < indexStruct->indnkeyatts;
i++)
13482 int pkattno = indexStruct->indkey.values[
i];
13484 attnums[
i] = pkattno;
13487 opclasses[
i] = indclass->
values[
i];
13488 *attnamelist =
lappend(*attnamelist,
13492 *pk_has_without_overlaps = indexStruct->indisexclusion;
13514 int numattrs,
int16 *attnums,
13515 bool with_period,
Oid *opclasses,
13516 bool *pk_has_without_overlaps)
13519 bool found =
false;
13520 bool found_deferrable =
false;
13521 List *indexoidlist;
13533 for (
i = 0;
i < numattrs;
i++)
13535 for (
j =
i + 1;
j < numattrs;
j++)
13537 if (attnums[
i] == attnums[
j])
13539 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
13540 errmsg(
"foreign key referenced-columns list must not contain duplicates")));
13551 foreach(indexoidscan, indexoidlist)
13559 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
13567 if (indexStruct->indnkeyatts == numattrs &&
13568 (with_period ? indexStruct->indisexclusion : indexStruct->indisunique) &&
13569 indexStruct->indisvalid &&
13573 Datum indclassDatum;
13578 Anum_pg_index_indclass);
13591 for (
i = 0;
i < numattrs;
i++)
13594 for (
j = 0;
j < numattrs;
j++)
13596 if (attnums[
i] == indexStruct->indkey.values[
j])
13598 opclasses[
i] = indclass->
values[
j];
13607 if (found && with_period)
13609 int16 periodattnum = attnums[numattrs - 1];
13611 found = (periodattnum == indexStruct->indkey.values[numattrs - 1]);
13619 if (found && !indexStruct->indimmediate)
13625 found_deferrable =
true;
13631 *pk_has_without_overlaps = indexStruct->indisexclusion;
13640 if (found_deferrable)
13642 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
13643 errmsg(
"cannot use a deferrable unique constraint for referenced table \"%s\"",
13647 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
13648 errmsg(
"there is no unique constraint matching given keys for referenced table \"%s\"",
13668 if (targetTypeId == sourceTypeId)
13679 elog(
ERROR,
"could not find cast from %u to %u",
13680 sourceTypeId, targetTypeId);
13705 for (
i = 0;
i < natts;
i++)
13737 (
errmsg_internal(
"validating foreign key constraint \"%s\"", conname)));
13772 "validateForeignKeyConstraint",
13793 trigdata.
type = T_TriggerData;
13800 fcinfo->context = (
Node *) &trigdata;
13823 Oid constraintOid,
Oid indexOid,
Oid parentTrigOid,
13841 fk_trigger->
trigname =
"RI_ConstraintTrigger_c";
13848 fk_trigger->
events = TRIGGER_TYPE_INSERT;
13853 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
13857 fk_trigger->
row =
true;
13858 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
13866 trigAddress =
CreateTrigger(fk_trigger, NULL, myRelOid, refRelOid,
13868 parentTrigOid, NULL,
true,
false);
13886 Oid constraintOid,
Oid indexOid,
13887 Oid parentDelTrigger,
Oid parentUpdTrigger,
13888 Oid *deleteTrigOid,
Oid *updateTrigOid)
13900 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
13903 fk_trigger->
row =
true;
13904 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
13905 fk_trigger->
events = TRIGGER_TYPE_DELETE;
13939 elog(
ERROR,
"unrecognized FK action type: %d",
13944 trigAddress =
CreateTrigger(fk_trigger, NULL, refRelOid, myRelOid,
13946 parentDelTrigger, NULL,
true,
false);
13948 *deleteTrigOid = trigAddress.
objectId;
13960 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
13963 fk_trigger->
row =
true;
13964 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
13965 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
13999 elog(
ERROR,
"unrecognized FK action type: %d",
14004 trigAddress =
CreateTrigger(fk_trigger, NULL, refRelOid, myRelOid,
14006 parentUpdTrigger, NULL,
true,
false);
14008 *updateTrigOid = trigAddress.
objectId;
14023 Oid parentInsTrigger,
Oid parentUpdTrigger,
14024 Oid *insertTrigOid,
Oid *updateTrigOid)
14027 constraintOid, indexOid,
14028 parentInsTrigger,
true);
14030 constraintOid, indexOid,
14031 parentUpdTrigger,
false);
14042 bool missing_ok,
LOCKMODE lockmode)
14048 bool found =
false;
14056 Anum_pg_constraint_conrelid,
14060 Anum_pg_constraint_contypid,
14064 Anum_pg_constraint_conname,
14068 true, NULL, 3, skey);
14074 missing_ok, lockmode);
14084 errcode(ERRCODE_UNDEFINED_OBJECT),
14085 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
14089 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist, skipping",
14106 bool recurse,
bool recursing,
bool missing_ok,
14113 bool is_no_inherit_constraint =
false;
14115 char *colname = NULL;
14128 constrName =
NameStr(con->conname);
14131 if (con->coninhcount > 0 && !recursing)
14133 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14134 errmsg(
"cannot drop inherited constraint \"%s\" of relation \"%s\"",
14144 if (con->contype == CONSTRAINT_NOTNULL)
14165 if (pkattrs == NULL &&
14166 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
14175 for (
int i = 0;
i < pk->
rd_index->indnkeyatts;
i++)
14185 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14186 errmsg(
"column \"%s\" is in a primary key",
14193 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14194 errmsg(
"column \"%s\" is in index used as replica identity",
14200 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
14203 if (attForm->attidentity !=
'\0')
14205 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
14206 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
14212 if (attForm->attnotnull)
14214 attForm->attnotnull =
false;
14221 is_no_inherit_constraint = con->connoinherit;
14230 if (con->contype == CONSTRAINT_FOREIGN &&
14251 if (con->contype != CONSTRAINT_CHECK &&
14252 con->contype != CONSTRAINT_NOTNULL &&
14253 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
14264 if (!is_no_inherit_constraint)
14283 if (con->contype == CONSTRAINT_NOTNULL)
14287 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation %u",
14296 Anum_pg_constraint_conrelid,
14300 Anum_pg_constraint_contypid,
14304 Anum_pg_constraint_conname,
14308 true, NULL, 3, skey);
14313 (
errcode(ERRCODE_UNDEFINED_OBJECT),
14314 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
14324 if (childcon->contype != CONSTRAINT_CHECK &&
14325 childcon->contype != CONSTRAINT_NOTNULL)
14326 elog(
ERROR,
"inherited constraint is not a CHECK or not-null constraint");
14328 if (childcon->coninhcount <= 0)
14329 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
14330 childrelid,
NameStr(childcon->conname));
14338 if (childcon->coninhcount == 1 && !childcon->conislocal)
14342 recurse,
true, missing_ok,
14348 childcon->coninhcount--;
14363 childcon->coninhcount--;
14364 if (childcon->coninhcount == 0)
14365 childcon->conislocal =
true;
14403 bool recurse,
bool recursing,
14407 char *colName = cmd->
name;
14415 int32 targettypmod;
14424 if (rel->
rd_rel->reloftype && !recursing)
14426 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14427 errmsg(
"cannot alter column type of typed table"),
14434 (
errcode(ERRCODE_UNDEFINED_COLUMN),
14435 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
14439 attnum = attTup->attnum;
14444 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14445 errmsg(
"cannot alter system column \"%s\"", colName),
14454 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
14455 errmsg(
"cannot specify USING when altering type of generated column"),
14456 errdetail(
"Column \"%s\" is a generated column.", colName),
14464 if (attTup->attinhcount > 0 && !recursing)
14466 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14467 errmsg(
"cannot alter inherited column \"%s\"", colName),
14475 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14476 errmsg(
"cannot alter column \"%s\" because it is part of the partition key of relation \"%s\"",
14495 if (attTup->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
14499 else if (tab->
relkind == RELKIND_RELATION ||
14500 tab->
relkind == RELKIND_PARTITIONED_TABLE)
14514 attTup->atttypid, attTup->atttypmod,
14515 attTup->attcollation,
14521 targettype, targettypmod,
14525 if (transform == NULL)
14530 (
errcode(ERRCODE_DATATYPE_MISMATCH),
14531 errmsg(
"result of USING clause for column \"%s\""
14532 " cannot be cast automatically to type %s",
14534 errhint(
"You might need to add an explicit cast.")));
14537 (
errcode(ERRCODE_DATATYPE_MISMATCH),
14538 errmsg(
"column \"%s\" cannot be cast automatically to type %s",
14540 !attTup->attgenerated ?
14542 errhint(
"You might need to specify \"USING %s::%s\".",
14545 targettypmod)) : 0));
14564 newval->is_generated =
false;
14570 else if (transform)
14572 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14573 errmsg(
"\"%s\" is not a table",
14576 if (!RELKIND_HAS_STORAGE(tab->
relkind) || attTup->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
14605 &child_numparents);
14612 forboth(lo, child_oids, li, child_numparents)
14620 if (childrelid == relid)
14637 (
errcode(ERRCODE_UNDEFINED_COLUMN),
14638 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
14642 if (childattTup->attinhcount > numparents)
14644 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14645 errmsg(
"cannot alter inherited column \"%s\" of relation \"%s\"",
14657 bool found_whole_row;
14670 if (found_whole_row)
14672 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14673 errmsg(
"cannot convert whole-row table reference"),
14674 errdetail(
"USING expression contains a whole-row table reference.")));
14677 ATPrepCmd(wqueue, childrel, cmd,
false,
true, lockmode, context);
14681 else if (!recursing &&
14684 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14685 errmsg(
"type of inherited column \"%s\" must be changed in child tables too",
14688 if (tab->
relkind == RELKIND_COMPOSITE_TYPE)
14714 if (
IsA(expr,
Var) && ((
Var *) expr)->varattno == varattno)
14732 case F_TIMESTAMPTZ_TIMESTAMP:
14733 case F_TIMESTAMP_TIMESTAMPTZ:
14757 char *colName = cmd->
name;
14767 int32 targettypmod;
14798 (
errcode(ERRCODE_UNDEFINED_COLUMN),
14799 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
14802 attnum = attTup->attnum;
14806 if (attTup->atttypid != attOldTup->atttypid ||
14807 attTup->atttypmod != attOldTup->atttypmod)
14809 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14810 errmsg(
"cannot alter type of column \"%s\" twice",
14814 typeTuple =
typenameType(NULL, typeName, &targettypmod);
14816 targettype = tform->oid;
14832 if (attTup->atthasdef)
14838 defaultexpr,
exprType(defaultexpr),
14839 targettype, targettypmod,
14843 if (defaultexpr == NULL)
14845 if (attTup->attgenerated)
14847 (
errcode(ERRCODE_DATATYPE_MISMATCH),
14848 errmsg(
"generation expression for column \"%s\" cannot be cast automatically to type %s",
14852 (
errcode(ERRCODE_DATATYPE_MISMATCH),
14853 errmsg(
"default for column \"%s\" cannot be cast automatically to type %s",
14858 defaultexpr = NULL;
14879 Anum_pg_depend_classid,
14883 Anum_pg_depend_objid,
14887 Anum_pg_depend_objsubid,
14899 foundObject.
classId = foundDep->refclassid;
14900 foundObject.
objectId = foundDep->refobjid;
14904 elog(
ERROR,
"found unexpected dependency type '%c'",
14905 foundDep->deptype);
14906 if (!(foundDep->refclassid == TypeRelationId &&
14907 foundDep->refobjid == attTup->atttypid) &&
14908 !(foundDep->refclassid == CollationRelationId &&
14909 foundDep->refobjid == attTup->attcollation))
14910 elog(
ERROR,
"found unexpected dependency for column: %s",
14925 if (attTup->atthasmissing)
14935 Anum_pg_attribute_attmissingval,
14936 attrelation->rd_att,
14952 Datum valuesAtt[Natts_pg_attribute] = {0};
14953 bool nullsAtt[Natts_pg_attribute] = {0};
14954 bool replacesAtt[Natts_pg_attribute] = {0};
14972 valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
14973 replacesAtt[Anum_pg_attribute_attmissingval - 1] =
true;
14974 nullsAtt[Anum_pg_attribute_attmissingval - 1] =
false;
14977 valuesAtt, nullsAtt, replacesAtt);
14984 attTup->atttypid = targettype;
14985 attTup->atttypmod = targettypmod;
14986 attTup->attcollation = targetcollid;
14989 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
14990 errmsg(
"too many array dimensions"));
14991 attTup->attndims =
list_length(typeName->arrayBounds);
14992 attTup->attlen = tform->typlen;
14993 attTup->attbyval = tform->typbyval;
14994 attTup->attalign = tform->typalign;
14995 attTup->attstorage = tform->typstorage;
15030 if (attTup->attgenerated)
15035 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
15084 Anum_pg_depend_refclassid,
15088 Anum_pg_depend_refobjid,
15092 Anum_pg_depend_refobjsubid,
15104 foundObject.
classId = foundDep->classid;
15105 foundObject.
objectId = foundDep->objid;
15110 case RelationRelationId:
15114 if (relKind == RELKIND_INDEX ||
15115 relKind == RELKIND_PARTITIONED_INDEX)
15120 else if (relKind == RELKIND_SEQUENCE)
15131 elog(
ERROR,
"unexpected object depending on column: %s",
15137 case ConstraintRelationId:
15142 case ProcedureRelationId:
15156 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15157 errmsg(
"cannot alter type of a column used by a function or procedure"),
15158 errdetail(
"%s depends on column \"%s\"",
15163 case RewriteRelationId:
15171 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15172 errmsg(
"cannot alter type of a column used by a view or rule"),
15173 errdetail(
"%s depends on column \"%s\"",
15178 case TriggerRelationId:
15191 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15192 errmsg(
"cannot alter type of a column used in a trigger definition"),
15193 errdetail(
"%s depends on column \"%s\"",
15198 case PolicyRelationId:
15210 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15211 errmsg(
"cannot alter type of a column used in a policy definition"),
15212 errdetail(
"%s depends on column \"%s\"",
15217 case AttrDefaultRelationId:
15241 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15242 errmsg(
"cannot alter type of a column used by a generated column"),
15243 errdetail(
"Column \"%s\" is used by generated column \"%s\".",
15252 case StatisticExtRelationId:
15261 case PublicationRelRelationId:
15269 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15270 errmsg(
"cannot alter type of a column used by a publication WHERE clause"),
15271 errdetail(
"%s depends on column \"%s\"",
15282 elog(
ERROR,
"unexpected object depending on column: %s",
15303 elog(
ERROR,
"relation %u has multiple indexes marked as replica identity", tab->
relid);
15318 elog(
ERROR,
"relation %u has multiple clustered indexes", tab->
relid);
15506 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
15509 relid = con->conrelid;
15515 elog(
ERROR,
"could not identify relation associated with constraint %u", oldId);
15517 confrelid = con->confrelid;
15518 conislocal = con->conislocal;
15540 if (relid != tab->
relid)
15544 (
char *)
lfirst(def_item),
15545 wqueue, lockmode, tab->
rewrite);
15547 forboth(oid_item, tab->changedIndexOids,
15548 def_item, tab->changedIndexDefs)
15559 if (relid != tab->relid)
15563 (
char *)
lfirst(def_item),
15564 wqueue, lockmode, tab->rewrite);
15571 forboth(oid_item, tab->changedStatisticsOids,
15572 def_item, tab->changedStatisticsDefs)
15589 if (relid != tab->relid)
15593 (
char *)
lfirst(def_item),
15594 wqueue, lockmode, tab->rewrite);
15603 if (tab->replicaIdentityIndex)
15609 subcmd->
name = tab->replicaIdentityIndex;
15621 if (tab->clusterOnIndex)
15626 cmd->
name = tab->clusterOnIndex;
15659 List *raw_parsetree_list;
15660 List *querytree_list;
15671 querytree_list =
NIL;
15672 foreach(list_item, raw_parsetree_list)
15678 querytree_list =
lappend(querytree_list,
15692 querytree_list =
list_concat(querytree_list, beforeStmts);
15694 querytree_list =
list_concat(querytree_list, afterStmts);
15697 querytree_list =
lappend(querytree_list,
15716 foreach(list_item, querytree_list)
15730 stmt->reset_default_tblspc =
true;
15745 foreach(lcmd,
stmt->cmds)
15761 RelationRelationId, 0);
15783 !rewrite && tab->
rewrite == 0)
15807 elog(
ERROR,
"unexpected statement subtype: %d",
15834 elog(
ERROR,
"unexpected statement subtype: %d",
15835 (
int)
stmt->subtype);
15843 stmt->stxcomment =
GetComment(oldId, StatisticExtRelationId, 0);
15852 elog(
ERROR,
"unexpected statement type: %d",
15872 const char *conname)
15879 comment_str =
GetComment(objid, ConstraintRelationId, 0);
15880 if (comment_str == NULL)
15917 stmt->accessMethod,
15919 stmt->excludeOpNames,
15920 stmt->iswithoutoverlaps))
15925 if (irel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
15957 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
15960 Anum_pg_constraint_conpfeqop);
15967 elog(
ERROR,
"conpfeqop is not a 1-D Oid array");
15971 for (
i = 0;
i < numkeys;
i++)
15984 const char *colName,
15995 Datum repl_val[Natts_pg_attribute];
15996 bool repl_null[Natts_pg_attribute];
15997 bool repl_repl[Natts_pg_attribute];
16012 (
errcode(ERRCODE_UNDEFINED_OBJECT),
16013 errmsg(
"foreign table \"%s\" does not exist",
16026 (
errcode(ERRCODE_UNDEFINED_COLUMN),
16027 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
16032 attnum = atttableform->attnum;
16035 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16036 errmsg(
"cannot alter system column \"%s\"", colName)));
16040 memset(repl_val, 0,
sizeof(repl_val));
16041 memset(repl_null,
false,
sizeof(repl_null));
16042 memset(repl_repl,
false,
sizeof(repl_repl));
16047 Anum_pg_attribute_attfdwoptions,
16059 repl_val[Anum_pg_attribute_attfdwoptions - 1] = datum;
16061 repl_null[Anum_pg_attribute_attfdwoptions - 1] =
true;
16063 repl_repl[Anum_pg_attribute_attfdwoptions - 1] =
true;
16068 repl_val, repl_null, repl_repl);
16074 atttableform->attnum);
16118 elog(
ERROR,
"cache lookup failed for relation %u", relationOid);
16122 switch (tuple_class->relkind)
16124 case RELKIND_RELATION:
16126 case RELKIND_MATVIEW:
16127 case RELKIND_FOREIGN_TABLE:
16128 case RELKIND_PARTITIONED_TABLE:
16131 case RELKIND_INDEX:
16141 if (tuple_class->relowner != newOwnerId)
16143 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16144 errmsg(
"cannot change owner of index \"%s\"",
16145 NameStr(tuple_class->relname)),
16146 errhint(
"Change the ownership of the index's table instead.")));
16148 newOwnerId = tuple_class->relowner;
16151 case RELKIND_PARTITIONED_INDEX:
16155 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16156 errmsg(
"cannot change owner of index \"%s\"",
16157 NameStr(tuple_class->relname)),
16158 errhint(
"Change the ownership of the index's table instead.")));
16160 case RELKIND_SEQUENCE:
16162 tuple_class->relowner != newOwnerId)
16171 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16172 errmsg(
"cannot change owner of sequence \"%s\"",
16173 NameStr(tuple_class->relname)),
16174 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
16175 NameStr(tuple_class->relname),
16179 case RELKIND_COMPOSITE_TYPE:
16183 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16184 errmsg(
"\"%s\" is a composite type",
16185 NameStr(tuple_class->relname)),
16190 case RELKIND_TOASTVALUE:
16196 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16197 errmsg(
"cannot change owner of relation \"%s\"",
16198 NameStr(tuple_class->relname)),
16206 if (tuple_class->relowner != newOwnerId)
16208 Datum repl_val[Natts_pg_class];
16209 bool repl_null[Natts_pg_class];
16210 bool repl_repl[Natts_pg_class];
16222 Oid namespaceOid = tuple_class->relnamespace;
16234 aclresult =
object_aclcheck(NamespaceRelationId, namespaceOid, newOwnerId,
16242 memset(repl_null,
false,
sizeof(repl_null));
16243 memset(repl_repl,
false,
sizeof(repl_repl));
16245 repl_repl[Anum_pg_class_relowner - 1] =
true;
16253 Anum_pg_class_relacl,
16258 tuple_class->relowner, newOwnerId);
16259 repl_repl[Anum_pg_class_relacl - 1] =
true;
16274 tuple_class->relowner,
16282 if (tuple_class->relkind != RELKIND_COMPOSITE_TYPE &&
16283 tuple_class->relkind != RELKIND_INDEX &&
16284 tuple_class->relkind != RELKIND_PARTITIONED_INDEX &&
16285 tuple_class->relkind != RELKIND_TOASTVALUE)
16300 if (tuple_class->relkind == RELKIND_RELATION ||
16301 tuple_class->relkind == RELKIND_PARTITIONED_TABLE ||
16302 tuple_class->relkind == RELKIND_MATVIEW ||
16303 tuple_class->relkind == RELKIND_TOASTVALUE)
16305 List *index_oid_list;
16312 foreach(
i, index_oid_list)
16319 if (tuple_class->reltoastrelid !=
InvalidOid)
16350 Anum_pg_attribute_attrelid,
16354 true, NULL, 1,
key);
16358 Datum repl_val[Natts_pg_attribute];
16359 bool repl_null[Natts_pg_attribute];
16360 bool repl_repl[Natts_pg_attribute];
16367 if (att->attisdropped)
16371 Anum_pg_attribute_attacl,
16378 memset(repl_null,
false,
sizeof(repl_null));
16379 memset(repl_repl,
false,
sizeof(repl_repl));
16382 oldOwnerId, newOwnerId);
16383 repl_repl[Anum_pg_attribute_attacl - 1] =
true;
16388 repl_val, repl_null, repl_repl);
16420 Anum_pg_depend_refclassid,
16424 Anum_pg_depend_refobjid,
16438 if (depForm->refobjsubid == 0 ||
16439 depForm->classid != RelationRelationId ||
16440 depForm->objsubid != 0 ||
16484 (
errcode(ERRCODE_UNDEFINED_OBJECT),
16485 errmsg(
"index \"%s\" for table \"%s\" does not exist",
16495 RelationRelationId, indexOid);
16528 if (amname != NULL)
16530 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
16536 if (rel->
rd_rel->relam == amoid)
16556 Oid oldAccessMethodId;
16572 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
16576 oldAccessMethodId = rd_rel->relam;
16577 rd_rel->relam = newAccessMethodId;
16580 if (rd_rel->relam == oldAccessMethodId)
16616 AccessMethodRelationId,
16626 AccessMethodRelationId,
16627 oldAccessMethodId, rd_rel->relam);
16663 (
errcode(ERRCODE_SYNTAX_ERROR),
16664 errmsg(
"cannot have multiple SET TABLESPACE subcommands")));
16682 Datum repl_val[Natts_pg_class];
16683 bool repl_null[Natts_pg_class];
16684 bool repl_repl[Natts_pg_class];
16696 elog(
ERROR,
"cache lookup failed for relation %u", relid);
16722 switch (rel->
rd_rel->relkind)
16724 case RELKIND_RELATION:
16725 case RELKIND_MATVIEW:
16728 case RELKIND_PARTITIONED_TABLE:
16734 case RELKIND_INDEX:
16735 case RELKIND_PARTITIONED_INDEX:
16738 case RELKIND_TOASTVALUE:
16742 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16743 errmsg(
"cannot set options for relation \"%s\"",
16750 if (rel->
rd_rel->relkind == RELKIND_VIEW)
16755 bool check_option =
false;
16757 foreach(cell, view_options)
16761 if (strcmp(defel->
defname,
"check_option") == 0)
16762 check_option =
true;
16771 const char *view_updatable_error =
16774 if (view_updatable_error)
16776 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16777 errmsg(
"WITH CHECK OPTION is supported only on automatically updatable views"),
16778 errhint(
"%s",
_(view_updatable_error))));
16786 memset(repl_val, 0,
sizeof(repl_val));
16787 memset(repl_null,
false,
sizeof(repl_null));
16788 memset(repl_repl,
false,
sizeof(repl_repl));
16790 if (newOptions != (
Datum) 0)
16791 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
16793 repl_null[Anum_pg_class_reloptions - 1] =
true;
16795 repl_repl[Anum_pg_class_reloptions - 1] =
true;
16798 repl_val, repl_null, repl_repl);
16813 Oid toastid = rel->
rd_rel->reltoastrelid;
16820 elog(
ERROR,
"cache lookup failed for relation %u", toastid);
16846 memset(repl_val, 0,
sizeof(repl_val));
16847 memset(repl_null,
false,
sizeof(repl_null));
16848 memset(repl_repl,
false,
sizeof(repl_repl));
16850 if (newOptions != (
Datum) 0)
16851 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
16853 repl_null[Anum_pg_class_reloptions - 1] =
true;
16855 repl_repl[Anum_pg_class_reloptions - 1] =
true;
16858 repl_val, repl_null, repl_repl);
16904 reltoastrelid = rel->
rd_rel->reltoastrelid;
16919 rel->
rd_rel->relpersistence);
16923 newrlocator.
relNumber = newrelfilenumber;
16924 newrlocator.
spcOid = newTableSpace;
16927 if (rel->
rd_rel->relkind == RELKIND_INDEX)
16959 foreach(lc, reltoastidxids)
17021 Oid orig_tablespaceoid;
17022 Oid new_tablespaceoid;
17029 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17030 errmsg(
"only tables, indexes, and materialized views exist in tablespaces")));
17038 if (orig_tablespaceoid == GLOBALTABLESPACE_OID ||
17039 new_tablespaceoid == GLOBALTABLESPACE_OID)
17041 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17042 errmsg(
"cannot move relations in to or out of pg_global tablespace")));
17071 if (orig_tablespaceoid == new_tablespaceoid)
17072 return new_tablespaceoid;
17079 Anum_pg_class_reltablespace,
17088 Oid relOid = relForm->oid;
17099 relForm->relisshared ||
17106 relForm->relkind != RELKIND_RELATION &&
17107 relForm->relkind != RELKIND_PARTITIONED_TABLE) ||
17109 relForm->relkind != RELKIND_INDEX &&
17110 relForm->relkind != RELKIND_PARTITIONED_INDEX) ||
17112 relForm->relkind != RELKIND_MATVIEW))
17130 if (
stmt->nowait &&
17133 (
errcode(ERRCODE_OBJECT_IN_USE),
17134 errmsg(
"aborting because lock on relation \"%s.%s\" is not available",
17136 NameStr(relForm->relname))));
17147 if (relations ==
NIL)
17149 (
errcode(ERRCODE_NO_DATA_FOUND),
17150 errmsg(
"no matching relations in tablespace \"%s\" found",
17151 orig_tablespaceoid ==
InvalidOid ?
"(database default)" :
17155 foreach(l, relations)
17161 cmd->
name =
stmt->new_tablespacename;
17171 return new_tablespaceoid;
17198 rel->
rd_rel->relpersistence);
17213 (rel->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
17217 rel->
rd_rel->relpersistence);
17233 char fires_when,
bool skip_system,
bool recurse,
17237 fires_when, skip_system, recurse,
17251 char fires_when,
LOCKMODE lockmode)
17269 if (child_rel->
rd_rel->reloftype)
17271 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17272 errmsg(
"cannot change inheritance of typed table")));
17274 if (child_rel->
rd_rel->relispartition)
17276 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17277 errmsg(
"cannot change inheritance of a partition")));
17279 if (child_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
17281 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17282 errmsg(
"cannot change inheritance of partitioned table")));
17294 const char *trigger_name;
17310 if (parent_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
17311 child_rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
17313 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17314 errmsg(
"cannot inherit from temporary relation \"%s\"",
17320 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17321 errmsg(
"cannot inherit from temporary relation of another session")));
17326 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17327 errmsg(
"cannot inherit to temporary relation of another session")));
17330 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
17332 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17333 errmsg(
"cannot inherit from partitioned table \"%s\"",
17337 if (parent_rel->
rd_rel->relispartition)
17339 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17340 errmsg(
"cannot inherit from a partition")));
17361 (
errcode(ERRCODE_DUPLICATE_TABLE),
17362 errmsg(
"circular inheritance not allowed"),
17363 errdetail(
"\"%s\" is already a child of \"%s\".",
17373 if (trigger_name != NULL)
17375 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17376 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming an inheritance child",
17378 errdetail(
"ROW triggers with transition tables are not supported in inheritance hierarchies.")));
17421 Anum_pg_inherits_inhrelid,
17425 true, NULL, 1, &
key);
17435 (
errcode(ERRCODE_DUPLICATE_TABLE),
17436 errmsg(
"relation \"%s\" would be inherited from more than once",
17439 if (inh->inhseqno > inhseqno)
17440 inhseqno = inh->inhseqno;
17457 parent_rel->
rd_rel->relkind ==
17458 RELKIND_PARTITIONED_TABLE);
17477 attr =
heap_getattr(contup, Anum_pg_constraint_conbin, tupdesc, &isnull);
17479 elog(
ERROR,
"null conbin for constraint %u", con->oid);
17502 if (acon->condeferrable != bcon->condeferrable ||
17503 acon->condeferred != bcon->condeferred ||
17534 for (
AttrNumber parent_attno = 1; parent_attno <= parent_desc->
natts; parent_attno++)
17537 char *parent_attname =
NameStr(parent_att->attname);
17541 if (parent_att->attisdropped)
17550 if (parent_att->atttypid != child_att->atttypid ||
17551 parent_att->atttypmod != child_att->atttypmod)
17553 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17554 errmsg(
"child table \"%s\" has different type for column \"%s\"",
17557 if (parent_att->attcollation != child_att->attcollation)
17559 (
errcode(ERRCODE_COLLATION_MISMATCH),
17560 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
17569 if (parent_att->attnotnull && !child_att->attnotnull)
17574 parent_att->attnum);
17578 errcode(ERRCODE_DATATYPE_MISMATCH),
17579 errmsg(
"column \"%s\" in child table \"%s\" must be marked NOT NULL",
17586 if (parent_att->attgenerated && !child_att->attgenerated)
17588 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17589 errmsg(
"column \"%s\" in child table must be a generated column", parent_attname)));
17590 if (child_att->attgenerated && !parent_att->attgenerated)
17592 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17593 errmsg(
"column \"%s\" in child table must not be a generated column", parent_attname)));
17595 if (parent_att->attgenerated && child_att->attgenerated && child_att->attgenerated != parent_att->attgenerated)
17597 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17598 errmsg(
"column \"%s\" inherits from generated column of different kind", parent_attname),
17599 errdetail(
"Parent column is %s, child column is %s.",
17600 parent_att->attgenerated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL",
17601 child_att->attgenerated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL")));
17609 child_att->attidentity = parent_att->attidentity;
17616 &child_att->attinhcount))
17618 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
17619 errmsg(
"too many inheritance parents"));
17626 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
17628 Assert(child_att->attinhcount == 1);
17629 child_att->attislocal =
false;
17638 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17639 errmsg(
"child table is missing column \"%s\"", parent_attname)));
17677 Anum_pg_constraint_conrelid,
17681 true, NULL, 1, &parent_key);
17694 bool found =
false;
17696 if (parent_con->contype != CONSTRAINT_CHECK &&
17697 parent_con->contype != CONSTRAINT_NOTNULL)
17701 if (parent_con->connoinherit)
17704 if (parent_con->contype == CONSTRAINT_NOTNULL)
17711 Anum_pg_constraint_conrelid,
17715 true, NULL, 1, &child_key);
17722 if (child_con->contype != parent_con->contype)
17729 if (child_con->contype == CONSTRAINT_CHECK)
17731 if (strcmp(
NameStr(parent_con->conname),
17732 NameStr(child_con->conname)) != 0)
17735 else if (child_con->contype == CONSTRAINT_NOTNULL)
17743 if (parent_attno != attmap->
attnums[child_attno - 1])
17748 if (parent_attr->attisdropped || child_attr->attisdropped)
17749 elog(
ERROR,
"found not-null constraint on dropped columns");
17752 if (child_con->contype == CONSTRAINT_CHECK &&
17755 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17756 errmsg(
"child table \"%s\" has different definition for check constraint \"%s\"",
17762 if (child_con->connoinherit)
17764 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
17765 errmsg(
"constraint \"%s\" conflicts with non-inherited constraint on child table \"%s\"",
17772 if (parent_con->convalidated && child_con->conenforced &&
17773 !child_con->convalidated)
17775 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
17776 errmsg(
"constraint \"%s\" conflicts with NOT VALID constraint on child table \"%s\"",
17784 if (parent_con->conenforced && !child_con->conenforced)
17786 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
17787 errmsg(
"constraint \"%s\" conflicts with NOT ENFORCED constraint on child table \"%s\"",
17798 &child_con->coninhcount))
17800 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
17801 errmsg(
"too many inheritance parents"));
17808 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
17810 Assert(child_con->coninhcount == 1);
17811 child_con->conislocal =
false;
17825 if (parent_con->contype == CONSTRAINT_NOTNULL)
17827 errcode(ERRCODE_DATATYPE_MISMATCH),
17828 errmsg(
"column \"%s\" in child table \"%s\" must be marked NOT NULL",
17835 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17836 errmsg(
"child table is missing constraint \"%s\"",
17837 NameStr(parent_con->conname))));
17856 if (rel->
rd_rel->relispartition)
17858 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17859 errmsg(
"cannot change inheritance of a partition")));
17899 bool found =
false;
17901 Assert(parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
17909 Anum_pg_inherits_inhparent,
17913 true, NULL, 1, &
key);
17920 if (inhForm->inhdetachpending)
17922 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
17923 errmsg(
"partition \"%s\" already pending detach in partitioned table \"%s.%s\"",
17927 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
17952 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
17987 bool is_partitioning;
17989 is_partitioning = (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
17997 if (is_partitioning)
18000 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
18006 errmsg(
"relation \"%s\" is not a parent of relation \"%s\"",
18016 Anum_pg_attribute_attrelid,
18020 true, NULL, 1,
key);
18026 if (att->attisdropped)
18028 if (att->attinhcount <= 0)
18038 copy_att->attinhcount--;
18039 if (copy_att->attinhcount == 0)
18040 copy_att->attislocal =
true;
18064 Anum_pg_constraint_conrelid,
18068 true, NULL, 1,
key);
18077 if (con->connoinherit)
18080 if (con->contype == CONSTRAINT_CHECK)
18082 if (con->contype == CONSTRAINT_NOTNULL)
18094 Anum_pg_constraint_conrelid,
18098 true, NULL, 1,
key);
18103 bool match =
false;
18109 if (con->contype == CONSTRAINT_CHECK)
18113 if (con->contype == CONSTRAINT_CHECK &&
18114 strcmp(
NameStr(con->conname), chkname) == 0)
18122 else if (con->contype == CONSTRAINT_NOTNULL)
18128 if (prevattno == child_attno)
18145 if (copy_con->coninhcount <= 0)
18146 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
18149 copy_con->coninhcount--;
18150 if (copy_con->coninhcount == 0)
18151 copy_con->conislocal =
true;
18159 if (connames !=
NIL || nncolumns !=
NIL)
18160 elog(
ERROR,
"%d unmatched constraints while removing inheritance from \"%s\" to \"%s\"",
18168 RelationRelationId,
18201 Anum_pg_depend_classid,
18205 Anum_pg_depend_objid,
18209 Anum_pg_depend_objsubid,
18220 if (dep->refclassid == refclassid &&
18221 dep->refobjid == refobjid &&
18222 dep->refobjsubid == 0 &&
18223 dep->deptype == deptype)
18264 typeid = typeform->oid;
18269 Anum_pg_inherits_inhrelid,
18273 true, NULL, 1, &
key);
18276 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18277 errmsg(
"typed tables cannot inherit")));
18288 for (type_attno = 1; type_attno <= typeTupleDesc->
natts; type_attno++)
18292 const char *type_attname,
18297 if (type_attr->attisdropped)
18299 type_attname =
NameStr(type_attr->attname);
18304 if (table_attno > tableTupleDesc->
natts)
18306 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18307 errmsg(
"table is missing column \"%s\"",
18309 table_attr =
TupleDescAttr(tableTupleDesc, table_attno - 1);
18311 }
while (table_attr->attisdropped);
18312 table_attname =
NameStr(table_attr->attname);
18315 if (strncmp(table_attname, type_attname,
NAMEDATALEN) != 0)
18317 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18318 errmsg(
"table has column \"%s\" where type requires \"%s\"",
18319 table_attname, type_attname)));
18322 if (table_attr->atttypid != type_attr->atttypid ||
18323 table_attr->atttypmod != type_attr->atttypmod ||
18324 table_attr->attcollation != type_attr->attcollation)
18326 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18327 errmsg(
"table \"%s\" has different type for column \"%s\"",
18333 for (; table_attno <= tableTupleDesc->
natts; table_attno++)
18338 if (!table_attr->attisdropped)
18340 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18341 errmsg(
"table has extra column \"%s\"",
18342 NameStr(table_attr->attname))));
18346 if (rel->
rd_rel->reloftype)
18351 tableobj.
classId = RelationRelationId;
18354 typeobj.
classId = TypeRelationId;
18363 elog(
ERROR,
"cache lookup failed for relation %u", relid);
18392 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18393 errmsg(
"\"%s\" is not a typed table",
18408 elog(
ERROR,
"cache lookup failed for relation %u", relid);
18446 elog(
ERROR,
"cache lookup failed for relation \"%s\"",
18449 if (pg_class_form->relreplident != ri_type)
18451 pg_class_form->relreplident = ri_type;
18464 bool dirty =
false;
18469 elog(
ERROR,
"cache lookup failed for index %u", thisIndexOid);
18472 if (thisIndexOid == indexOid)
18475 if (!pg_index_form->indisreplident)
18478 pg_index_form->indisreplident =
true;
18484 if (pg_index_form->indisreplident)
18487 pg_index_form->indisreplident =
false;
18522 if (
stmt->identity_type == REPLICA_IDENTITY_DEFAULT)
18527 else if (
stmt->identity_type == REPLICA_IDENTITY_FULL)
18532 else if (
stmt->identity_type == REPLICA_IDENTITY_NOTHING)
18537 else if (
stmt->identity_type == REPLICA_IDENTITY_INDEX)
18542 elog(
ERROR,
"unexpected identity type %u",
stmt->identity_type);
18548 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18549 errmsg(
"index \"%s\" for table \"%s\" does not exist",
18558 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18559 errmsg(
"\"%s\" is not an index for table \"%s\"",
18569 !indexRel->
rd_index->indisunique) &&
18572 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18573 errmsg(
"cannot use non-unique index \"%s\" as replica identity",
18576 if (!indexRel->
rd_index->indimmediate)
18578 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18579 errmsg(
"cannot use non-immediate index \"%s\" as replica identity",
18584 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18585 errmsg(
"cannot use expression index \"%s\" as replica identity",
18590 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18591 errmsg(
"cannot use partial index \"%s\" as replica identity",
18607 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
18608 errmsg(
"index \"%s\" cannot be used as replica identity because column %d is a system column",
18612 if (!attr->attnotnull)
18614 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18615 errmsg(
"index \"%s\" cannot be used as replica identity because column \"%s\" is nullable",
18644 elog(
ERROR,
"cache lookup failed for relation %u", relid);
18673 elog(
ERROR,
"cache lookup failed for relation %u", relid);
18696 Datum repl_val[Natts_pg_foreign_table];
18697 bool repl_null[Natts_pg_foreign_table];
18698 bool repl_repl[Natts_pg_foreign_table];
18711 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18712 errmsg(
"foreign table \"%s\" does not exist",
18718 memset(repl_val, 0,
sizeof(repl_val));
18719 memset(repl_null,
false,
sizeof(repl_null));
18720 memset(repl_repl,
false,
sizeof(repl_repl));
18725 Anum_pg_foreign_table_ftoptions,
18737 repl_val[Anum_pg_foreign_table_ftoptions - 1] = datum;
18739 repl_null[Anum_pg_foreign_table_ftoptions - 1] =
true;
18741 repl_repl[Anum_pg_foreign_table_ftoptions - 1] =
true;
18746 repl_val, repl_null, repl_repl);
18771 const char *column,
18783 compression =
strVal(newValue);
18791 (
errcode(ERRCODE_UNDEFINED_COLUMN),
18792 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
18797 attnum = atttableform->attnum;
18800 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18801 errmsg(
"cannot alter system column \"%s\"", column)));
18810 atttableform->attcompression = cmethod;
18859 switch (rel->
rd_rel->relpersistence)
18861 case RELPERSISTENCE_TEMP:
18863 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
18864 errmsg(
"cannot change logged status of table \"%s\" because it is temporary",
18868 case RELPERSISTENCE_PERMANENT:
18873 case RELPERSISTENCE_UNLOGGED:
18887 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
18888 errmsg(
"cannot change table \"%s\" to unlogged because it is part of a publication",
18890 errdetail(
"Unlogged relations cannot be replicated.")));
18904 toLogged ? Anum_pg_constraint_conrelid :
18905 Anum_pg_constraint_confrelid,
18909 toLogged ? ConstraintRelidTypidNameIndexId :
InvalidOid,
18910 true, NULL, 1, skey);
18916 if (con->contype == CONSTRAINT_FOREIGN)
18922 foreignrelid = toLogged ? con->confrelid : con->conrelid;
18934 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
18935 errmsg(
"could not change table \"%s\" to logged because it references unlogged table \"%s\"",
18944 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
18945 errmsg(
"could not change table \"%s\" to unlogged because it references logged table \"%s\"",
18990 (
errmsg(
"relation \"%s\" does not exist, skipping",
18991 stmt->relation->relname)));
19000 if (rel->
rd_rel->relkind == RELKIND_SEQUENCE)
19008 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19009 errmsg(
"cannot move an owned sequence into another schema"),
19010 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
19029 *oldschema = oldNspOid;
19048 Assert(objsMoved != NULL);
19054 nspOid,
true, objsMoved);
19081 Oid oldNspOid,
Oid newNspOid,
19082 bool hasDependEntry,
19088 bool already_done =
false;
19093 elog(
ERROR,
"cache lookup failed for relation %u", relOid);
19096 Assert(classForm->relnamespace == oldNspOid);
19098 thisobj.
classId = RelationRelationId;
19108 if (!already_done && oldNspOid != newNspOid)
19116 (
errcode(ERRCODE_DUPLICATE_TABLE),
19117 errmsg(
"relation \"%s\" already exists in schema \"%s\"",
19122 classForm->relnamespace = newNspOid;
19129 if (hasDependEntry &&
19132 NamespaceRelationId,
19135 elog(
ERROR,
"could not change schema dependency for relation \"%s\"",
19136 NameStr(classForm->relname));
19165 foreach(l, indexList)
19170 thisobj.
classId = RelationRelationId;
19185 oldNspOid, newNspOid,
19218 Anum_pg_depend_refclassid,
19222 Anum_pg_depend_refobjid,
19236 if (depForm->refobjsubid == 0 ||
19237 depForm->classid != RelationRelationId ||
19238 depForm->objsubid != 0 ||
19255 oldNspOid, newNspOid,
19331 if (oc->
relid == relid)
19349 List *oids_to_truncate =
NIL;
19390 if (oids_to_truncate !=
NIL)
19393 if (oids_to_drop !=
NIL)
19397 foreach(l, oids_to_drop)
19401 object.
classId = RelationRelationId;
19403 object.objectSubId = 0;
19425#ifdef USE_ASSERT_CHECKING
19538 if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE &&
19539 relkind != RELKIND_MATVIEW && relkind != RELKIND_PARTITIONED_TABLE)
19541 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19542 errmsg(
"\"%s\" is not a table or materialized view", relation->
relname)));
19567 elog(
ERROR,
"cache lookup failed for relation %u", relId);
19591 elog(
ERROR,
"cache lookup failed for relation %u", relId);
19600 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
19601 errmsg(
"permission denied: \"%s\" is a system catalog",
19626 relkind = classform->relkind;
19635 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
19636 errmsg(
"permission denied: \"%s\" is a system catalog",
19647 aclresult =
object_aclcheck(NamespaceRelationId, classform->relnamespace,
19674 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19677 if (reltype ==
OBJECT_VIEW && relkind != RELKIND_VIEW)
19679 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19684 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19685 errmsg(
"\"%s\" is not a materialized view", rv->
relname)));
19689 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19692 if (reltype ==
OBJECT_TYPE && relkind != RELKIND_COMPOSITE_TYPE)
19694 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19697 if (reltype ==
OBJECT_INDEX && relkind != RELKIND_INDEX &&
19698 relkind != RELKIND_PARTITIONED_INDEX
19701 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19708 if (reltype !=
OBJECT_TYPE && relkind == RELKIND_COMPOSITE_TYPE)
19710 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19722 if (relkind == RELKIND_INDEX || relkind == RELKIND_PARTITIONED_INDEX)
19724 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19725 errmsg(
"cannot change schema of index \"%s\"",
19727 errhint(
"Change the schema of the table instead.")));
19728 else if (relkind == RELKIND_COMPOSITE_TYPE)
19730 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19731 errmsg(
"cannot change schema of composite type \"%s\"",
19736 else if (relkind == RELKIND_TOASTVALUE)
19738 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19739 errmsg(
"cannot change schema of TOAST table \"%s\"",
19741 errhint(
"Change the schema of the table instead.")));
19770 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19771 errmsg(
"cannot use \"list\" partition strategy with more than one column")));
19779 NULL,
false,
true);
19812 List **partexprs,
Oid *partopclass,
Oid *partcollation,
19820 foreach(lc, partParams)
19826 if (pelem->
name != NULL)
19836 (
errcode(ERRCODE_UNDEFINED_COLUMN),
19837 errmsg(
"column \"%s\" named in partition key does not exist",
19842 if (attform->attnum <= 0)
19844 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19845 errmsg(
"cannot use system column \"%s\" in partition key",
19856 if (attform->attgenerated)
19858 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19859 errmsg(
"cannot use generated column in partition key"),
19860 errdetail(
"Column \"%s\" is a generated column.",
19864 partattrs[attn] = attform->attnum;
19865 atttype = attform->atttypid;
19866 attcollation = attform->attcollation;
19873 char partattname[16];
19887 snprintf(partattname,
sizeof(partattname),
"%d", attn + 1);
19889 atttype, attcollation,
19927 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19928 errmsg(
"partition key expressions cannot contain system column references")));
19940 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19941 errmsg(
"cannot use generated column in partition key"),
19942 errdetail(
"Column \"%s\" is a generated column.",
19948 ((
Var *) expr)->varattno > 0)
19955 partattrs[attn] = ((
Var *) expr)->varattno;
19959 partattrs[attn] = 0;
19960 *partexprs =
lappend(*partexprs, expr);
19991 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19992 errmsg(
"functions in partition key expression must be marked IMMUTABLE")));
20000 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
20001 errmsg(
"cannot use constant expression as partition key")));
20021 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
20022 errmsg(
"could not determine which collation to use for partition expression"),
20023 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
20029 (
errcode(ERRCODE_DATATYPE_MISMATCH),
20030 errmsg(
"collations are not supported by type %s",
20034 partcollation[attn] = attcollation;
20042 am_oid = HASH_AM_OID;
20044 am_oid = BTREE_AM_OID;
20054 (
errcode(ERRCODE_UNDEFINED_OBJECT),
20055 errmsg(
"data type %s has no default operator class for access method \"%s\"",
20057 errhint(
"You must specify a hash operator class or define a default hash operator class for the data type.")));
20060 (
errcode(ERRCODE_UNDEFINED_OBJECT),
20061 errmsg(
"data type %s has no default operator class for access method \"%s\"",
20063 errhint(
"You must specify a btree operator class or define a default btree operator class for the data type.")));
20069 am_oid == HASH_AM_OID ?
"hash" :
"btree",
20086 List *partConstraint)
20096 for (
i = 1;
i <= natts;
i++)
20108 wholeatt->atttypid,
20109 wholeatt->atttypmod,
20110 wholeatt->attcollation,
20119 ntest->argisrow =
false;
20121 existConstraint =
lappend(existConstraint, ntest);
20147 num_check = (constr != NULL) ? constr->
num_check : 0;
20148 for (
i = 0;
i < num_check;
i++)
20204 List *partConstraint,
20205 bool validate_default)
20213 if (!validate_default)
20215 (
errmsg_internal(
"partition constraint for table \"%s\" is implied by existing constraints",
20219 (
errmsg_internal(
"updated partition constraint for default partition \"%s\" is implied by existing constraints",
20229 if (scanrel->
rd_rel->relkind == RELKIND_RELATION)
20239 else if (scanrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
20247 List *thisPartConstraint;
20258 thisPartConstraint =
20260 part_rel, scanrel);
20263 thisPartConstraint,
20315 List *attachrel_children;
20316 List *partConstraint;
20323 const char *trigger_name;
20324 Oid defaultPartOid;
20325 List *partBoundConstraint;
20354 if (attachrel->
rd_rel->relispartition)
20356 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20357 errmsg(
"\"%s\" is already a partition",
20362 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20363 errmsg(
"cannot attach a typed table as partition")));
20371 Anum_pg_inherits_inhrelid,
20378 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20379 errmsg(
"cannot attach inheritance child as partition")));
20384 Anum_pg_inherits_inhparent,
20390 attachrel->
rd_rel->relkind == RELKIND_RELATION)
20392 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20393 errmsg(
"cannot attach inheritance parent as partition")));
20416 (
errcode(ERRCODE_DUPLICATE_TABLE),
20417 errmsg(
"circular inheritance not allowed"),
20418 errdetail(
"\"%s\" is already a child of \"%s\".",
20423 if (rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
20424 attachrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
20426 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20427 errmsg(
"cannot attach a temporary relation as partition of permanent relation \"%s\"",
20431 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
20432 attachrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
20434 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20435 errmsg(
"cannot attach a permanent relation as partition of temporary relation \"%s\"",
20441 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20442 errmsg(
"cannot attach as partition of temporary relation of another session")));
20447 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20448 errmsg(
"cannot attach temporary relation of another session as partition")));
20455 natts = tupleDesc->
natts;
20456 for (attno = 1; attno <= natts; attno++)
20459 char *attributeName =
NameStr(attribute->attname);
20462 if (attribute->attisdropped)
20465 if (attribute->attidentity)
20467 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20468 errmsg(
"table \"%s\" being attached contains an identity column \"%s\"",
20470 errdetail(
"The new partition may not contain an identity column."));
20477 (
errcode(ERRCODE_DATATYPE_MISMATCH),
20478 errmsg(
"table \"%s\" contains column \"%s\" not found in parent \"%s\"",
20481 errdetail(
"The new partition may contain only the columns present in parent.")));
20490 if (trigger_name != NULL)
20492 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20493 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming a partition",
20495 errdetail(
"ROW triggers with transition tables are not supported on partitions.")));
20503 cmd->
bound, pstate);
20523 if (partConstraint)
20532 (
Node *) partConstraint);
20559 List *defPartConstraint;
20565 defPartConstraint =
20572 defPartConstraint =
20574 1, defaultrel, rel);
20576 defPartConstraint,
true);
20590 if (attachrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
20594 foreach(l, attachrel_children)
20618 List *attachRelIdxs;
20626 "AttachPartitionEnsureIndexes",
20650 if (attachrel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
20652 foreach(cell, idxes)
20657 if (idxRel->
rd_index->indisunique ||
20660 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20661 errmsg(
"cannot attach foreign table \"%s\" as partition of partitioned table \"%s\"",
20664 errdetail(
"Partitioned table \"%s\" contains unique indexes.",
20676 foreach(cell, idxes)
20682 bool found =
false;
20689 if (idxRel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
20713 if (attachrelIdxRels[
i]->rd_rel->relispartition)
20717 if (!attachrelIdxRels[
i]->rd_index->indisvalid)
20721 attachrelIdxRels[
i]->rd_indcollation,
20777 true,
false,
false,
false,
false);
20809 true, NULL, 1, &
key);
20828 if (!TRIGGER_FOR_ROW(trigForm->tgtype))
20835 if (trigForm->tgisinternal)
20841 if (!TRIGGER_FOR_BEFORE(trigForm->tgtype) &&
20842 !TRIGGER_FOR_AFTER(trigForm->tgtype))
20843 elog(
ERROR,
"unexpected trigger \"%s\" found",
20859 partition, parent);
20861 partition, parent);
20868 if (trigForm->tgattr.dim1 > 0)
20872 for (
i = 0;
i < trigForm->tgattr.dim1;
i++)
20877 trigForm->tgattr.values[
i] - 1);
20884 if (trigForm->tgnargs > 0)
20891 elog(
ERROR,
"tgargs is null for trigger \"%s\" in partition \"%s\"",
20896 for (
int i = 0;
i < trigForm->tgnargs;
i++)
20899 p += strlen(p) + 1;
20909 trigStmt->
args = trigargs;
20910 trigStmt->
row =
true;
20911 trigStmt->
timing = trigForm->tgtype & TRIGGER_TYPE_TIMING_MASK;
20912 trigStmt->
events = trigForm->tgtype & TRIGGER_TYPE_EVENT_MASK;
20916 trigStmt->
deferrable = trigForm->tgdeferrable;
20922 trigForm->tgfoid, trigForm->oid, qual,
20923 false,
true, trigForm->tgenabled);
20959 Oid defaultPartOid;
20986 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20987 errmsg(
"cannot detach partitions concurrently when a default partition exists")));
21029 char *parentrelname;
21085 if (partRel != NULL)
21086 elog(
WARNING,
"dangling partition \"%s\" remains, can't fix",
21089 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
21090 errmsg(
"partitioned table \"%s\" was removed concurrently",
21093 if (partRel == NULL)
21095 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
21096 errmsg(
"partition \"%s\" was removed concurrently", partrelname)));
21128 Oid defaultPartOid)
21134 Datum new_val[Natts_pg_class];
21135 bool new_null[Natts_pg_class],
21136 new_repl[Natts_pg_class];
21193 if (conform->contype != CONSTRAINT_FOREIGN ||
21215 Oid insertTriggerOid,
21220 &insertTriggerOid, &updateTriggerOid);
21247 int numfkdelsetcols;
21263 fkconstraint->
contype = CONSTRAINT_FOREIGN;
21265 fkconstraint->
deferrable = conform->condeferrable;
21267 fkconstraint->
is_enforced = conform->conenforced;
21271 fkconstraint->
pktable = NULL;
21283 for (
int i = 0;
i < numfks;
i++)
21310 conform->conperiod);
21333 ConstraintRelationId,
21343 foreach(cell, indexes)
21349 Oid parentConstrOid;
21381 elog(
ERROR,
"cache lookup failed for relation %u",
21386 memset(new_val, 0,
sizeof(new_val));
21387 memset(new_null,
false,
sizeof(new_null));
21388 memset(new_repl,
false,
sizeof(new_repl));
21389 new_val[Anum_pg_class_relpartbound - 1] = (
Datum) 0;
21390 new_null[Anum_pg_class_relpartbound - 1] =
true;
21391 new_repl[Anum_pg_class_relpartbound - 1] =
true;
21393 new_val, new_null, new_repl);
21407 if (!attr->attisdropped && attr->attidentity)
21441 if (partRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
21447 foreach(cell, children)
21512 true, NULL, 1, &skey);
21538 RelationRelationId,
21577 if (!
state->lockedParentTbl)
21580 state->lockedParentTbl =
true;
21603 if (classform->relkind != RELKIND_PARTITIONED_INDEX &&
21604 classform->relkind != RELKIND_INDEX)
21606 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
21641 state.lockedParentTbl =
false;
21649 (
errcode(ERRCODE_UNDEFINED_OBJECT),
21650 errmsg(
"index \"%s\" does not exist",
name->relname)));
21662 currParent = partIdx->
rd_rel->relispartition ?
21683 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
21684 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
21687 errdetail(
"Index \"%s\" is already attached to another index.",
21695 if (partDesc->
oids[
i] ==
state.partitionOid)
21703 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
21704 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
21707 errdetail(
"Index \"%s\" is not an index on any partition of table \"%s\".",
21724 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
21725 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
21728 errdetail(
"The index definitions do not match.")));
21743 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
21744 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
21747 errdetail(
"The index \"%s\" belongs to a constraint in table \"%s\" but no constraint exists for index \"%s\".",
21757 if (parentIdx->
rd_index->indisprimary)
21792 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
21793 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
21796 errdetail(
"Another index \"%s\" is already attached for partition \"%s\".",
21815 bool updated =
false;
21817 Assert(partedIdx->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX);
21839 elog(
ERROR,
"cache lookup failed for index %u", inhForm->inhrelid);
21841 if (indexForm->indisvalid)
21864 elog(
ERROR,
"cache lookup failed for index %u",
21868 indexForm->indisvalid =
true;
21881 if (updated && partedIdx->
rd_rel->relispartition)
21917 if (!att->attnotnull)
21919 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
21920 errmsg(
"invalid primary key definition"),
21921 errdetail(
"Column \"%s\" of relation \"%s\" is not marked NOT NULL.",
21970 constraints =
lappend_oid(constraints, constrForm->oid);
21976 return constraints;
21992 foreach(cell, constraints)
22002 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
22038 if (compression == NULL || strcmp(compression,
"default") == 0)
22055 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
22056 errmsg(
"column data type %s does not support compression",
22062 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
22063 errmsg(
"invalid compression method \"%s\"", compression)));
22077 cstorage = TYPSTORAGE_PLAIN;
22079 cstorage = TYPSTORAGE_EXTERNAL;
22081 cstorage = TYPSTORAGE_EXTENDED;
22083 cstorage = TYPSTORAGE_MAIN;
22088 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
22089 errmsg(
"invalid storage type \"%s\"",
22098 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
22099 errmsg(
"column data type %s can only have storage PLAIN",
22120 switch (con->contype)
22134 elog(
ERROR,
"unrecognized constraint type: %d",
22135 (
int) con->contype);
22159 if (!ex->is_generated)
22170 switch (con->contype)
22173 if (!
ExecCheck(con->qualstate, econtext))
22175 errcode(ERRCODE_CHECK_VIOLATION),
22176 errmsg(
"check constraint \"%s\" of relation \"%s\" is violated by some row",
22185 elog(
ERROR,
"unrecognized constraint type: %d",
22186 (
int) con->contype);
22203 for (parent_attno = 1; parent_attno <= modelDesc->
natts;
22211 if (attribute->attisdropped)
22215 attribute->atttypmod, attribute->attcollation);
22220 def->
identity = attribute->attidentity;
22223 def->
generated = attribute->attgenerated;
22225 def->
storage = attribute->attstorage;
22235 colList =
lappend(colList, def);
22257 List *cookedConstraints =
NIL;
22260 constr = tupleDesc->
constr;
22275 for (parent_attno = 1; parent_attno <= tupleDesc->
natts; parent_attno++)
22281 if (attribute->attisdropped)
22285 if (attribute->atthasdef)
22287 Node *this_default = NULL;
22288 bool found_whole_row;
22293 if (attribute->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
22298 if (this_default == NULL)
22299 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
22303 num = attmap->
attnums[parent_attno - 1];
22306 if (found_whole_row && attribute->attgenerated !=
'\0')
22307 elog(
ERROR,
"cannot convert whole-row table reference");
22318 if (attribute->attgenerated == ATTRIBUTE_GENERATED_STORED)
22323 newval->is_generated = (attribute->attgenerated !=
'\0');
22330 for (ccnum = 0; ccnum < constr->
num_check; ccnum++)
22338 bool found_whole_row;
22356 if (found_whole_row)
22357 elog(
ERROR,
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
22373 constraints =
lappend(constraints, constr);
22378 false,
true,
true, NULL);
22391 if (!ccon->skip_validation)
22410 newcon->
name = ccon->name;
22412 newcon->
qual = qual;
22425 List *nnconstraints;
22471 errcode(ERRCODE_WRONG_OBJECT_TYPE),
22472 errmsg(
"cannot create as partition of temporary relation of another session"));
22481 relamId = (parent_relform->relam !=
InvalidOid) ? parent_relform->relam : HEAP_TABLE_AM_OID;
22488 errcode(ERRCODE_DUPLICATE_TABLE),
22489 errmsg(
"relation \"%s\" already exists", newPartName->
relname));
22497 if (parent_relform->relpersistence != RELPERSISTENCE_TEMP &&
22500 errcode(ERRCODE_WRONG_OBJECT_TYPE),
22501 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
22506 parent_relform->relpersistence == RELPERSISTENCE_TEMP)
22508 errcode(ERRCODE_WRONG_OBJECT_TYPE),
22509 errmsg(
"cannot create a permanent relation as partition of temporary relation \"%s\"",
22515 parent_relform->reltablespace,
22650 insertslot = dstslot;
22676 insertslot, econtext);
22680 ti_options, bistate);
22706 foreach(ltab, *wqueue)
22747 List *mergingPartitions =
NIL;
22748 Oid defaultPartOid;
22752 int save_sec_context;
22753 int save_nestlevel;
22775 if (ownerId != mergingPartition->
rd_rel->relowner)
22777 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
22778 errmsg(
"partitions being merged have different owners"));
22781 ownerId = mergingPartition->
rd_rel->relowner;
22784 mergingPartitions =
lappend_oid(mergingPartitions,
22829 errcode(ERRCODE_DUPLICATE_TABLE),
22838 foreach_oid(mergingPartitionOid, mergingPartitions)
22858 foreach_oid(mergingPartitionOid, mergingPartitions)
22863 object.
objectId = mergingPartitionOid;
22864 object.classId = RelationRelationId;
22865 object.objectSubId = 0;
22895 foreach_oid(mergingPartitionOid, mergingPartitions)
22899 object.
objectId = mergingPartitionOid;
22900 object.classId = RelationRelationId;
22901 object.objectSubId = 0;
22979 foreach(ltab, *wqueue)
23005 List *partlist,
List *newPartRels)
23027 forboth(listptr, partlist, listptr2, newPartRels)
23044 defaultPartCtx = pc;
23048 List *partConstraint;
23054 (
Node *) partConstraint);
23065 pc->partqualstate =
23067 Assert(pc->partqualstate != NULL);
23071 partContexts =
lappend(partContexts, pc);
23100 bool found =
false;
23108 foreach(listptr, partContexts)
23113 if (pc->partqualstate &&
ExecCheck(pc->partqualstate, econtext))
23122 if (defaultPartCtx)
23123 pc = defaultPartCtx;
23126 errcode(ERRCODE_CHECK_VIOLATION),
23127 errmsg(
"can not find partition for split partition row"),
23142 insertslot = pc->dstslot;
23168 insertslot, econtext);
23172 ti_options, pc->bistate);
23204 bool isSameName =
false;
23208 Oid defaultPartOid;
23210 int save_sec_context;
23211 int save_nestlevel;
23235 if (existingRelid == splitRelOid && !isSameName)
23240 errcode(ERRCODE_DUPLICATE_TABLE),
23241 errmsg(
"relation \"%s\" already exists", sps->name->relname));
23256 object.objectId = splitRelOid;
23257 object.classId = RelationRelationId;
23258 object.objectSubId = 0;
23289 splitRel->
rd_rel->relowner);
23290 newPartRels =
lappend(newPartRels, newPartRel);
23328 object.classId = RelationRelationId;
23329 object.objectId = splitRelOid;
23330 object.objectSubId = 0;
Datum idx(PG_FUNCTION_ARGS)
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
void check_can_set_role(Oid member, Oid role)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
StrategyNumber IndexAmTranslateCompareType(CompareType cmptype, Oid amoid, Oid opfamily, bool missing_ok)
Oid get_table_am_oid(const char *amname, bool missing_ok)
char * get_am_name(Oid amOid)
#define DatumGetArrayTypeP(X)
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
void free_attrmap(AttrMap *map)
AttrMap * make_attrmap(int maplen)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
AttrMap * build_attrmap_by_name_if_req(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 * raw_parser(const char *str, RawParseMode mode)
bool TimestampTimestampTzRequiresRewrite(void)
Bitmapset * bms_make_singleton(int x)
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
Bitmapset * bms_del_member(Bitmapset *a, int x)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
void FlushRelationBuffers(Relation rel)
#define TextDatumGetCString(d)
#define PG_USED_FOR_ASSERTS_ONLY
#define InvalidSubTransactionId
#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)
bool contain_volatile_functions(Node *clause)
void check_index_is_clusterable(Relation OldHeap, Oid indexOid, LOCKMODE lockmode)
void finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, bool is_system_catalog, bool swap_toast_by_content, bool check_constraints, bool is_internal, TransactionId frozenXid, MultiXactId cutoffMulti, char newrelpersistence)
Oid make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, Oid NewAccessMethod, char relpersistence, LOCKMODE lockmode)
void mark_index_clustered(Relation rel, Oid indexOid, bool is_internal)
void ResetSequence(Oid seq_relid)
void SequenceChangePersistence(Oid relid, char newrelpersistence)
int32 defGetInt32(DefElem *def)
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
void performDeletionCheck(const ObjectAddress *object, DropBehavior behavior, int flags)
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
void free_object_addresses(ObjectAddresses *addrs)
#define PERFORM_DELETION_CONCURRENTLY
@ DEPENDENCY_PARTITION_PRI
@ DEPENDENCY_PARTITION_SEC
#define PERFORM_DELETION_QUIETLY
#define PERFORM_DELETION_INTERNAL
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
void hash_destroy(HTAB *hashp)
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 * ExecInitExpr(Expr *node, PlanState *parent)
ExprState * ExecPrepareExpr(Expr *node, EState *estate)
bool ExecCheck(ExprState *state, ExprContext *econtext)
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, ResultRelInfo *partition_root_rri, int instrument_options)
AttrNumber ExecRelGenVirtualNotNull(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate, List *notnull_virtual_attrs)
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
HeapTuple ExecFetchSlotHeapTuple(TupleTableSlot *slot, bool materialize, bool *shouldFree)
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
void FreeExecutorState(EState *estate)
EState * CreateExecutorState(void)
struct ResultRelInfo ResultRelInfo
#define GetPerTupleExprContext(estate)
#define ResetExprContext(econtext)
#define GetPerTupleMemoryContext(estate)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
#define palloc_object(type)
#define palloc_array(type, count)
#define palloc0_object(type)
#define DirectFunctionCall2(func, arg1, arg2)
#define DatumGetByteaPP(X)
#define SizeForFunctionCallInfo(nargs)
#define LOCAL_FCINFO(name, nargs)
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
ForeignServer * GetForeignServer(Oid serverid)
Oid GetForeignServerIdByRelId(Oid relid)
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)
struct RelationData * Relation
bool allowSystemTableMods
int NewGUCNestLevel(void)
void RestrictSearchPath(void)
void AtEOXact_GUC(bool isCommit, int nestLevel)
Assert(PointerIsAligned(start, uint64))
void RelationClearMissing(Relation rel)
List * heap_truncate_find_FKs(List *relationIds)
void StorePartitionKey(Relation rel, char strategy, int16 partnatts, AttrNumber *partattrs, List *partexprs, Oid *partopclass, Oid *partcollation)
void RemoveStatistics(Oid relid, AttrNumber attnum)
Oid heap_create_with_catalog(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, Oid reltypeid, Oid reloftypeid, Oid ownerid, Oid accessmtd, TupleDesc tupdesc, List *cooked_constraints, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, OnCommitAction oncommit, Datum reloptions, bool use_user_acl, bool allow_system_table_mods, bool is_internal, Oid relrewrite, ObjectAddress *typaddress)
void heap_truncate(List *relids)
void CheckAttributeType(const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, int flags)
void heap_truncate_check_FKs(List *relations, bool tempTables)
void StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
List * AddRelationNotNullConstraints(Relation rel, List *constraints, List *old_notnulls)
List * AddRelationNewConstraints(Relation rel, List *newColDefaults, List *newConstraints, bool allow_merge, bool is_local, bool is_internal, const char *queryString)
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)
void StoreAttrMissingVal(Relation rel, AttrNumber attnum, Datum missingval)
#define CHKATYPE_IS_VIRTUAL
#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)
static void * GETSTRUCT(const HeapTupleData *tuple)
#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)
IndexInfo * BuildIndexInfo(Relation index)
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)
#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, const ItemPointerData *otid, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
static bool pg_add_s16_overflow(int16 a, int16 b, int16 *result)
void AcceptInvalidationMessages(void)
void CacheInvalidateRelcache(Relation relation)
void CacheInvalidateRelcacheByRelid(Oid relid)
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
if(TABLE==NULL||TABLE_index==NULL)
Datum is_valid(PG_FUNCTION_ARGS)
List * lcons_oid(Oid datum, List *list)
List * lappend(List *list, void *datum)
List * list_difference_ptr(const List *list1, const List *list2)
List * list_delete_nth_cell(List *list, int n)
List * list_concat(List *list1, const List *list2)
List * list_delete_cell(List *list, ListCell *cell)
List * list_concat_copy(const List *list1, const List *list2)
List * list_copy(const List *oldlist)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
List * lcons(void *datum, List *list)
List * list_append_unique_oid(List *list, Oid datum)
void list_free(List *list)
bool list_member_oid(const List *list, Oid datum)
void list_free_deep(List *list)
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
void UnlockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
bool CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode, bool orstronger)
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
#define AccessExclusiveLock
#define ShareRowExclusiveLock
#define InplaceUpdateTupleLock
#define ShareUpdateExclusiveLock
char * get_rel_name(Oid relid)
AttrNumber get_attnum(Oid relid, const char *attname)
Oid get_constraint_index(Oid conoid)
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_collation_name(Oid colloid)
bool get_index_isclustered(Oid index_oid)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
char * get_constraint_name(Oid conoid)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
bool get_collation_isdeterministic(Oid colloid)
char * get_opfamily_name(Oid opfid, bool missing_ok)
Oid get_rel_relam(Oid relid)
bool type_is_collatable(Oid typid)
Oid get_rel_tablespace(Oid relid)
Oid get_typ_typrelid(Oid typid)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Oid getBaseType(Oid typid)
char * get_namespace_name(Oid nspid)
char get_constraint_type(Oid conoid)
Oid get_relname_relid(const char *relname, Oid relnamespace)
#define TypeIsToastable(typid)
Expr * make_ands_explicit(List *andclauses)
TypeName * makeTypeNameFromNameList(List *names)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
ColumnDef * makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Constraint * makeNotNullConstraint(String *colname)
List * make_ands_implicit(Expr *clause)
char * MemoryContextStrdup(MemoryContext context, const char *string)
void MemoryContextReset(MemoryContext context)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
MemoryContext CacheMemoryContext
void MemoryContextDelete(MemoryContext context)
MemoryContext PortalContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define ALLOCSET_SMALL_SIZES
#define SECURITY_RESTRICTED_OPERATION
#define CHECK_FOR_INTERRUPTS()
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
bool InSecurityRestrictedOperation(void)
void SetUserIdAndSecContext(Oid userid, int sec_context)
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)
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)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
@ 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)
Oid attnumCollationId(Relation rd, int attid)
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
Oid attnumTypeId(Relation rd, int attid)
const NameData * attnumAttName(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 * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
AlterTableStmt * transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, const char *queryString, List **beforeStmts, List **afterStmts)
CreateStatsStmt * transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
PartitionBoundSpec * transformPartitionBound(ParseState *pstate, Relation parent, PartitionBoundSpec *spec)
IndexStmt * generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx, const AttrMap *attmap, Oid *constraintOid)
#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)
List * map_partition_varattnos(List *expr, int fromrel_varno, Relation to_rel, Relation from_rel)
bool has_partition_attrs(Relation rel, Bitmapset *attnums, bool *used_in_expr)
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 StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr, bool is_internal)
Oid GetAttrDefaultOid(Oid relid, AttrNumber attnum)
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
Oid CreateConstraintEntry(const char *constraintName, Oid constraintNamespace, char constraintType, bool isDeferrable, bool isDeferred, bool isEnforced, 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, int16 conInhCount, bool conNoInherit, bool conPeriod, bool is_internal)
HeapTuple findNotNullConstraint(Oid relid, const char *colname)
bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)
void FindFKPeriodOpers(Oid opclass, Oid *containedbyoperoid, Oid *aggedcontainedbyoperoid, Oid *intersectoperoid)
void RenameConstraintById(Oid conId, const char *newname)
Oid get_relation_idx_constraint_oid(Oid relationId, Oid indexId)
void ConstraintSetParentConstraint(Oid childConstrId, Oid parentConstrId, Oid childTableId)
void DeconstructFkConstraintRow(HeapTuple tuple, int *numfks, AttrNumber *conkey, AttrNumber *confkey, Oid *pf_eq_oprs, Oid *pp_eq_oprs, Oid *ff_eq_oprs, int *num_fk_del_set_cols, AttrNumber *fk_del_set_cols)
HeapTuple findNotNullConstraintAttnum(Oid relid, AttrNumber attnum)
void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, Oid newNspId, bool isType, ObjectAddresses *objsMoved)
List * RelationGetNotNullConstraints(Oid relid, bool cooked, bool include_noinh)
char * ChooseConstraintName(const char *name1, const char *name2, const char *label, Oid namespaceid, List *others)
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)
List * getOwnedSequences(Oid relid)
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId, char deptype, Oid refclassId, Oid refobjectId)
Oid getIdentitySequence(Relation rel, AttrNumber attnum, bool missing_ok)
Oid get_index_constraint(Oid indexId)
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
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
bool DeleteInheritsTuple(Oid inhrelid, Oid inhparent, bool expect_detach_pending, const char *childname)
List * find_inheritance_children(Oid parentrelId, LOCKMODE lockmode)
void StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)
bool has_superclass(Oid relationId)
bool PartitionHasPendingDetach(Oid partoid)
FormData_pg_inherits * Form_pg_inherits
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
#define foreach_current_index(var_or_cell)
#define foreach_delete_current(lst, var_or_cell)
#define list_make1_oid(x1)
#define foreach_ptr(type, var, lst)
#define for_each_from(cell, lst, N)
static void * list_nth(const List *list, int n)
#define list_make3(x1, x2, x3)
#define foreach_node(type, var, lst)
static ListCell * list_head(const List *l)
#define foreach_oid(var, lst)
#define list_nth_node(type, list, n)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make2(x1, x2)
#define foreach_int(var, lst)
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)
static char buf[DEFAULT_XLOG_SEG_SIZE]
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)
static Datum PointerGetDatum(const void *X)
static Datum Int16GetDatum(int16 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)
Oid RelationGetPrimaryKeyIndex(Relation relation, bool deferrable_ok)
int errtableconstraint(Relation rel, const char *conname)
int errtablecol(Relation rel, int attnum)
List * RelationGetIndexPredicate(Relation relation)
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
void RelationSetNewRelfilenumber(Relation relation, char persistence)
List * RelationGetFKeyList(Relation relation)
List * RelationGetIndexExpressions(Relation relation)
void RelationAssumeNewRelfilelocator(Relation relation)
int errtable(Relation rel)
@ INDEX_ATTR_BITMAP_PRIMARY_KEY
@ INDEX_ATTR_BITMAP_IDENTITY_KEY
List * untransformRelOptions(Datum options)
bytea * view_reloptions(Datum reloptions, bool validate)
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
Datum transformRelOptions(Datum oldOptions, List *defList, const char *nameSpace, const char *const validnsps[], bool acceptOidsOff, bool isReset)
LOCKMODE AlterTableGetRelOptionsLockLevel(List *defList)
bytea * attribute_reloptions(Datum reloptions, bool validate)
bytea * heap_reloptions(char relkind, 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
Query * get_view_query(Relation view)
const char * view_query_is_auto_updatable(Query *viewquery, bool check_cols)
Node * build_generation_expression(Relation rel, int attrno)
Node * build_column_default(Relation rel, int attrno)
Node * expand_generated_columns_in_expr(Node *node, Relation rel, int rt_index)
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_statisticsobjdef_string(Oid statextid)
char * pg_get_indexdef_string(Oid indexrelid)
const char * quote_identifier(const char *ident)
Datum pg_get_expr(PG_FUNCTION_ARGS)
char * pg_get_constraintdef_command(Oid constraintId)
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)
void check_stack_depth(void)
ObjectAddress CreateStatistics(CreateStatsStmt *stmt, bool check_rights)
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
MemoryContext es_query_cxt
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
PartitionBoundSpec * bound
ExprState * partqualstate
TupleTableSlot * tg_trigslot
bool has_generated_virtual
const char * skipping_msg
const char * nonexistent_msg
const char * drophint_msg
Oid values[FLEXIBLE_ARRAY_MEMBER]
#define FirstLowInvalidHeapAttributeNumber
#define TableOidAttributeNumber
HeapTuple SearchSysCacheCopyAttName(Oid relid, const char *attname)
HeapTuple SearchSysCacheCopyAttNum(Oid relid, int16 attnum)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCacheLocked1(int cacheId, Datum key1)
HeapTuple SearchSysCacheLockedCopy1(int cacheId, Datum key1)
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)
Relation table_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
char * default_table_access_method
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, ScanKeyData *key)
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
static void table_endscan(TableScanDesc scan)
#define TABLE_INSERT_SKIP_FSM
static void table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, int options, BulkInsertStateData *bistate)
static void table_finish_bulk_insert(Relation rel, int options)
static void table_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key)
static void QueueFKConstraintValidation(List **wqueue, Relation conrel, Relation fkrel, Oid pkrelid, HeapTuple contuple, LOCKMODE lockmode)
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 int validateFkOnDeleteSetColumns(int numfks, const int16 *fkattnums, int numfksetcols, int16 *fksetcolsattnums, List *fksetcols)
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 void AlterConstrEnforceabilityRecurse(List **wqueue, ATAlterConstraint *cmdcon, Relation conrel, Relation tgrel, Oid fkrelid, Oid pkrelid, HeapTuple contuple, LOCKMODE lockmode, Oid ReferencedParentDelTrigger, Oid ReferencedParentUpdTrigger, Oid ReferencingParentInsTrigger, Oid ReferencingParentUpdTrigger)
static ObjectAddress ATExecAddInherit(Relation child_rel, RangeVar *parent, LOCKMODE lockmode)
ObjectAddress RenameRelation(RenameStmt *stmt)
static AlteredTableInfo * ATGetQueueEntry(List **wqueue, Relation rel)
static void verifyNotNullPKCompatible(HeapTuple tuple, const char *colname)
static void ATExecDropOf(Relation rel, LOCKMODE lockmode)
static ObjectAddress ATExecAlterConstraint(List **wqueue, Relation rel, ATAlterConstraint *cmdcon, bool recurse, LOCKMODE lockmode)
static ColumnDef * MergeInheritedAttribute(List *inh_columns, int exist_attno, const ColumnDef *newdef)
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, bool with_period)
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 MergePartitionsMoveRows(List **wqueue, List *mergingPartitions, Relation newPartRel)
static void drop_parent_dependency(Oid relid, Oid refclassid, Oid refobjid, DependencyType deptype)
static void DropForeignKeyConstraintTriggers(Relation trigrel, Oid conoid, Oid confrelid, Oid conrelid)
static void RemoveInheritance(Relation child_rel, Relation parent_rel, bool expect_detached)
void PreCommit_on_commit_actions(void)
static ObjectAddress dropconstraint_internal(Relation rel, HeapTuple constraintTup, DropBehavior behavior, bool recurse, bool recursing, bool missing_ok, LOCKMODE lockmode)
static void RemoveInheritedConstraint(Relation conrel, Relation trigrel, Oid conoid, Oid conrelid)
struct SplitPartitionContext SplitPartitionContext
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)
static Oid transformFkeyCheckAttrs(Relation pkrel, int numattrs, int16 *attnums, bool with_period, Oid *opclasses, bool *pk_has_without_overlaps)
void RemoveRelations(DropStmt *drop)
static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacename, LOCKMODE lockmode)
static void ATTypedTableRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void RememberReplicaIdentityForRebuilding(Oid indoid, AlteredTableInfo *tab)
static List * GetParentedForeignKeyRefs(Relation partition)
void AlterRelationNamespaceInternal(Relation classRel, Oid relOid, Oid oldNspOid, Oid newNspOid, bool hasDependEntry, ObjectAddresses *objsMoved)
static ObjectAddress ATExecAddConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *newConstraint, bool recurse, bool is_readd, LOCKMODE lockmode)
ObjectAddress renameatt(RenameStmt *stmt)
void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lockmode)
static void RangeVarCallbackForAlterRelation(const RangeVar *rv, Oid relid, Oid oldrelid, void *arg)
static void CheckAlterTableIsSafe(Relation rel)
static void DropErrorMsgWrongType(const char *relname, char wrongkind, char rightkind)
LOCKMODE AlterTableGetLockLevel(List *cmds)
struct ForeignTruncateInfo ForeignTruncateInfo
static ObjectAddress ATExecDetachPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, RangeVar *name, bool concurrent)
static void AlterSeqNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved, LOCKMODE lockmode)
static void RangeVarCallbackForRenameAttribute(const RangeVar *rv, Oid relid, Oid oldrelid, void *arg)
TupleDesc BuildDescForRelation(const List *columns)
static void attachPartitionTable(List **wqueue, Relation rel, Relation attachrel, PartitionBoundSpec *bound)
static void ATExecForceNoForceRowSecurity(Relation rel, bool force_rls)
static void createTableConstraints(List **wqueue, AlteredTableInfo *tab, Relation parent_rel, Relation newRel)
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 Relation createPartitionTable(List **wqueue, RangeVar *newPartName, Relation parent_rel, Oid ownerId)
static void SplitPartitionMoveRows(List **wqueue, Relation rel, Relation splitRel, List *partlist, List *newPartRels)
static bool ATExecAlterConstrInheritability(List **wqueue, ATAlterConstraint *cmdcon, Relation conrel, Relation rel, HeapTuple contuple, LOCKMODE lockmode)
static void createForeignKeyActionTriggers(Oid myRelOid, Oid refRelOid, Constraint *fkconstraint, Oid constraintOid, Oid indexOid, Oid parentDelTrigger, Oid parentUpdTrigger, Oid *deleteTrigOid, Oid *updateTrigOid)
static void evaluateGeneratedExpressionsAndCheckConstraints(AlteredTableInfo *tab, Relation newPartRel, TupleTableSlot *insertslot, ExprContext *econtext)
static void ATExecEnableDisableTrigger(Relation rel, const char *trigname, char fires_when, bool skip_system, bool recurse, LOCKMODE lockmode)
static void AttachPartitionForeignKey(List **wqueue, Relation partition, Oid partConstrOid, Oid parentConstrOid, Oid parentInsTrigger, Oid parentUpdTrigger, Relation trigrel)
static List * MergeCheckConstraint(List *constraints, const char *name, Node *expr, bool is_enforced)
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 void AlterConstrUpdateConstraintEntry(ATAlterConstraint *cmdcon, Relation conrel, HeapTuple contuple)
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 ObjectAddress addFkConstraint(addFkConstraintSides fkside, char *constraintname, 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 is_internal, bool with_period)
static void RememberClusterOnForRebuilding(Oid indoid, AlteredTableInfo *tab)
static ObjectAddress ATExecSetOptions(Relation rel, const char *colName, Node *options, bool isReset, LOCKMODE lockmode)
static List * getAttributesList(Relation parent_rel)
static bool ATExecAlterConstrEnforceability(List **wqueue, ATAlterConstraint *cmdcon, Relation conrel, Relation tgrel, Oid fkrelid, Oid pkrelid, HeapTuple contuple, LOCKMODE lockmode, Oid ReferencedParentDelTrigger, Oid ReferencedParentUpdTrigger, Oid ReferencingParentInsTrigger, Oid ReferencingParentUpdTrigger)
static void QueueNNConstraintValidation(List **wqueue, Relation conrel, Relation rel, HeapTuple contuple, bool recurse, bool recursing, LOCKMODE lockmode)
static void detachPartitionTable(Relation parent_rel, Relation child_rel, Oid defaultPartOid)
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)
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 bool ATExecAlterConstraintInternal(List **wqueue, ATAlterConstraint *cmdcon, Relation conrel, Relation tgrel, Relation rel, HeapTuple contuple, bool recurse, LOCKMODE lockmode)
static void verifyPartitionIndexNotNull(IndexInfo *iinfo, Relation partition)
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 void ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel, PartitionCmd *cmd, AlterTableUtilityContext *context)
static AlterTableCmd * ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses *objsMoved)
static 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 const char * alter_table_type_to_string(AlterTableType cmdtype)
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 void relation_mark_replica_identity(Relation rel, char ri_type, Oid indexOid, bool is_internal)
#define ATT_FOREIGN_TABLE
static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing, bool is_view, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNumber *partattrs, List **partexprs, Oid *partopclass, Oid *partcollation, PartitionStrategy strategy)
static void CloneRowTriggersToPartition(Relation parent, Relation partition)
static void AttachPartitionEnsureIndexes(List **wqueue, Relation rel, Relation attachrel)
static void StoreCatalogInheritance(Oid relationId, List *supers, bool child_is_partition)
static void ATExecGenericOptions(Relation rel, List *options)
static void TryReuseForeignKey(Oid oldId, Constraint *con)
struct AlteredTableInfo AlteredTableInfo
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
static void AlterConstrDeferrabilityRecurse(List **wqueue, ATAlterConstraint *cmdcon, Relation conrel, Relation tgrel, Relation rel, HeapTuple contuple, bool recurse, List **otherrelids, LOCKMODE lockmode)
struct NewConstraint NewConstraint
static ObjectAddress ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newValue, LOCKMODE lockmode)
static void ATSimpleRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void DetachPartitionFinalize(Relation rel, Relation partRel, bool concurrent, Oid defaultPartOid)
static 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 void addFkRecurseReferenced(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, bool with_period)
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)
static void validateForeignKeyConstraint(char *conname, Relation rel, Relation pkrel, Oid pkindOid, Oid constraintOid, bool hasperiod)
static char * decompile_conbin(HeapTuple contup, TupleDesc tupdesc)
static void QueueCheckConstraintValidation(List **wqueue, Relation conrel, Relation rel, char *constrName, HeapTuple contuple, bool recurse, bool recursing, LOCKMODE lockmode)
void SetRelationTableSpace(Relation rel, Oid newTableSpaceId, RelFileNumber newRelFilenumber)
void remove_on_commit_action(Oid relid)
static void ATExecDropCluster(Relation rel, LOCKMODE lockmode)
#define ATT_PARTITIONED_INDEX
static void CreateInheritance(Relation child_rel, Relation parent_rel, bool ispartition)
static const struct dropmsgstrings dropmsgstringarray[]
static void ATPrepChangePersistence(AlteredTableInfo *tab, Relation rel, bool toLogged)
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 AlterConstrTriggerDeferrability(Oid conoid, Relation tgrel, Relation rel, bool deferrable, bool initdeferred, List **otherrelids)
static void ATPrepAddPrimaryKey(List **wqueue, Relation rel, AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode, AlterTableUtilityContext *context)
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 SplitPartitionContext * createSplitPartitionContext(Relation partRel)
static void AlterIndexNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved)
#define ATT_PARTITIONED_TABLE
static void deleteSplitPartitionContext(SplitPartitionContext *pc, List **wqueue, int ti_options)
static void ATExecCmd(List **wqueue, AlteredTableInfo *tab, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
static bool ATExecAlterConstrDeferrability(List **wqueue, ATAlterConstraint *cmdcon, Relation conrel, Relation tgrel, Relation rel, HeapTuple contuple, bool recurse, List **otherrelids, LOCKMODE lockmode)
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 int transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, List **attnamelist, int16 *attnums, Oid *atttypids, Oid *attcollids, Oid *opclasses, bool *pk_has_without_overlaps)
static ObjectAddress ATExecAddIdentity(Relation rel, const char *colName, Node *def, LOCKMODE lockmode, bool recurse, bool recursing)
static void ATExecSetAccessMethodNoStorage(Relation rel, Oid newAccessMethodId)
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 buildExpressionExecutionStates(AlteredTableInfo *tab, Relation newPartRel, EState *estate)
static void index_copy_data(Relation rel, RelFileLocator newrlocator)
static ObjectAddress ATExecSetNotNull(List **wqueue, Relation rel, char *conName, char *colName, bool recurse, bool recursing, LOCKMODE lockmode)
void RenameRelationInternal(Oid myrelid, const char *newrelname, bool is_internal, bool is_index)
static void set_attnotnull(List **wqueue, Relation rel, AttrNumber attnum, bool is_valid, bool queue_validation)
static bool tryAttachPartitionForeignKey(List **wqueue, ForeignKeyCacheInfo *fk, Relation partition, Oid parentConstrOid, int numfks, AttrNumber *mapped_conkey, AttrNumber *confkey, Oid *conpfeqop, Oid parentInsTrigger, Oid parentUpdTrigger, Relation trigrel)
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 int transformColumnNameList(Oid relId, List *colList, int16 *attnums, Oid *atttypids, Oid *attcollids)
static void change_owner_fix_column_acls(Oid relationOid, Oid oldOwnerId, Oid newOwnerId)
#define ATT_COMPOSITE_TYPE
static ObjectAddress ATExecAttachPartitionIdx(List **wqueue, Relation parentIdx, RangeVar *name)
bool PartConstraintImpliedByRelConstraint(Relation scanrel, List *partConstraint)
void RangeVarCallbackMaintainsTable(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
static void ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, PartitionCmd *cmd, AlterTableUtilityContext *context)
static bool constraints_equivalent(HeapTuple a, HeapTuple b, TupleDesc tupleDesc)
static ObjectAddress ATExecAddStatistics(AlteredTableInfo *tab, Relation rel, CreateStatsStmt *stmt, bool is_rebuild, LOCKMODE lockmode)
ObjectAddress RenameConstraint(RenameStmt *stmt)
static void ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode, AlterTableUtilityContext *context)
void register_on_commit_action(Oid relid, OnCommitAction action)
static void RangeVarCallbackForTruncate(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
static ObjectAddress ATExecClusterOn(Relation rel, const char *indexName, LOCKMODE lockmode)
static char GetAttributeStorage(Oid atttypid, const char *storagemode)
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
#define child_dependency_type(child_is_partition)
static void refuseDupeIndexAttach(Relation parentIdx, Relation partIdx, Relation partitionTbl)
void ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged, DropBehavior behavior, bool restart_seqs, bool run_as_table_owner)
static void ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
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)
const char * FindTriggerIncompatibleWithInheritance(TriggerDesc *trigdesc)
void ExecASTruncateTriggers(EState *estate, ResultRelInfo *relinfo)
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
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
void free_conversion_map(TupleConversionMap *map)
TupleTableSlot * execute_attr_map_slot(AttrMap *attrMap, TupleTableSlot *in_slot, TupleTableSlot *out_slot)
TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc)
Node * TupleDescGetDefault(TupleDesc tupdesc, AttrNumber attnum)
TupleDesc CreateTemplateTupleDesc(int natts)
void populate_compact_attribute(TupleDesc tupdesc, int 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 ATTNULLABLE_VALID
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
static void slot_getallattrs(TupleTableSlot *slot)
static bool slot_attisnull(TupleTableSlot *slot, int attnum)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
bool DomainHasConstraints(Oid type_id)
void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId)
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
void checkDomainOwner(HeapTuple tup)
Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid, bool isImplicitArray, bool ignoreDependent, bool errorOnTableType, ObjectAddresses *objsMoved)
List * roleSpecsToIds(List *memberNames)
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)
static char * VARDATA_ANY(const void *PTR)
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
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void XLogRegisterData(const void *data, uint32 len)
void XLogSetRecordFlags(uint8 flags)
void XLogBeginInsert(void)