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);
1312 false,
false,
false,
false,
false);
1340 if (
stmt->constraints)
1342 true,
true,
false, queryString);
1420 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1421 errmsg(
"too many array dimensions"));
1425 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1426 errmsg(
"column \"%s\" cannot be declared SETOF",
1430 atttypid, atttypmod, attdim);
1439 att->attinhcount = entry->
inhcount;
1440 att->attidentity = entry->
identity;
1444 att->attstorage = entry->
storage;
1469 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1475 (
errmsg(
"schema \"%s\" does not exist, skipping",
1483 if (rentry->
kind == rightkind)
1513 if (rentry->
kind == rightkind)
1518 if (wentry->
kind == wrongkind)
1523 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1554 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1555 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1558 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1559 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1572 relkind = RELKIND_RELATION;
1576 relkind = RELKIND_INDEX;
1580 relkind = RELKIND_SEQUENCE;
1584 relkind = RELKIND_VIEW;
1588 relkind = RELKIND_MATVIEW;
1592 relkind = RELKIND_FOREIGN_TABLE;
1596 elog(
ERROR,
"unrecognized drop object type: %d",
1625 state.expected_relkind = relkind;
1648 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1660 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1662 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1663 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1673 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1675 state.heap_lockmode,
1679 obj.
classId = RelationRelationId;
1707 bool invalid_system_index =
false;
1742 is_partition = classform->relispartition;
1745 state->actual_relkind = classform->relkind;
1746 state->actual_relpersistence = classform->relpersistence;
1756 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1758 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1765 state->expected_relkind);
1780 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1794 indisvalid = indexform->indisvalid;
1799 invalid_system_index =
true;
1805 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1806 errmsg(
"permission denied: \"%s\" is a system catalog",
1820 relOid != oldRelOid)
1833 if (is_partition && relOid != oldRelOid)
1867 foreach(cell,
stmt->relations)
1871 bool recurse = rv->
inh;
1897 relids_logged =
lappend_oid(relids_logged, myrelid);
1906 foreach(child, children)
1945 relids_logged =
lappend_oid(relids_logged, childrelid);
1948 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1950 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1951 errmsg(
"cannot truncate only a partitioned table"),
1952 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1956 stmt->behavior,
stmt->restart_seqs,
false);
1983 List *relids_logged,
1985 bool run_as_table_owner)
1989 HTAB *ft_htab = NULL;
2015 if (newrelids ==
NIL)
2018 foreach(cell, newrelids)
2025 (
errmsg(
"truncate cascades to table \"%s\"",
2035 relids_logged =
lappend_oid(relids_logged, relid);
2045#ifdef USE_ASSERT_CHECKING
2066 foreach(seqcell, seqlist)
2100 resultRelInfo = resultRelInfos;
2121 resultRelInfo = resultRelInfos;
2126 if (run_as_table_owner)
2130 if (run_as_table_owner)
2145 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2155 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2166 memset(&hctl, 0,
sizeof(
HASHCTL));
2171 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2231 toast_relid = rel->
rd_rel->reltoastrelid;
2238 toastrel->
rd_rel->relpersistence);
2284 foreach(cell, seq_relids)
2298 if (relids_logged !=
NIL)
2307 foreach(cell, relids_logged)
2330 resultRelInfo = resultRelInfos;
2335 if (run_as_table_owner)
2339 if (run_as_table_owner)
2378 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2385 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2386 errmsg(
"cannot truncate foreign table \"%s\"",
2389 else if (reltuple->relkind != RELKIND_RELATION &&
2390 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2392 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2405 (relid != LargeObjectRelationId &&
2406 relid != LargeObjectMetadataRelationId)))
2408 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2409 errmsg(
"permission denied: \"%s\" is a system catalog",
2445 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2446 errmsg(
"cannot truncate temporary tables of other sessions")));
2464 case TYPSTORAGE_PLAIN:
2466 case TYPSTORAGE_EXTERNAL:
2468 case TYPSTORAGE_EXTENDED:
2470 case TYPSTORAGE_MAIN:
2546 bool is_partition,
List **supconstr,
List **supnotnulls)
2551 bool have_bogus_defaults =
false;
2553 static Node bogus_marker = {0};
2570 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2571 errmsg(
"tables can have at most %d columns",
2588 for (
int coldefpos = 0; coldefpos <
list_length(columns); coldefpos++)
2592 if (!is_partition && coldef->
typeName == NULL)
2601 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2602 errmsg(
"column \"%s\" does not exist",
2607 for (
int restpos = coldefpos + 1; restpos <
list_length(columns);)
2627 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2628 errmsg(
"column \"%s\" specified more than once",
2643 saved_columns = columns;
2659 List *inherited_defaults;
2660 List *cols_with_defaults;
2681 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !is_partition)
2683 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2684 errmsg(
"cannot inherit from partitioned table \"%s\"",
2686 if (relation->
rd_rel->relispartition && !is_partition)
2688 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2689 errmsg(
"cannot inherit from partition \"%s\"",
2692 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2693 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2694 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2696 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2697 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2705 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2706 relpersistence == RELPERSISTENCE_TEMP)
2708 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2709 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2713 if (relpersistence != RELPERSISTENCE_TEMP &&
2714 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2716 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2718 ?
"cannot inherit from temporary relation \"%s\""
2719 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2725 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2727 ?
"cannot inherit from temporary relation of another session"
2728 :
"cannot create as partition of temporary relation of another session")));
2739 constr = tupleDesc->
constr;
2749 inherited_defaults = cols_with_defaults =
NIL;
2765 char *attributeName =
NameStr(attribute->attname);
2773 if (attribute->attisdropped)
2780 attribute->atttypmod, attribute->attcollation);
2781 newdef->
storage = attribute->attstorage;
2782 newdef->
generated = attribute->attgenerated;
2793 newdef->
identity = attribute->attidentity;
2800 if (exist_attno > 0)
2807 newattmap->
attnums[parent_attno - 1] = exist_attno;
2822 inh_columns =
lappend(inh_columns, newdef);
2824 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2837 if (attribute->atthasdef)
2842 if (this_default == NULL)
2843 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2852 inherited_defaults =
lappend(inherited_defaults, this_default);
2853 cols_with_defaults =
lappend(cols_with_defaults, mergeddef);
2861 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2865 bool found_whole_row;
2879 if (found_whole_row)
2881 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2882 errmsg(
"cannot convert whole-row table reference"),
2883 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2899 have_bogus_defaults =
true;
2916 bool found_whole_row;
2919 if (check[
i].ccnoinherit)
2933 if (found_whole_row)
2935 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2936 errmsg(
"cannot convert whole-row table reference"),
2937 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2942 check[
i].ccenforced);
2954 nn->attnum = newattmap->
attnums[nn->attnum - 1];
2956 nnconstraints =
lappend(nnconstraints, nn);
2975 if (inh_columns !=
NIL)
2977 int newcol_attno = 0;
2979 foreach(lc, columns)
2982 char *attributeName = newdef->
colname;
2997 if (exist_attno > 0)
3009 inh_columns =
lappend(inh_columns, newdef);
3013 columns = inh_columns;
3021 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
3022 errmsg(
"tables can have at most %d columns",
3033 foreach(lc, saved_columns)
3058 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3059 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3063 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3064 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3071 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3072 errmsg(
"child column \"%s\" specifies generation expression",
3074 errhint(
"A child table column cannot be generated unless its parent column is.")));
3079 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3080 errmsg(
"column \"%s\" inherits from generated column of different kind",
3082 errdetail(
"Parent column is %s, child column is %s.",
3083 coldef->
generated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL",
3084 restdef->
generated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL")));
3108 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3109 errmsg(
"column \"%s\" does not exist",
3118 if (have_bogus_defaults)
3120 foreach(lc, columns)
3128 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3129 errmsg(
"column \"%s\" inherits conflicting generation expressions",
3131 errhint(
"To resolve the conflict, specify a generation expression explicitly.")));
3134 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3135 errmsg(
"column \"%s\" inherits conflicting default values",
3137 errhint(
"To resolve the conflict, specify a default explicitly.")));
3142 *supconstr = constraints;
3143 *supnotnulls = nnconstraints;
3170 foreach(lc, constraints)
3186 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3187 errmsg(
"too many inheritance parents"));
3204 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3215 newcon->
expr = expr;
3219 return lappend(constraints, newcon);
3246 char *attributeName = newdef->
colname;
3255 if (exist_attno == newcol_attno)
3257 (
errmsg(
"merging column \"%s\" with inherited definition",
3261 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
3262 errdetail(
"User-specified column moved to the position of the inherited column.")));
3271 if (inhtypeid != newtypeid || inhtypmod != newtypmod)
3273 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3274 errmsg(
"column \"%s\" has a type conflict",
3285 if (inhcollid != newcollid)
3287 (
errcode(ERRCODE_COLLATION_MISMATCH),
3288 errmsg(
"column \"%s\" has a collation conflict",
3307 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3308 errmsg(
"column \"%s\" has a storage parameter conflict",
3323 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3324 errmsg(
"column \"%s\" has a compression method conflict",
3352 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3353 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3357 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3358 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3365 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3366 errmsg(
"child column \"%s\" specifies generation expression",
3368 errhint(
"A child table column cannot be generated unless its parent column is.")));
3373 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3374 errmsg(
"column \"%s\" inherits from generated column of different kind",
3376 errdetail(
"Parent column is %s, child column is %s.",
3377 inhdef->
generated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL",
3378 newdef->
generated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL")));
3418 char *attributeName = newdef->
colname;
3428 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
3437 if (prevtypeid != newtypeid || prevtypmod != newtypmod)
3439 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3440 errmsg(
"inherited column \"%s\" has a type conflict",
3451 if (prevcollid != newcollid)
3453 (
errcode(ERRCODE_COLLATION_MISMATCH),
3454 errmsg(
"inherited column \"%s\" has a collation conflict",
3467 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3468 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
3483 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3484 errmsg(
"column \"%s\" has a compression method conflict",
3495 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3496 errmsg(
"inherited column \"%s\" has a generation conflict",
3506 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3507 errmsg(
"too many inheritance parents"));
3520 bool child_is_partition)
3546 foreach(entry, supers)
3551 child_is_partition);
3565 bool child_is_partition)
3576 parentobject.
classId = RelationRelationId;
3579 childobject.
classId = RelationRelationId;
3613 foreach(lc, columns)
3662 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3665 if (classtuple->relhassubclass != relhassubclass)
3667 classtuple->relhassubclass = relhassubclass;
3693 Oid oldTableSpaceId;
3699 oldTableSpaceId = rel->
rd_rel->reltablespace;
3700 if (newTableSpaceId == oldTableSpaceId ||
3710 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3711 errmsg(
"cannot move system relation \"%s\"",
3715 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3717 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3718 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3726 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3727 errmsg(
"cannot move temporary tables of other sessions")));
3749 Oid newTableSpaceId,
3765 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3773 rd_rel->relfilenode = newRelFilenumber;
3781 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3783 rd_rel->reltablespace);
3795 char relkind = classform->relkind;
3797 if (classform->reloftype && !recursing)
3799 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3800 errmsg(
"cannot rename column of typed table")));
3809 if (relkind != RELKIND_RELATION &&
3810 relkind != RELKIND_VIEW &&
3811 relkind != RELKIND_MATVIEW &&
3812 relkind != RELKIND_COMPOSITE_TYPE &&
3813 relkind != RELKIND_INDEX &&
3814 relkind != RELKIND_PARTITIONED_INDEX &&
3815 relkind != RELKIND_FOREIGN_TABLE &&
3816 relkind != RELKIND_PARTITIONED_TABLE)
3818 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3819 errmsg(
"cannot rename columns of relation \"%s\"",
3831 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3832 errmsg(
"permission denied: \"%s\" is a system catalog",
3833 NameStr(classform->relname))));
3843 const char *oldattname,
3844 const char *newattname,
3847 int expected_parents,
3891 forboth(lo, child_oids, li, child_numparents)
3896 if (childrelid == myrelid)
3899 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3910 if (expected_parents == 0 &&
3913 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3914 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3919 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3928 foreach(lo, child_oids)
3937 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3938 errmsg(
"column \"%s\" does not exist",
3942 attnum = attform->attnum;
3945 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3946 errmsg(
"cannot rename system column \"%s\"",
3958 if (attform->attinhcount > expected_parents)
3960 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3961 errmsg(
"cannot rename inherited column \"%s\"",
4022 (
errmsg(
"relation \"%s\" does not exist, skipping",
4023 stmt->relation->relname)));
4031 stmt->relation->inh,
4047 const char *oldconname,
4048 const char *newconname,
4051 int expected_parents)
4059 Assert(!myrelid || !mytypid);
4080 elog(
ERROR,
"cache lookup failed for constraint %u",
4085 (con->contype == CONSTRAINT_CHECK ||
4086 con->contype == CONSTRAINT_NOTNULL) &&
4099 forboth(lo, child_oids, li, child_numparents)
4104 if (childrelid == myrelid)
4112 if (expected_parents == 0 &&
4115 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4116 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
4120 if (con->coninhcount > expected_parents)
4122 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4123 errmsg(
"cannot rename inherited constraint \"%s\"",
4128 && (con->contype == CONSTRAINT_PRIMARY
4129 || con->contype == CONSTRAINT_UNIQUE
4130 || con->contype == CONSTRAINT_EXCLUSION))
4168 elog(
ERROR,
"cache lookup failed for type %u", typid);
4183 (
errmsg(
"relation \"%s\" does not exist, skipping",
4184 stmt->relation->relname)));
4194 stmt->relation->inh),
4235 (
errmsg(
"relation \"%s\" does not exist, skipping",
4236 stmt->relation->relname)));
4247 obj_is_index = (relkind == RELKIND_INDEX ||
4248 relkind == RELKIND_PARTITIONED_INDEX);
4249 if (obj_is_index || is_index_stmt == obj_is_index)
4253 is_index_stmt = obj_is_index;
4297 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4303 (
errcode(ERRCODE_DUPLICATE_TABLE),
4304 errmsg(
"relation \"%s\" already exists",
4314 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4315 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
4337 newrelname, namespaceId);
4342 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4343 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
4374 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4416 int expected_refcnt;
4421 (
errcode(ERRCODE_OBJECT_IN_USE),
4423 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4426 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4427 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4430 (
errcode(ERRCODE_OBJECT_IN_USE),
4432 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4457 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4458 errmsg(
"cannot alter temporary tables of other sessions")));
4570 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4851 elog(
ERROR,
"unrecognized alter table type: %d",
4859 if (cmd_lockmode > lockmode)
4860 lockmode = cmd_lockmode;
4885 ATPrepCmd(&wqueue, rel, cmd, recurse,
false, lockmode, context);
4909 bool recurse,
bool recursing,
LOCKMODE lockmode,
4922 if (rel->
rd_rel->relispartition &&
4926 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4927 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4929 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
5155 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5156 errmsg(
"cannot change persistence setting twice")));
5172 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5173 errmsg(
"cannot have multiple SET ACCESS METHOD subcommands")));
5292 elog(
ERROR,
"unrecognized alter table type: %d",
5326 foreach(ltab, *wqueue)
5342 foreach(lcmd, subcmds)
5345 lockmode, pass, context);
5364 foreach(ltab, *wqueue)
5373 if (((tab->
relkind == RELKIND_RELATION ||
5374 tab->
relkind == RELKIND_PARTITIONED_TABLE) &&
5376 tab->
relkind == RELKIND_MATVIEW)
5398 lockmode, cur_pass, context);
5426 cmd->
recurse,
false, lockmode);
5479 cmd->
recurse,
false, lockmode);
5484 true,
true, lockmode);
5546 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
5557 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
5558 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
5667 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
5679 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5691 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5699 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5704 elog(
ERROR,
"unrecognized alter table type: %d",
5764 foreach(lc, beforeStmts)
5773 foreach(lc, atstmt->
cmds)
5825 if (pass < cur_pass)
5828 elog(
ERROR,
"ALTER TABLE scheduling failure: too late for pass %d",
5831 else if (pass > cur_pass)
5848 elog(
ERROR,
"ALTER TABLE scheduling failure: bogus item for pass %d",
5869 foreach(ltab, *wqueue)
5874 if (!RELKIND_HAS_STORAGE(tab->
relkind))
5915 Oid NewAccessMethod;
5928 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5929 errmsg(
"cannot rewrite system relation \"%s\"",
5934 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5935 errmsg(
"cannot rewrite table \"%s\" used as a catalog table",
5946 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5947 errmsg(
"cannot rewrite temporary tables of other sessions")));
5956 NewTableSpace = OldHeap->
rd_rel->reltablespace;
5965 NewAccessMethod = OldHeap->
rd_rel->relam;
6008 persistence, lockmode);
6067 foreach(lc, seqlist)
6083 foreach(ltab, *wqueue)
6090 if (!RELKIND_HAS_STORAGE(tab->
relkind))
6129 foreach(ltab, *wqueue)
6157 bool needscan =
false;
6158 List *notnull_attrs;
6159 List *notnull_virtual_attrs;
6224 elog(
ERROR,
"unrecognized constraint type: %d",
6244 notnull_attrs = notnull_virtual_attrs =
NIL;
6257 for (
i = 0;
i < newTupDesc->
natts;
i++)
6266 if (wholeatt->attgenerated != ATTRIBUTE_GENERATED_VIRTUAL)
6267 notnull_attrs =
lappend_int(notnull_attrs, wholeatt->attnum);
6269 notnull_virtual_attrs =
lappend_int(notnull_virtual_attrs,
6273 if (notnull_attrs || notnull_virtual_attrs)
6277 if (newrel || needscan)
6295 if (notnull_virtual_attrs !=
NIL)
6370 for (
i = 0;
i < newTupDesc->
natts;
i++)
6406 foreach(lc, dropped_attrs)
6460 insertslot = newslot;
6469 insertslot = oldslot;
6482 (
errcode(ERRCODE_NOT_NULL_VIOLATION),
6483 errmsg(
"column \"%s\" of relation \"%s\" contains null values",
6490 if (notnull_virtual_attrs !=
NIL)
6496 notnull_virtual_attrs);
6502 errcode(ERRCODE_NOT_NULL_VIOLATION),
6503 errmsg(
"column \"%s\" of relation \"%s\" contains null values",
6519 (
errcode(ERRCODE_CHECK_VIOLATION),
6520 errmsg(
"check constraint \"%s\" of relation \"%s\" is violated by some row",
6530 elog(
ERROR,
"unrecognized constraint type: %d",
6535 if (partqualstate && !
ExecCheck(partqualstate, econtext))
6539 (
errcode(ERRCODE_CHECK_VIOLATION),
6540 errmsg(
"updated partition constraint for default partition \"%s\" would be violated by some row",
6545 (
errcode(ERRCODE_CHECK_VIOLATION),
6546 errmsg(
"partition constraint of relation \"%s\" is violated by some row",
6554 ti_options, bistate);
6593 foreach(ltab, *wqueue)
6596 if (tab->
relid == relid)
6615 *wqueue =
lappend(*wqueue, tab);
6627 return "ADD COLUMN";
6630 return "ALTER COLUMN ... SET DEFAULT";
6632 return "ALTER COLUMN ... DROP NOT NULL";
6634 return "ALTER COLUMN ... SET NOT NULL";
6636 return "ALTER COLUMN ... SET EXPRESSION";
6638 return "ALTER COLUMN ... DROP EXPRESSION";
6640 return "ALTER COLUMN ... SET STATISTICS";
6642 return "ALTER COLUMN ... SET";
6644 return "ALTER COLUMN ... RESET";
6646 return "ALTER COLUMN ... SET STORAGE";
6648 return "ALTER COLUMN ... SET COMPRESSION";
6650 return "DROP COLUMN";
6658 return "ADD CONSTRAINT";
6660 return "ALTER CONSTRAINT";
6662 return "VALIDATE CONSTRAINT";
6664 return "DROP CONSTRAINT";
6668 return "ALTER COLUMN ... SET DATA TYPE";
6670 return "ALTER COLUMN ... OPTIONS";
6674 return "CLUSTER ON";
6676 return "SET WITHOUT CLUSTER";
6678 return "SET ACCESS METHOD";
6680 return "SET LOGGED";
6682 return "SET UNLOGGED";
6684 return "SET WITHOUT OIDS";
6686 return "SET TABLESPACE";
6694 return "ENABLE TRIGGER";
6696 return "ENABLE ALWAYS TRIGGER";
6698 return "ENABLE REPLICA TRIGGER";
6700 return "DISABLE TRIGGER";
6702 return "ENABLE TRIGGER ALL";
6704 return "DISABLE TRIGGER ALL";
6706 return "ENABLE TRIGGER USER";
6708 return "DISABLE TRIGGER USER";
6710 return "ENABLE RULE";
6712 return "ENABLE ALWAYS RULE";
6714 return "ENABLE REPLICA RULE";
6716 return "DISABLE RULE";
6720 return "NO INHERIT";
6726 return "REPLICA IDENTITY";
6728 return "ENABLE ROW SECURITY";
6730 return "DISABLE ROW SECURITY";
6732 return "FORCE ROW SECURITY";
6734 return "NO FORCE ROW SECURITY";
6738 return "ATTACH PARTITION";
6740 return "DETACH PARTITION";
6742 return "DETACH PARTITION ... FINALIZE";
6744 return "MERGE PARTITIONS";
6746 return "SPLIT PARTITION";
6748 return "ALTER COLUMN ... ADD IDENTITY";
6750 return "ALTER COLUMN ... SET";
6752 return "ALTER COLUMN ... DROP IDENTITY";
6772 switch (rel->
rd_rel->relkind)
6774 case RELKIND_RELATION:
6777 case RELKIND_PARTITIONED_TABLE:
6783 case RELKIND_MATVIEW:
6789 case RELKIND_PARTITIONED_INDEX:
6792 case RELKIND_COMPOSITE_TYPE:
6795 case RELKIND_FOREIGN_TABLE:
6798 case RELKIND_SEQUENCE:
6807 if ((actual_target & allowed_targets) == 0)
6813 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6815 errmsg(
"ALTER action %s cannot be performed on relation \"%s\"",
6820 elog(
ERROR,
"invalid ALTER action attempted on relation \"%s\"",
6831 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6832 errmsg(
"permission denied: \"%s\" is a system catalog",
6853 if (recurse && rel->
rd_rel->relhassubclass)
6866 foreach(child, children)
6871 if (childrelid == relid)
6876 ATPrepCmd(wqueue, childrel, cmd,
false,
true, lockmode, context);
6892 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
6926 Assert(rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
6932 foreach(child, children)
6939 ATPrepCmd(wqueue, childrel, cmd,
true,
true, lockmode, context);
6966 const char *origTypeName)
6983 Anum_pg_depend_refclassid,
6987 Anum_pg_depend_refobjid,
7002 if (pg_depend->classid == TypeRelationId)
7011 origRelation, origTypeName);
7016 if (pg_depend->classid != RelationRelationId)
7035 if (pg_depend->objsubid > 0 && pg_depend->objsubid <= tupleDesc->
natts)
7040 for (
int attno = 1; attno <= tupleDesc->
natts; attno++)
7043 if (att->atttypid == typeOid && !att->attisdropped)
7064 if (RELKIND_HAS_STORAGE(rel->
rd_rel->relkind) ||
7065 RELKIND_HAS_PARTITIONS(rel->
rd_rel->relkind))
7069 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7070 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
7074 else if (origRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
7076 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7077 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
7081 else if (origRelation->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
7083 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7084 errmsg(
"cannot alter foreign table \"%s\" because column \"%s.%s\" uses its row type",
7090 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7091 errmsg(
"cannot alter table \"%s\" because column \"%s.%s\" uses its row type",
7103 origRelation, origTypeName);
7134 Anum_pg_class_reloftype,
7146 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
7147 errmsg(
"cannot alter type \"%s\" because it is the type of a typed table",
7149 errhint(
"Use ALTER ... CASCADE to alter the typed tables too.")));
7175 bool typeOk =
false;
7177 if (typ->typtype == TYPTYPE_COMPOSITE)
7183 typeOk = (typeRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
7194 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7195 errmsg(
"type %s is the row type of another table",
7197 errdetail(
"A typed table must use a stand-alone composite type created with CREATE TYPE.")));
7201 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7202 errmsg(
"type %s is not a composite type",
7226 if (rel->
rd_rel->reloftype && !recursing)
7228 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7229 errmsg(
"cannot add column to typed table")));
7231 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
7234 if (recurse && !is_view)
7253 bool if_not_exists = (*cmd)->missing_ok;
7276 if (rel->
rd_rel->relispartition && !recursing)
7278 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7279 errmsg(
"cannot add column to a partition")));
7304 if (ctypeId != childatt->atttypid ||
7305 ctypmod != childatt->atttypmod)
7307 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7308 errmsg(
"child table \"%s\" has different type for column \"%s\"",
7311 if (ccollid != childatt->attcollation)
7313 (
errcode(ERRCODE_COLLATION_MISMATCH),
7314 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
7322 &childatt->attinhcount))
7324 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
7325 errmsg(
"too many inheritance parents"));
7332 (
errmsg(
"merging definition of column \"%s\" for child \"%s\"",
7362 if (context != NULL && !recursing)
7381 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE &&
7384 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7385 errmsg(
"cannot recursively add identity column to table that has child tables")));
7391 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
7393 relkind = relform->relkind;
7396 newattnum = relform->relnatts + 1;
7399 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
7400 errmsg(
"tables can have at most %d columns",
7411 attribute->attnum = newattnum;
7425 relform->relnatts = newattnum;
7447 rawEnt->
attnum = attribute->attnum;
7456 false,
true,
false, NULL);
7494 if (RELKIND_HAS_STORAGE(relkind))
7496 bool has_domain_constraints;
7497 bool has_missing =
false;
7508 nve->
typeId = attribute->atttypid;
7510 defval = (
Expr *) nve;
7517 if (!defval && has_domain_constraints)
7523 baseTypeMod = attribute->atttypmod;
7530 attribute->atttypid,
7531 attribute->atttypmod,
7536 elog(
ERROR,
"failed to coerce base type to domain");
7548 newval->attnum = attribute->attnum;
7563 if (rel->
rd_rel->relkind == RELKIND_RELATION &&
7565 !has_domain_constraints &&
7596 if (colDef->
generated != ATTRIBUTE_GENERATED_VIRTUAL)
7629 if (children && !recurse)
7631 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7632 errmsg(
"column must be added to child tables too")));
7645 foreach(child, children)
7660 &childcmd, recurse,
true,
7661 lockmode, cur_pass, context);
7701 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7702 errmsg(
"column name \"%s\" conflicts with a system column name",
7709 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7710 errmsg(
"column \"%s\" of relation \"%s\" already exists, skipping",
7716 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7717 errmsg(
"column \"%s\" of relation \"%s\" already exists",
7733 myself.
classId = RelationRelationId;
7736 referenced.
classId = TypeRelationId;
7754 myself.
classId = RelationRelationId;
7757 referenced.
classId = CollationRelationId;
7789 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7790 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7798 if (!attTup->attnotnull)
7807 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7808 errmsg(
"cannot alter system column \"%s\"",
7811 if (attTup->attidentity)
7813 (
errcode(ERRCODE_SYNTAX_ERROR),
7814 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
7820 if (rel->
rd_rel->relispartition)
7827 parent_attnum =
get_attnum(parentId, colName);
7830 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7831 errmsg(
"column \"%s\" is marked NOT NULL in parent table",
7842 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation \"%s\"",
7870 bool is_valid,
bool queue_validation)
7875 Assert(!queue_validation || wqueue);
7884 if (attr->attisdropped)
7887 if (!attr->attnotnull)
7896 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
7904 attr->attnotnull =
true;
7911 if (queue_validation && wqueue &&
7943 bool recurse,
bool recursing,
LOCKMODE lockmode)
7951 bool is_no_inherit =
false;
7967 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7968 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7974 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7975 errmsg(
"cannot alter system column \"%s\"",
7983 bool changed =
false;
7988 if (conForm->connoinherit && recurse)
7990 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7991 errmsg(
"cannot change NO INHERIT status of NOT NULL constraint \"%s\" on relation \"%s\"",
8003 &conForm->coninhcount))
8005 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
8006 errmsg(
"too many inheritance parents"));
8009 else if (!conForm->conislocal)
8011 conForm->conislocal =
true;
8014 else if (!conForm->convalidated)
8021 recurse, recursing, lockmode);
8050 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
8052 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8053 errmsg(
"constraint must be added to child tables too"),
8054 errhint(
"Do not specify the ONLY keyword."));
8056 is_no_inherit =
true;
8067 colName,
"not_null",
8074 constraint->
conname = conName;
8078 false, !recursing,
false, NULL);
8105 recurse,
true, lockmode);
8135 nnulltest->argisrow =
false;
8141 (
errmsg_internal(
"existing constraints on column \"%s.%s\" are sufficient to prove that it does not contain nulls",
8168 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8169 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8175 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8176 errmsg(
"cannot alter system column \"%s\"",
8181 (
errcode(ERRCODE_SYNTAX_ERROR),
8182 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
8185 newDefault ? 0 :
errhint(
"Use %s instead.",
8186 "ALTER TABLE ... ALTER COLUMN ... DROP IDENTITY")));
8190 (
errcode(ERRCODE_SYNTAX_ERROR),
8191 errmsg(
"column \"%s\" of relation \"%s\" is a generated column",
8195 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... SET EXPRESSION") :
8197 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... DROP EXPRESSION") : 0)));
8209 newDefault != NULL);
8226 false,
true,
false, NULL);
8270 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing)
8280 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8281 if (ispartitioned && !recurse)
8283 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8284 errmsg(
"cannot add identity to a column of only the partitioned table"),
8285 errhint(
"Do not specify the ONLY keyword.")));
8287 if (rel->
rd_rel->relispartition && !recursing)
8289 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8290 errmsg(
"cannot add identity to a column of a partition"));
8297 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8298 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8306 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8307 errmsg(
"cannot alter system column \"%s\"",
8315 if (!attTup->attnotnull)
8317 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8318 errmsg(
"column \"%s\" of relation \"%s\" must be declared NOT NULL before identity can be added",
8325 if (attTup->attnotnull)
8333 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation \"%s\"",
8337 if (!conForm->convalidated)
8339 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8340 errmsg(
"incompatible NOT VALID constraint \"%s\" on relation \"%s\"",
8342 errhint(
"You might need to validate it using %s.",
8343 "ALTER TABLE ... VALIDATE CONSTRAINT"));
8346 if (attTup->attidentity)
8348 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8349 errmsg(
"column \"%s\" of relation \"%s\" is already an identity column",
8352 if (attTup->atthasdef)
8354 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8355 errmsg(
"column \"%s\" of relation \"%s\" already has a default value",
8358 attTup->attidentity = cdef->
identity;
8374 if (recurse && ispartitioned)
8381 foreach(lc, children)
8401 LOCKMODE lockmode,
bool recurse,
bool recursing)
8412 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8413 if (ispartitioned && !recurse)
8415 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8416 errmsg(
"cannot change identity column of only the partitioned table"),
8417 errhint(
"Do not specify the ONLY keyword.")));
8419 if (rel->
rd_rel->relispartition && !recursing)
8421 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8422 errmsg(
"cannot change identity column of a partition"));
8428 if (strcmp(defel->
defname,
"generated") == 0)
8432 (
errcode(ERRCODE_SYNTAX_ERROR),
8433 errmsg(
"conflicting or redundant options")));
8434 generatedEl = defel;
8437 elog(
ERROR,
"option \"%s\" not recognized",
8451 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8452 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8460 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8461 errmsg(
"cannot alter system column \"%s\"",
8464 if (!attTup->attidentity)
8466 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8467 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8491 if (generatedEl && recurse && ispartitioned)
8498 foreach(lc, children)
8518 bool recurse,
bool recursing)
8529 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8530 if (ispartitioned && !recurse)
8532 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8533 errmsg(
"cannot drop identity from a column of only the partitioned table"),
8534 errhint(
"Do not specify the ONLY keyword.")));
8536 if (rel->
rd_rel->relispartition && !recursing)
8538 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8539 errmsg(
"cannot drop identity from a column of a partition"));
8545 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8546 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8554 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8555 errmsg(
"cannot alter system column \"%s\"",
8558 if (!attTup->attidentity)
8562 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8563 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8568 (
errmsg(
"column \"%s\" of relation \"%s\" is not an identity column, skipping",
8576 attTup->attidentity =
'\0';
8592 if (recurse && ispartitioned)
8599 foreach(lc, children)
8616 seqaddress.
classId = RelationRelationId;
8648 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8649 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8657 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8658 errmsg(
"cannot alter system column \"%s\"",
8661 attgenerated = attTup->attgenerated;
8664 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8665 errmsg(
"column \"%s\" of relation \"%s\" is not a generated column",
8672 if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL &&
8675 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8676 errmsg(
"ALTER TABLE / SET EXPRESSION is not supported for virtual generated columns in tables with check constraints"),
8677 errdetail(
"Column \"%s\" of relation \"%s\" is a virtual generated column.",
8680 if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL && attTup->attnotnull)
8690 if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL &&
8693 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8694 errmsg(
"ALTER TABLE / SET EXPRESSION is not supported for virtual generated columns in tables that are part of a publication"),
8695 errdetail(
"Column \"%s\" of relation \"%s\" is a virtual generated column.",
8698 rewrite = (attgenerated == ATTRIBUTE_GENERATED_STORED);
8728 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8751 false,
true,
false, NULL);
8764 newval->is_generated =
true;
8800 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8801 errmsg(
"ALTER TABLE / DROP EXPRESSION must be applied to child tables too")));
8814 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8815 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8820 if (attTup->attinhcount > 0)
8822 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8823 errmsg(
"cannot drop generation expression from inherited column")));
8844 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8845 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8853 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8854 errmsg(
"cannot alter system column \"%s\"",
8863 if (attTup->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
8865 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8866 errmsg(
"ALTER TABLE / DROP EXPRESSION is not supported for virtual generated columns"),
8867 errdetail(
"Column \"%s\" of relation \"%s\" is a virtual generated column.",
8870 if (!attTup->attgenerated)
8874 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8875 errmsg(
"column \"%s\" of relation \"%s\" is not a generated column",
8880 (
errmsg(
"column \"%s\" of relation \"%s\" is not a generated column, skipping",
8892 attTup->attgenerated =
'\0';
8909 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8938 bool newtarget_default;
8945 Datum repl_val[Natts_pg_attribute];
8946 bool repl_null[Natts_pg_attribute];
8947 bool repl_repl[Natts_pg_attribute];
8953 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
8954 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
8957 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8958 errmsg(
"cannot refer to non-index column by number")));
8961 if (newValue &&
intVal(newValue) != -1)
8963 newtarget =
intVal(newValue);
8964 newtarget_default =
false;
8967 newtarget_default =
true;
8969 if (!newtarget_default)
8977 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8978 errmsg(
"statistics target %d is too low",
8985 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8986 errmsg(
"lowering statistics target to %d",
8999 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9000 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9009 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9010 errmsg(
"column number %d of relation \"%s\" does not exist",
9016 attnum = attrtuple->attnum;
9019 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9020 errmsg(
"cannot alter system column \"%s\"",
9027 if (attrtuple->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
9029 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9030 errmsg(
"cannot alter statistics on virtual generated column \"%s\"",
9033 if (rel->
rd_rel->relkind == RELKIND_INDEX ||
9034 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
9038 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9039 errmsg(
"cannot alter statistics on included column \"%s\" of index \"%s\"",
9043 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9044 errmsg(
"cannot alter statistics on non-expression column \"%s\" of index \"%s\"",
9046 errhint(
"Alter statistics on table column instead.")));
9050 memset(repl_null,
false,
sizeof(repl_null));
9051 memset(repl_repl,
false,
sizeof(repl_repl));
9052 if (!newtarget_default)
9053 repl_val[Anum_pg_attribute_attstattarget - 1] =
Int16GetDatum(newtarget);
9055 repl_null[Anum_pg_attribute_attstattarget - 1] =
true;
9056 repl_repl[Anum_pg_attribute_attstattarget - 1] =
true;
9058 repl_val, repl_null, repl_repl);
9092 Datum repl_val[Natts_pg_attribute];
9093 bool repl_null[Natts_pg_attribute];
9094 bool repl_repl[Natts_pg_attribute];
9102 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9103 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9107 attnum = attrtuple->attnum;
9110 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9111 errmsg(
"cannot alter system column \"%s\"",
9124 memset(repl_null,
false,
sizeof(repl_null));
9125 memset(repl_repl,
false,
sizeof(repl_repl));
9126 if (newOptions != (
Datum) 0)
9127 repl_val[Anum_pg_attribute_attoptions - 1] = newOptions;
9129 repl_null[Anum_pg_attribute_attoptions - 1] =
true;
9130 repl_repl[Anum_pg_attribute_attoptions - 1] =
true;
9132 repl_val, repl_null, repl_repl);
9161 bool setstorage,
char newstorage,
9162 bool setcompression,
char newcompression,
9176 for (
int i = 0;
i < indrel->
rd_index->indnatts;
i++)
9198 attrtuple->attstorage = newstorage;
9201 attrtuple->attcompression = newcompression;
9236 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9237 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9241 attnum = attrtuple->attnum;
9244 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9245 errmsg(
"cannot alter system column \"%s\"",
9261 true, attrtuple->attstorage,
9289 if (rel->
rd_rel->reloftype && !recursing)
9291 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9292 errmsg(
"cannot drop column from typed table")));
9294 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
9315 bool recurse,
bool recursing,
9316 bool missing_ok,
LOCKMODE lockmode,
9332 Assert(!recursing || addrs != NULL);
9349 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9350 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9356 (
errmsg(
"column \"%s\" of relation \"%s\" does not exist, skipping",
9363 attnum = targetatt->attnum;
9368 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9369 errmsg(
"cannot drop system column \"%s\"",
9376 if (targetatt->attinhcount > 0 && !recursing)
9378 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9379 errmsg(
"cannot drop inherited column \"%s\"",
9391 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9392 errmsg(
"cannot drop column \"%s\" because it is part of the partition key of relation \"%s\"",
9414 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !recurse)
9416 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9417 errmsg(
"cannot drop column from only the partitioned table when partitions exist"),
9418 errhint(
"Do not specify the ONLY keyword.")));
9421 foreach(child, children)
9433 elog(
ERROR,
"cache lookup failed for attribute \"%s\" of relation %u",
9434 colName, childrelid);
9437 if (childatt->attinhcount <= 0)
9438 elog(
ERROR,
"relation %u has non-inherited attribute \"%s\"",
9439 childrelid, colName);
9448 if (childatt->attinhcount == 1 && !childatt->attislocal)
9452 behavior,
true,
true,
9453 false, lockmode, addrs);
9458 childatt->attinhcount--;
9473 childatt->attinhcount--;
9474 childatt->attislocal =
true;
9490 object.classId = RelationRelationId;
9492 object.objectSubId =
attnum;
9534 bool got_children =
false;
9572 got_children =
true;
9582 errmsg(
"column \"%s\" of table \"%s\" is not marked NOT NULL",
9596 newcmd->
def = (
Node *) nnconstr;
9598 ATPrepCmd(wqueue, rel, newcmd,
true,
false, lockmode, context);
9611 if (conForm->contype != CONSTRAINT_NOTNULL)
9612 elog(
ERROR,
"constraint %u is not a not-null constraint", conForm->oid);
9615 if (conForm->connoinherit)
9617 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
9618 errmsg(
"cannot create primary key on column \"%s\"", colname),
9620 errdetail(
"The constraint \"%s\" on column \"%s\" of table \"%s\", marked %s, is incompatible with a primary key.",
9621 NameStr(conForm->conname), colname,
9623 errhint(
"You might need to make the existing constraint inheritable using %s.",
9624 "ALTER TABLE ... ALTER CONSTRAINT ... INHERIT"));
9627 if (!conForm->convalidated)
9629 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
9630 errmsg(
"cannot create primary key on column \"%s\"", colname),
9632 errdetail(
"The constraint \"%s\" on column \"%s\" of table \"%s\", marked %s, is incompatible with a primary key.",
9633 NameStr(conForm->conname), colname,
9635 errhint(
"You might need to validate it using %s.",
9636 "ALTER TABLE ... VALIDATE CONSTRAINT"));
9664 check_rights = !is_rebuild;
9737 Oid index_oid =
stmt->indexOid;
9741 char *constraintName;
9742 char constraintType;
9754 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
9756 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9757 errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables")));
9767 elog(
ERROR,
"index \"%s\" is not unique", indexName);
9776 constraintName =
stmt->idxname;
9777 if (constraintName == NULL)
9778 constraintName = indexName;
9779 else if (strcmp(constraintName, indexName) != 0)
9782 (
errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index \"%s\" to \"%s\"",
9783 indexName, constraintName)));
9793 constraintType = CONSTRAINT_PRIMARY;
9795 constraintType = CONSTRAINT_UNIQUE;
9827 Constraint *newConstraint,
bool recurse,
bool is_readd,
9839 switch (newConstraint->
contype)
9845 newConstraint, recurse,
false, is_readd,
9861 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
9880 elog(
ERROR,
"unrecognized constraint type: %d",
9881 (
int) newConstraint->
contype);
9907 foreach(lc, colnames)
9912 buf[buflen++] =
'_';
9919 buflen += strlen(
buf + buflen);
9943 Constraint *constr,
bool recurse,
bool recursing,
9972 recursing || is_readd,
9982 foreach(lcon, newcons)
10028 if (newcons ==
NIL)
10050 if (!recurse && children !=
NIL)
10052 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
10053 errmsg(
"constraint must be added to child tables too")));
10058 foreach(child, children)
10073 constr, recurse,
true, is_readd, lockmode);
10099 bool recurse,
bool recursing,
LOCKMODE lockmode)
10114 bool pk_has_without_overlaps;
10137 if (!recurse && rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10139 errcode(ERRCODE_WRONG_OBJECT_TYPE),
10140 errmsg(
"cannot use ONLY for foreign key on partitioned table \"%s\" referencing relation \"%s\"",
10144 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
10145 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
10147 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10148 errmsg(
"referenced relation \"%s\" is not a table",
10153 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
10154 errmsg(
"permission denied: \"%s\" is a system catalog",
10165 switch (rel->
rd_rel->relpersistence)
10167 case RELPERSISTENCE_PERMANENT:
10170 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
10171 errmsg(
"constraints on permanent tables may reference only permanent tables")));
10173 case RELPERSISTENCE_UNLOGGED:
10175 && pkrel->
rd_rel->relpersistence != RELPERSISTENCE_UNLOGGED)
10177 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
10178 errmsg(
"constraints on unlogged tables may reference only permanent or unlogged tables")));
10180 case RELPERSISTENCE_TEMP:
10181 if (pkrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
10183 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
10184 errmsg(
"constraints on temporary tables may reference only temporary tables")));
10187 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
10188 errmsg(
"constraints on temporary tables must involve temporary tables of this session")));
10198 fkattnum, fktypoid, fkcolloid);
10202 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10203 errmsg(
"foreign key uses PERIOD on the referenced table but not the referencing table"));
10207 fkdelsetcols, NULL, NULL);
10224 pkattnum, pktypoid, pkcolloid,
10225 opclasses, &pk_has_without_overlaps);
10230 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10231 errmsg(
"foreign key uses PERIOD on the referenced table but not the referencing table"));
10237 pkattnum, pktypoid, pkcolloid);
10242 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10243 errmsg(
"foreign key uses PERIOD on the referencing table but not the referenced table"));
10247 with_period, opclasses, &pk_has_without_overlaps);
10254 if (pk_has_without_overlaps && !with_period)
10256 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10257 errmsg(
"foreign key must use PERIOD when referencing a primary key using WITHOUT OVERLAPS"));
10267 for (
i = 0;
i < numfks;
i++)
10280 (
errcode(ERRCODE_SYNTAX_ERROR),
10281 errmsg(
"invalid %s action for foreign key constraint containing generated column",
10286 (
errcode(ERRCODE_SYNTAX_ERROR),
10287 errmsg(
"invalid %s action for foreign key constraint containing generated column",
10299 if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
10301 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10302 errmsg(
"foreign key constraints on virtual generated columns are not supported")));
10315 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10316 errmsg(
"unsupported %s action for foreign key constraint using PERIOD",
10324 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10325 errmsg(
"unsupported %s action for foreign key constraint using PERIOD",
10337 if (numfks != numpks)
10339 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
10340 errmsg(
"number of referencing and referenced columns for foreign key disagree")));
10349 for (
i = 0;
i < numpks;
i++)
10351 Oid pktype = pktypoid[
i];
10352 Oid fktype = fktypoid[
i];
10354 Oid pkcoll = pkcolloid[
i];
10355 Oid fkcoll = fkcolloid[
i];
10372 elog(
ERROR,
"cache lookup failed for opclass %u", opclasses[
i]);
10374 amid = cla_tup->opcmethod;
10375 opfamily = cla_tup->opcfamily;
10376 opcintype = cla_tup->opcintype;
10389 for_overlaps = with_period &&
i == numpks - 1;
10394 errcode(ERRCODE_UNDEFINED_OBJECT),
10396 ?
errmsg(
"could not identify an overlaps operator for foreign key")
10397 :
errmsg(
"could not identify an equality operator for foreign key"),
10398 errdetail(
"Could not translate compare type %d for operator family \"%s\" of access method \"%s\".",
10409 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
10410 eqstrategy, opcintype, opcintype, opfamily);
10422 pfeqop_right = fktyped;
10444 Oid input_typeids[2];
10445 Oid target_typeids[2];
10447 input_typeids[0] = pktype;
10448 input_typeids[1] = fktype;
10449 target_typeids[0] = opcintype;
10450 target_typeids[1] = opcintype;
10454 pfeqop = ffeqop = ppeqop;
10455 pfeqop_right = opcintype;
10461 (
errcode(ERRCODE_DATATYPE_MISMATCH),
10462 errmsg(
"foreign key constraint \"%s\" cannot be implemented",
10464 errdetail(
"Key columns \"%s\" of the referencing table and \"%s\" of the referenced table "
10465 "are of incompatible types: %s and %s.",
10476 elog(
ERROR,
"key columns are not both collatable");
10493 if ((!pkcolldet || !fkcolldet) && pkcoll != fkcoll)
10495 (
errcode(ERRCODE_COLLATION_MISMATCH),
10496 errmsg(
"foreign key constraint \"%s\" cannot be implemented", fkconstraint->
conname),
10497 errdetail(
"Key columns \"%s\" of the referencing table and \"%s\" of the referenced table "
10498 "have incompatible collations: \"%s\" and \"%s\". "
10499 "If either collation is nondeterministic, then both collations have to be the same.",
10514 old_check_ok = (pfeqop ==
lfirst_oid(old_pfeqop_item));
10536 old_fktype = attr->atttypid;
10537 new_fktype = fktype;
10543 old_fkcoll = attr->attcollation;
10544 new_fkcoll = fkcoll;
10579 old_check_ok = (new_pathtype == old_pathtype &&
10580 new_castfunc == old_castfunc &&
10581 (!IsPolymorphicType(pfeqop_right) ||
10582 new_fktype == old_fktype) &&
10583 (new_fkcoll == old_fkcoll ||
10587 pfeqoperators[
i] = pfeqop;
10588 ppeqoperators[
i] = ppeqop;
10589 ffeqoperators[
i] = ffeqop;
10603 Oid aggedperiodoperoid;
10604 Oid intersectoperoid;
10607 &intersectoperoid);
10612 fkconstraint->
conname, fkconstraint, rel, pkrel,
10677 int numfksetcols,
int16 *fksetcolsattnums,
10680 int numcolsout = 0;
10682 for (
int i = 0;
i < numfksetcols;
i++)
10684 int16 setcol_attnum = fksetcolsattnums[
i];
10688 for (
int j = 0;
j < numfks;
j++)
10690 if (fkattnums[
j] == setcol_attnum)
10702 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
10703 errmsg(
"column \"%s\" referenced in ON DELETE SET action must be part of foreign key", col)));
10708 for (
int j = 0;
j < numcolsout;
j++)
10710 if (fksetcolsattnums[
j] == setcol_attnum)
10717 fksetcolsattnums[numcolsout++] = setcol_attnum;
10753 char *constraintname,
Constraint *fkconstraint,
10755 int numfks,
int16 *pkattnum,
10756 int16 *fkattnum,
Oid *pfeqoperators,
Oid *ppeqoperators,
10757 Oid *ffeqoperators,
int numfkdelsetcols,
int16 *fkdelsetcols,
10758 bool is_internal,
bool with_period)
10771 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
10772 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
10774 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10775 errmsg(
"referenced relation \"%s\" is not a table",
10792 conname = constraintname;
10794 if (fkconstraint->
conname == NULL)
10799 conislocal =
false;
10801 connoinherit =
false;
10811 connoinherit = rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE;
10819 CONSTRAINT_FOREIGN,
10934 Oid *ppeqoperators,
Oid *ffeqoperators,
10935 int numfkdelsetcols,
int16 *fkdelsetcols,
10937 Oid parentDelTrigger,
Oid parentUpdTrigger,
10954 parentConstr, indexOid,
10955 parentDelTrigger, parentUpdTrigger,
10956 &deleteTriggerOid, &updateTriggerOid);
10963 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10988 for (
int j = 0;
j < numfks;
j++)
10989 mapped_pkattnum[
j] = map->
attnums[pkattnum[
j] - 1];
10992 mapped_pkattnum = pkattnum;
10997 elog(
ERROR,
"index for %u not found in partition %s",
11002 fkconstraint->
conname, fkconstraint, rel,
11003 partRel, partIndexId, parentConstr,
11004 numfks, mapped_pkattnum,
11005 fkattnum, pfeqoperators, ppeqoperators,
11006 ffeqoperators, numfkdelsetcols,
11007 fkdelsetcols,
true, with_period);
11010 partIndexId, address.
objectId, numfks,
11011 mapped_pkattnum, fkattnum,
11012 pfeqoperators, ppeqoperators, ffeqoperators,
11013 numfkdelsetcols, fkdelsetcols,
11015 deleteTriggerOid, updateTriggerOid,
11022 pfree(mapped_pkattnum);
11070 int numfks,
int16 *pkattnum,
int16 *fkattnum,
11071 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
11072 int numfkdelsetcols,
int16 *fkdelsetcols,
11073 bool old_check_ok,
LOCKMODE lockmode,
11074 Oid parentInsTrigger,
Oid parentUpdTrigger,
11084 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
11086 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11087 errmsg(
"foreign key constraints are not supported on foreign tables")));
11101 parentInsTrigger, parentUpdTrigger,
11102 &insertTriggerOid, &updateTriggerOid);
11104 if (rel->
rd_rel->relkind == RELKIND_RELATION)
11127 newcon->
conid = parentConstr;
11129 newcon->
qual = (
Node *) fkconstraint;
11134 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11166 for (
int j = 0;
j < numfks;
j++)
11167 mapped_fkattnum[
j] = attmap->
attnums[fkattnum[
j] - 1];
11200 fkconstraint->
conname, fkconstraint,
11201 partition, pkrel, indexOid, parentConstr,
11203 mapped_fkattnum, pfeqoperators,
11204 ppeqoperators, ffeqoperators,
11205 numfkdelsetcols, fkdelsetcols,
true,
11251 Assert(parentRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
11326 foreach(cell, clone)
11340 int numfkdelsetcols;
11349 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
11365 indexOid = constrForm->conindid;
11376 for (
int i = 0;
i < numfks;
i++)
11377 mapped_confkey[
i] = attmap->
attnums[confkey[
i] - 1];
11380 fkconstraint->
contype = CONSTRAINT_FOREIGN;
11382 fkconstraint->
deferrable = constrForm->condeferrable;
11385 fkconstraint->
pktable = NULL;
11388 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
11394 fkconstraint->
is_enforced = constrForm->conenforced;
11399 for (
int i = 0;
i < numfks;
i++)
11416 elog(
ERROR,
"index for %u not found in partition %s",
11424 if (constrForm->conenforced)
11426 constrForm->confrelid, constrForm->conrelid,
11427 &deleteTriggerOid, &updateTriggerOid);
11431 fkconstraint->
conname, fkconstraint, fkRel,
11432 partitionRel, partIndexId, constrOid,
11433 numfks, mapped_confkey,
11434 conkey, conpfeqop, conppeqop, conffeqop,
11435 numfkdelsetcols, confdelsetcols,
false,
11436 constrForm->conperiod);
11454 constrForm->conperiod);
11502 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11503 errmsg(
"cannot attach table \"%s\" as a partition because it is referenced by foreign key \"%s\"",
11517 if (partRel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
11519 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11520 errmsg(
"foreign key constraints are not supported on foreign tables")));
11540 foreach(cell, clone)
11553 int numfkdelsetcols;
11566 elog(
ERROR,
"cache lookup failed for constraint %u",
11582 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11587 conpfeqop, conppeqop, conffeqop,
11588 &numfkdelsetcols, confdelsetcols);
11589 for (
int i = 0;
i < numfks;
i++)
11590 mapped_conkey[
i] = attmap->
attnums[conkey[
i] - 1];
11601 if (constrForm->conenforced)
11603 constrForm->confrelid, constrForm->conrelid,
11604 &insertTriggerOid, &updateTriggerOid);
11614 foreach(lc, partFKs)
11643 fkconstraint->
contype = CONSTRAINT_FOREIGN;
11645 fkconstraint->
deferrable = constrForm->condeferrable;
11648 fkconstraint->
pktable = NULL;
11651 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
11657 fkconstraint->
is_enforced = constrForm->conenforced;
11660 for (
int i = 0;
i < numfks;
i++)
11665 mapped_conkey[
i] - 1);
11670 indexOid = constrForm->conindid;
11671 with_period = constrForm->conperiod;
11675 NameStr(constrForm->conname), fkconstraint,
11676 partRel, pkrel, indexOid, parentConstrOid,
11678 mapped_conkey, conpfeqop,
11679 conppeqop, conffeqop,
11680 numfkdelsetcols, confdelsetcols,
11681 false, with_period);
11727 Oid parentConstrOid,
11732 Oid parentInsTrigger,
11733 Oid parentUpdTrigger,
11744 elog(
ERROR,
"cache lookup failed for constraint %u", parentConstrOid);
11751 if (fk->
confrelid != parentConstr->confrelid || fk->
nkeys != numfks)
11756 for (
int i = 0;
i < numfks;
i++)
11758 if (fk->conkey[
i] != mapped_conkey[
i] ||
11759 fk->confkey[
i] != confkey[
i] ||
11760 fk->conpfeqop[
i] != conpfeqop[
i])
11781 if (partConstr->conenforced != parentConstr->conenforced)
11783 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
11784 errmsg(
"constraint \"%s\" enforceability conflicts with constraint \"%s\" on relation \"%s\"",
11785 NameStr(parentConstr->conname),
11786 NameStr(partConstr->conname),
11790 partConstr->condeferrable != parentConstr->condeferrable ||
11791 partConstr->condeferred != parentConstr->condeferred ||
11792 partConstr->confupdtype != parentConstr->confupdtype ||
11793 partConstr->confdeltype != parentConstr->confdeltype ||
11794 partConstr->confmatchtype != parentConstr->confmatchtype)
11806 parentConstrOid, parentInsTrigger,
11807 parentUpdTrigger, trigrel);
11823 Oid parentConstrOid,
11824 Oid parentInsTrigger,
11825 Oid parentUpdTrigger,
11832 bool queueValidation;
11833 Oid partConstrFrelid;
11834 Oid partConstrRelid;
11835 bool parentConstrIsEnforced;
11841 elog(
ERROR,
"cache lookup failed for constraint %u", parentConstrOid);
11843 parentConstrIsEnforced = parentConstr->conenforced;
11849 elog(
ERROR,
"cache lookup failed for constraint %u", partConstrOid);
11851 partConstrFrelid = partConstr->confrelid;
11852 partConstrRelid = partConstr->conrelid;
11874 queueValidation = parentConstr->convalidated && !partConstr->convalidated;
11896 if (parentConstrIsEnforced)
11898 Oid insertTriggerOid,
11902 partConstrOid, partConstrFrelid, partConstrRelid,
11903 &insertTriggerOid, &updateTriggerOid);
11923 if (queueValidation)
11932 elog(
ERROR,
"cache lookup failed for constraint %u", partConstrOid);
11961 Anum_pg_constraint_conrelid,
11966 ConstraintRelidTypidNameIndexId,
11967 true, NULL, 1, &
key);
11973 if (conform->conparentid != conoid)
11992 ConstraintRelationId,
12001 Anum_pg_trigger_tgconstraint,
12005 true, NULL, 1, &key2);
12041 Anum_pg_trigger_tgconstraint,
12054 if (
OidIsValid(conrelid) && trgform->tgconstrrelid != conrelid)
12056 if (
OidIsValid(confrelid) && trgform->tgrelid != confrelid)
12060 Assert(trgform->tgfoid == F_RI_FKEY_CHECK_INS ||
12061 trgform->tgfoid == F_RI_FKEY_CHECK_UPD ||
12062 trgform->tgfoid == F_RI_FKEY_CASCADE_DEL ||
12063 trgform->tgfoid == F_RI_FKEY_CASCADE_UPD ||
12064 trgform->tgfoid == F_RI_FKEY_RESTRICT_DEL ||
12065 trgform->tgfoid == F_RI_FKEY_RESTRICT_UPD ||
12066 trgform->tgfoid == F_RI_FKEY_SETNULL_DEL ||
12067 trgform->tgfoid == F_RI_FKEY_SETNULL_UPD ||
12068 trgform->tgfoid == F_RI_FKEY_SETDEFAULT_DEL ||
12069 trgform->tgfoid == F_RI_FKEY_SETDEFAULT_UPD ||
12070 trgform->tgfoid == F_RI_FKEY_NOACTION_DEL ||
12071 trgform->tgfoid == F_RI_FKEY_NOACTION_UPD);
12102 Oid conoid,
Oid confrelid,
Oid conrelid,
12103 Oid *deleteTriggerOid,
12104 Oid *updateTriggerOid)
12110 *deleteTriggerOid = *updateTriggerOid =
InvalidOid;
12112 Anum_pg_trigger_tgconstraint,
12122 if (trgform->tgconstrrelid != conrelid)
12124 if (trgform->tgrelid != confrelid)
12129 if (TRIGGER_FOR_DELETE(trgform->tgtype))
12132 *deleteTriggerOid = trgform->oid;
12134 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
12137 *updateTriggerOid = trgform->oid;
12139#ifndef USE_ASSERT_CHECKING
12147 elog(
ERROR,
"could not find ON DELETE action trigger of foreign key constraint %u",
12150 elog(
ERROR,
"could not find ON UPDATE action trigger of foreign key constraint %u",
12163 Oid conoid,
Oid confrelid,
Oid conrelid,
12164 Oid *insertTriggerOid,
12165 Oid *updateTriggerOid)
12171 *insertTriggerOid = *updateTriggerOid =
InvalidOid;
12173 Anum_pg_trigger_tgconstraint,
12183 if (trgform->tgconstrrelid != confrelid)
12185 if (trgform->tgrelid != conrelid)
12190 if (TRIGGER_FOR_INSERT(trgform->tgtype))
12193 *insertTriggerOid = trgform->oid;
12195 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
12198 *updateTriggerOid = trgform->oid;
12200#ifndef USE_ASSERT_CHECKING
12208 elog(
ERROR,
"could not find ON INSERT check triggers of foreign key constraint %u",
12211 elog(
ERROR,
"could not find ON UPDATE check triggers of foreign key constraint %u",
12243 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !recurse)
12245 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12246 errmsg(
"constraint must be altered in child tables too"),
12247 errhint(
"Do not specify the ONLY keyword."));
12257 Anum_pg_constraint_conrelid,
12261 Anum_pg_constraint_contypid,
12265 Anum_pg_constraint_conname,
12269 true, NULL, 3, skey);
12274 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12275 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12281 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
12282 errmsg(
"constraint \"%s\" of relation \"%s\" is not a foreign key constraint",
12286 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
12287 errmsg(
"cannot alter enforceability of constraint \"%s\" of relation \"%s\"",
12290 currcon->contype != CONSTRAINT_NOTNULL)
12292 errcode(ERRCODE_WRONG_OBJECT_TYPE),
12293 errmsg(
"constraint \"%s\" of relation \"%s\" is not a not-null constraint",
12298 cmdcon->
noinherit && currcon->coninhcount > 0)
12300 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12301 errmsg(
"cannot alter inherited constraint \"%s\" on relation \"%s\"",
12317 Oid parent = currcon->conparentid;
12318 char *ancestorname = NULL;
12319 char *ancestortable = NULL;
12335 parent = contup->conparentid;
12340 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12341 errmsg(
"cannot alter constraint \"%s\" on relation \"%s\"",
12343 ancestorname && ancestortable ?
12344 errdetail(
"Constraint \"%s\" is derived from constraint \"%s\" of relation \"%s\".",
12345 cmdcon->
conname, ancestorname, ancestortable) : 0,
12346 errhint(
"You may alter the constraint it derives from instead.")));
12355 contuple, recurse, lockmode))
12377 bool changed =
false;
12396 currcon->conrelid, currcon->confrelid,
12403 contuple, recurse, &otherrelids,
12444 Oid fkrelid,
Oid pkrelid,
12446 Oid ReferencedParentDelTrigger,
12447 Oid ReferencedParentUpdTrigger,
12448 Oid ReferencingParentInsTrigger,
12449 Oid ReferencingParentUpdTrigger)
12454 bool changed =
false;
12462 conoid = currcon->oid;
12465 Assert(currcon->contype == CONSTRAINT_FOREIGN);
12467 rel =
table_open(currcon->conrelid, lockmode);
12483 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
12486 fkrelid, pkrelid, contuple,
12509 if (currcon->conrelid == fkrelid)
12511 currcon->confrelid,
12515 ReferencedParentDelTrigger,
12516 ReferencedParentUpdTrigger,
12517 &ReferencedDelTriggerOid,
12518 &ReferencedUpdTriggerOid);
12521 if (currcon->confrelid == pkrelid)
12527 ReferencingParentInsTrigger,
12528 ReferencingParentUpdTrigger,
12529 &ReferencingInsTriggerOid,
12530 &ReferencingUpdTriggerOid);
12538 if (rel->
rd_rel->relkind == RELKIND_RELATION &&
12539 currcon->confrelid == pkrelid)
12547 newcon->
refrelid = currcon->confrelid;
12548 newcon->
refindid = currcon->conindid;
12549 newcon->
conid = currcon->oid;
12550 newcon->
qual = (
Node *) fkconstraint;
12562 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
12565 fkrelid, pkrelid, contuple,
12566 lockmode, ReferencedDelTriggerOid,
12567 ReferencedUpdTriggerOid,
12568 ReferencingInsTriggerOid,
12569 ReferencingUpdTriggerOid);
12595 bool changed =
false;
12603 refrelid = currcon->confrelid;
12606 Assert(currcon->contype == CONSTRAINT_FOREIGN);
12612 if (currcon->condeferrable != cmdcon->
deferrable ||
12631 if (recurse && changed &&
12632 (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
12635 contuple, recurse, otherrelids,
12659 Assert(currcon->contype == CONSTRAINT_NOTNULL);
12665 if (cmdcon->
noinherit == currcon->connoinherit)
12673 colName =
get_attname(currcon->conrelid, colNum,
false);
12692 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation %u",
12693 colName, childoid);
12695 Assert(childcon->coninhcount > 0);
12696 childcon->coninhcount--;
12697 childcon->conislocal =
true;
12706 colName,
true,
true, lockmode);
12725 bool deferrable,
bool initdeferred,
12726 List **otherrelids)
12733 Anum_pg_trigger_tgconstraint,
12760 if (tgform->tgfoid != F_RI_FKEY_NOACTION_DEL &&
12761 tgform->tgfoid != F_RI_FKEY_NOACTION_UPD &&
12762 tgform->tgfoid != F_RI_FKEY_CHECK_INS &&
12763 tgform->tgfoid != F_RI_FKEY_CHECK_UPD)
12769 copy_tg->tgdeferrable = deferrable;
12770 copy_tg->tginitdeferred = initdeferred;
12795 Oid fkrelid,
Oid pkrelid,
12797 Oid ReferencedParentDelTrigger,
12798 Oid ReferencedParentUpdTrigger,
12799 Oid ReferencingParentInsTrigger,
12800 Oid ReferencingParentUpdTrigger)
12809 conoid = currcon->oid;
12812 Anum_pg_constraint_conparentid,
12817 true, NULL, 1, &pkey);
12821 pkrelid, childtup, lockmode,
12822 ReferencedParentDelTrigger,
12823 ReferencedParentUpdTrigger,
12824 ReferencingParentInsTrigger,
12825 ReferencingParentUpdTrigger);
12854 conoid = currcon->oid;
12857 Anum_pg_constraint_conparentid,
12862 true, NULL, 1, &pkey);
12869 childrel =
table_open(childcon->conrelid, lockmode);
12872 childtup, recurse, otherrelids, lockmode);
12911 copy_con->condeferrable = cmdcon->
deferrable;
12915 copy_con->connoinherit = cmdcon->
noinherit;
12939 bool recurse,
bool recursing,
LOCKMODE lockmode)
12954 Anum_pg_constraint_conrelid,
12958 Anum_pg_constraint_contypid,
12962 Anum_pg_constraint_conname,
12966 true, NULL, 3, skey);
12971 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12972 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12976 if (con->contype != CONSTRAINT_FOREIGN &&
12977 con->contype != CONSTRAINT_CHECK &&
12978 con->contype != CONSTRAINT_NOTNULL)
12980 errcode(ERRCODE_WRONG_OBJECT_TYPE),
12981 errmsg(
"cannot validate constraint \"%s\" of relation \"%s\"",
12983 errdetail(
"This operation is not supported for this type of constraint."));
12985 if (!con->conenforced)
12987 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12988 errmsg(
"cannot validate NOT ENFORCED constraint")));
12990 if (!con->convalidated)
12992 if (con->contype == CONSTRAINT_FOREIGN)
12997 else if (con->contype == CONSTRAINT_CHECK)
13000 tuple, recurse, recursing, lockmode);
13002 else if (con->contype == CONSTRAINT_NOTNULL)
13005 tuple, recurse, recursing, lockmode);
13037 Assert(con->contype == CONSTRAINT_FOREIGN);
13038 Assert(!con->convalidated);
13049 if (fkrel->
rd_rel->relkind == RELKIND_RELATION &&
13050 con->confrelid == pkrelid)
13063 newcon->
refrelid = con->confrelid;
13065 newcon->
conid = con->oid;
13066 newcon->
qual = (
Node *) fkconstraint;
13078 if (fkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
13086 Anum_pg_constraint_conparentid,
13091 true, NULL, 1, &pkey);
13105 if (childcon->convalidated)
13108 childrel =
table_open(childcon->conrelid, lockmode);
13115 childtup, lockmode);
13131 copy_con->convalidated =
true;
13149 bool recurse,
bool recursing,
LOCKMODE lockmode)
13163 Assert(con->contype == CONSTRAINT_CHECK);
13170 if (!recursing && !con->connoinherit)
13181 foreach(child, children)
13196 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13197 errmsg(
"constraint must be validated on child tables too")));
13209 newcon->
name = constrName;
13213 newcon->
conid = con->oid;
13216 Anum_pg_constraint_conbin);
13234 copy_con->convalidated =
true;
13251 HeapTuple contuple,
bool recurse,
bool recursing,
13263 Assert(con->contype == CONSTRAINT_NOTNULL);
13275 if (!recursing && !con->connoinherit)
13296 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13297 errmsg(
"constraint must be validated on child tables too"));
13305 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation \"%s\"",
13308 if (childcon->convalidated)
13317 false,
true, lockmode);
13337 copy_con->convalidated =
true;
13364 foreach(l, colList)
13373 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13374 errmsg(
"column \"%s\" referenced in foreign key constraint does not exist",
13377 if (attform->attnum < 0)
13379 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13380 errmsg(
"system columns cannot be used in foreign keys")));
13383 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
13384 errmsg(
"cannot have more than %d keys in a foreign key",
13386 attnums[
attnum] = attform->attnum;
13387 if (atttypids != NULL)
13388 atttypids[
attnum] = attform->atttypid;
13389 if (attcollids != NULL)
13390 attcollids[
attnum] = attform->attcollation;
13413 List **attnamelist,
13415 Oid *opclasses,
bool *pk_has_without_overlaps)
13417 List *indexoidlist;
13421 Datum indclassDatum;
13434 foreach(indexoidscan, indexoidlist)
13440 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
13442 if (indexStruct->indisprimary && indexStruct->indisvalid)
13449 if (!indexStruct->indimmediate)
13451 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
13452 errmsg(
"cannot use a deferrable primary key for referenced table \"%s\"",
13455 *indexOid = indexoid;
13468 (
errcode(ERRCODE_UNDEFINED_OBJECT),
13469 errmsg(
"there is no primary key for referenced table \"%s\"",
13474 Anum_pg_index_indclass);
13481 *attnamelist =
NIL;
13482 for (
i = 0;
i < indexStruct->indnkeyatts;
i++)
13484 int pkattno = indexStruct->indkey.values[
i];
13486 attnums[
i] = pkattno;
13489 opclasses[
i] = indclass->
values[
i];
13490 *attnamelist =
lappend(*attnamelist,
13494 *pk_has_without_overlaps = indexStruct->indisexclusion;
13516 int numattrs,
int16 *attnums,
13517 bool with_period,
Oid *opclasses,
13518 bool *pk_has_without_overlaps)
13521 bool found =
false;
13522 bool found_deferrable =
false;
13523 List *indexoidlist;
13535 for (
i = 0;
i < numattrs;
i++)
13537 for (
j =
i + 1;
j < numattrs;
j++)
13539 if (attnums[
i] == attnums[
j])
13541 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
13542 errmsg(
"foreign key referenced-columns list must not contain duplicates")));
13553 foreach(indexoidscan, indexoidlist)
13561 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
13569 if (indexStruct->indnkeyatts == numattrs &&
13570 (with_period ? indexStruct->indisexclusion : indexStruct->indisunique) &&
13571 indexStruct->indisvalid &&
13575 Datum indclassDatum;
13580 Anum_pg_index_indclass);
13593 for (
i = 0;
i < numattrs;
i++)
13596 for (
j = 0;
j < numattrs;
j++)
13598 if (attnums[
i] == indexStruct->indkey.values[
j])
13600 opclasses[
i] = indclass->
values[
j];
13609 if (found && with_period)
13611 int16 periodattnum = attnums[numattrs - 1];
13613 found = (periodattnum == indexStruct->indkey.values[numattrs - 1]);
13621 if (found && !indexStruct->indimmediate)
13627 found_deferrable =
true;
13633 *pk_has_without_overlaps = indexStruct->indisexclusion;
13642 if (found_deferrable)
13644 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
13645 errmsg(
"cannot use a deferrable unique constraint for referenced table \"%s\"",
13649 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
13650 errmsg(
"there is no unique constraint matching given keys for referenced table \"%s\"",
13670 if (targetTypeId == sourceTypeId)
13681 elog(
ERROR,
"could not find cast from %u to %u",
13682 sourceTypeId, targetTypeId);
13707 for (
i = 0;
i < natts;
i++)
13739 (
errmsg_internal(
"validating foreign key constraint \"%s\"", conname)));
13774 "validateForeignKeyConstraint",
13795 trigdata.
type = T_TriggerData;
13802 fcinfo->context = (
Node *) &trigdata;
13825 Oid constraintOid,
Oid indexOid,
Oid parentTrigOid,
13843 fk_trigger->
trigname =
"RI_ConstraintTrigger_c";
13850 fk_trigger->
events = TRIGGER_TYPE_INSERT;
13855 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
13859 fk_trigger->
row =
true;
13860 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
13868 trigAddress =
CreateTrigger(fk_trigger, NULL, myRelOid, refRelOid,
13870 parentTrigOid, NULL,
true,
false);
13888 Oid constraintOid,
Oid indexOid,
13889 Oid parentDelTrigger,
Oid parentUpdTrigger,
13890 Oid *deleteTrigOid,
Oid *updateTrigOid)
13902 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
13905 fk_trigger->
row =
true;
13906 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
13907 fk_trigger->
events = TRIGGER_TYPE_DELETE;
13941 elog(
ERROR,
"unrecognized FK action type: %d",
13946 trigAddress =
CreateTrigger(fk_trigger, NULL, refRelOid, myRelOid,
13948 parentDelTrigger, NULL,
true,
false);
13950 *deleteTrigOid = trigAddress.
objectId;
13962 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
13965 fk_trigger->
row =
true;
13966 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
13967 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
14001 elog(
ERROR,
"unrecognized FK action type: %d",
14006 trigAddress =
CreateTrigger(fk_trigger, NULL, refRelOid, myRelOid,
14008 parentUpdTrigger, NULL,
true,
false);
14010 *updateTrigOid = trigAddress.
objectId;
14025 Oid parentInsTrigger,
Oid parentUpdTrigger,
14026 Oid *insertTrigOid,
Oid *updateTrigOid)
14029 constraintOid, indexOid,
14030 parentInsTrigger,
true);
14032 constraintOid, indexOid,
14033 parentUpdTrigger,
false);
14044 bool missing_ok,
LOCKMODE lockmode)
14050 bool found =
false;
14058 Anum_pg_constraint_conrelid,
14062 Anum_pg_constraint_contypid,
14066 Anum_pg_constraint_conname,
14070 true, NULL, 3, skey);
14076 missing_ok, lockmode);
14086 errcode(ERRCODE_UNDEFINED_OBJECT),
14087 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
14091 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist, skipping",
14108 bool recurse,
bool recursing,
bool missing_ok,
14115 bool is_no_inherit_constraint =
false;
14117 char *colname = NULL;
14130 constrName =
NameStr(con->conname);
14133 if (con->coninhcount > 0 && !recursing)
14135 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14136 errmsg(
"cannot drop inherited constraint \"%s\" of relation \"%s\"",
14146 if (con->contype == CONSTRAINT_NOTNULL)
14167 if (pkattrs == NULL &&
14168 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
14177 for (
int i = 0;
i < pk->
rd_index->indnkeyatts;
i++)
14187 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14188 errmsg(
"column \"%s\" is in a primary key",
14195 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14196 errmsg(
"column \"%s\" is in index used as replica identity",
14202 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
14205 if (attForm->attidentity !=
'\0')
14207 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
14208 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
14214 if (attForm->attnotnull)
14216 attForm->attnotnull =
false;
14223 is_no_inherit_constraint = con->connoinherit;
14232 if (con->contype == CONSTRAINT_FOREIGN &&
14253 if (con->contype != CONSTRAINT_CHECK &&
14254 con->contype != CONSTRAINT_NOTNULL &&
14255 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
14266 if (!is_no_inherit_constraint)
14285 if (con->contype == CONSTRAINT_NOTNULL)
14289 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation %u",
14298 Anum_pg_constraint_conrelid,
14302 Anum_pg_constraint_contypid,
14306 Anum_pg_constraint_conname,
14310 true, NULL, 3, skey);
14315 (
errcode(ERRCODE_UNDEFINED_OBJECT),
14316 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
14326 if (childcon->contype != CONSTRAINT_CHECK &&
14327 childcon->contype != CONSTRAINT_NOTNULL)
14328 elog(
ERROR,
"inherited constraint is not a CHECK or not-null constraint");
14330 if (childcon->coninhcount <= 0)
14331 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
14332 childrelid,
NameStr(childcon->conname));
14340 if (childcon->coninhcount == 1 && !childcon->conislocal)
14344 recurse,
true, missing_ok,
14350 childcon->coninhcount--;
14365 childcon->coninhcount--;
14366 if (childcon->coninhcount == 0)
14367 childcon->conislocal =
true;
14405 bool recurse,
bool recursing,
14409 char *colName = cmd->
name;
14417 int32 targettypmod;
14426 if (rel->
rd_rel->reloftype && !recursing)
14428 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14429 errmsg(
"cannot alter column type of typed table"),
14436 (
errcode(ERRCODE_UNDEFINED_COLUMN),
14437 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
14441 attnum = attTup->attnum;
14446 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14447 errmsg(
"cannot alter system column \"%s\"", colName),
14456 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
14457 errmsg(
"cannot specify USING when altering type of generated column"),
14458 errdetail(
"Column \"%s\" is a generated column.", colName),
14466 if (attTup->attinhcount > 0 && !recursing)
14468 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14469 errmsg(
"cannot alter inherited column \"%s\"", colName),
14477 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14478 errmsg(
"cannot alter column \"%s\" because it is part of the partition key of relation \"%s\"",
14497 if (attTup->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
14501 else if (tab->
relkind == RELKIND_RELATION ||
14502 tab->
relkind == RELKIND_PARTITIONED_TABLE)
14516 attTup->atttypid, attTup->atttypmod,
14517 attTup->attcollation,
14523 targettype, targettypmod,
14527 if (transform == NULL)
14532 (
errcode(ERRCODE_DATATYPE_MISMATCH),
14533 errmsg(
"result of USING clause for column \"%s\""
14534 " cannot be cast automatically to type %s",
14536 errhint(
"You might need to add an explicit cast.")));
14539 (
errcode(ERRCODE_DATATYPE_MISMATCH),
14540 errmsg(
"column \"%s\" cannot be cast automatically to type %s",
14542 !attTup->attgenerated ?
14544 errhint(
"You might need to specify \"USING %s::%s\".",
14547 targettypmod)) : 0));
14566 newval->is_generated =
false;
14572 else if (transform)
14574 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14575 errmsg(
"\"%s\" is not a table",
14578 if (!RELKIND_HAS_STORAGE(tab->
relkind) || attTup->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
14607 &child_numparents);
14614 forboth(lo, child_oids, li, child_numparents)
14622 if (childrelid == relid)
14639 (
errcode(ERRCODE_UNDEFINED_COLUMN),
14640 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
14644 if (childattTup->attinhcount > numparents)
14646 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14647 errmsg(
"cannot alter inherited column \"%s\" of relation \"%s\"",
14659 bool found_whole_row;
14672 if (found_whole_row)
14674 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14675 errmsg(
"cannot convert whole-row table reference"),
14676 errdetail(
"USING expression contains a whole-row table reference.")));
14679 ATPrepCmd(wqueue, childrel, cmd,
false,
true, lockmode, context);
14683 else if (!recursing &&
14686 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14687 errmsg(
"type of inherited column \"%s\" must be changed in child tables too",
14690 if (tab->
relkind == RELKIND_COMPOSITE_TYPE)
14716 if (
IsA(expr,
Var) && ((
Var *) expr)->varattno == varattno)
14734 case F_TIMESTAMPTZ_TIMESTAMP:
14735 case F_TIMESTAMP_TIMESTAMPTZ:
14759 char *colName = cmd->
name;
14769 int32 targettypmod;
14800 (
errcode(ERRCODE_UNDEFINED_COLUMN),
14801 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
14804 attnum = attTup->attnum;
14808 if (attTup->atttypid != attOldTup->atttypid ||
14809 attTup->atttypmod != attOldTup->atttypmod)
14811 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14812 errmsg(
"cannot alter type of column \"%s\" twice",
14816 typeTuple =
typenameType(NULL, typeName, &targettypmod);
14818 targettype = tform->oid;
14834 if (attTup->atthasdef)
14840 defaultexpr,
exprType(defaultexpr),
14841 targettype, targettypmod,
14845 if (defaultexpr == NULL)
14847 if (attTup->attgenerated)
14849 (
errcode(ERRCODE_DATATYPE_MISMATCH),
14850 errmsg(
"generation expression for column \"%s\" cannot be cast automatically to type %s",
14854 (
errcode(ERRCODE_DATATYPE_MISMATCH),
14855 errmsg(
"default for column \"%s\" cannot be cast automatically to type %s",
14860 defaultexpr = NULL;
14881 Anum_pg_depend_classid,
14885 Anum_pg_depend_objid,
14889 Anum_pg_depend_objsubid,
14901 foundObject.
classId = foundDep->refclassid;
14902 foundObject.
objectId = foundDep->refobjid;
14906 elog(
ERROR,
"found unexpected dependency type '%c'",
14907 foundDep->deptype);
14908 if (!(foundDep->refclassid == TypeRelationId &&
14909 foundDep->refobjid == attTup->atttypid) &&
14910 !(foundDep->refclassid == CollationRelationId &&
14911 foundDep->refobjid == attTup->attcollation))
14912 elog(
ERROR,
"found unexpected dependency for column: %s",
14927 if (attTup->atthasmissing)
14937 Anum_pg_attribute_attmissingval,
14938 attrelation->rd_att,
14954 Datum valuesAtt[Natts_pg_attribute] = {0};
14955 bool nullsAtt[Natts_pg_attribute] = {0};
14956 bool replacesAtt[Natts_pg_attribute] = {0};
14974 valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
14975 replacesAtt[Anum_pg_attribute_attmissingval - 1] =
true;
14976 nullsAtt[Anum_pg_attribute_attmissingval - 1] =
false;
14979 valuesAtt, nullsAtt, replacesAtt);
14986 attTup->atttypid = targettype;
14987 attTup->atttypmod = targettypmod;
14988 attTup->attcollation = targetcollid;
14991 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
14992 errmsg(
"too many array dimensions"));
14993 attTup->attndims =
list_length(typeName->arrayBounds);
14994 attTup->attlen = tform->typlen;
14995 attTup->attbyval = tform->typbyval;
14996 attTup->attalign = tform->typalign;
14997 attTup->attstorage = tform->typstorage;
15032 if (attTup->attgenerated)
15037 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
15086 Anum_pg_depend_refclassid,
15090 Anum_pg_depend_refobjid,
15094 Anum_pg_depend_refobjsubid,
15106 foundObject.
classId = foundDep->classid;
15107 foundObject.
objectId = foundDep->objid;
15112 case RelationRelationId:
15116 if (relKind == RELKIND_INDEX ||
15117 relKind == RELKIND_PARTITIONED_INDEX)
15122 else if (relKind == RELKIND_SEQUENCE)
15133 elog(
ERROR,
"unexpected object depending on column: %s",
15139 case ConstraintRelationId:
15144 case ProcedureRelationId:
15158 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15159 errmsg(
"cannot alter type of a column used by a function or procedure"),
15160 errdetail(
"%s depends on column \"%s\"",
15165 case RewriteRelationId:
15173 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15174 errmsg(
"cannot alter type of a column used by a view or rule"),
15175 errdetail(
"%s depends on column \"%s\"",
15180 case TriggerRelationId:
15193 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15194 errmsg(
"cannot alter type of a column used in a trigger definition"),
15195 errdetail(
"%s depends on column \"%s\"",
15200 case PolicyRelationId:
15212 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15213 errmsg(
"cannot alter type of a column used in a policy definition"),
15214 errdetail(
"%s depends on column \"%s\"",
15219 case AttrDefaultRelationId:
15243 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15244 errmsg(
"cannot alter type of a column used by a generated column"),
15245 errdetail(
"Column \"%s\" is used by generated column \"%s\".",
15254 case StatisticExtRelationId:
15263 case PublicationRelRelationId:
15271 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15272 errmsg(
"cannot alter type of a column used by a publication WHERE clause"),
15273 errdetail(
"%s depends on column \"%s\"",
15284 elog(
ERROR,
"unexpected object depending on column: %s",
15305 elog(
ERROR,
"relation %u has multiple indexes marked as replica identity", tab->
relid);
15320 elog(
ERROR,
"relation %u has multiple clustered indexes", tab->
relid);
15508 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
15511 relid = con->conrelid;
15517 elog(
ERROR,
"could not identify relation associated with constraint %u", oldId);
15519 confrelid = con->confrelid;
15520 conislocal = con->conislocal;
15542 if (relid != tab->
relid)
15546 (
char *)
lfirst(def_item),
15547 wqueue, lockmode, tab->
rewrite);
15549 forboth(oid_item, tab->changedIndexOids,
15550 def_item, tab->changedIndexDefs)
15561 if (relid != tab->relid)
15565 (
char *)
lfirst(def_item),
15566 wqueue, lockmode, tab->rewrite);
15573 forboth(oid_item, tab->changedStatisticsOids,
15574 def_item, tab->changedStatisticsDefs)
15591 if (relid != tab->relid)
15595 (
char *)
lfirst(def_item),
15596 wqueue, lockmode, tab->rewrite);
15605 if (tab->replicaIdentityIndex)
15611 subcmd->
name = tab->replicaIdentityIndex;
15623 if (tab->clusterOnIndex)
15628 cmd->
name = tab->clusterOnIndex;
15661 List *raw_parsetree_list;
15662 List *querytree_list;
15673 querytree_list =
NIL;
15674 foreach(list_item, raw_parsetree_list)
15680 querytree_list =
lappend(querytree_list,
15694 querytree_list =
list_concat(querytree_list, beforeStmts);
15696 querytree_list =
list_concat(querytree_list, afterStmts);
15699 querytree_list =
lappend(querytree_list,
15718 foreach(list_item, querytree_list)
15732 stmt->reset_default_tblspc =
true;
15747 foreach(lcmd,
stmt->cmds)
15763 RelationRelationId, 0);
15785 !rewrite && tab->
rewrite == 0)
15809 elog(
ERROR,
"unexpected statement subtype: %d",
15836 elog(
ERROR,
"unexpected statement subtype: %d",
15837 (
int)
stmt->subtype);
15845 stmt->stxcomment =
GetComment(oldId, StatisticExtRelationId, 0);
15854 elog(
ERROR,
"unexpected statement type: %d",
15874 const char *conname)
15881 comment_str =
GetComment(objid, ConstraintRelationId, 0);
15882 if (comment_str == NULL)
15919 stmt->accessMethod,
15921 stmt->excludeOpNames,
15922 stmt->iswithoutoverlaps))
15927 if (irel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
15959 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
15962 Anum_pg_constraint_conpfeqop);
15969 elog(
ERROR,
"conpfeqop is not a 1-D Oid array");
15973 for (
i = 0;
i < numkeys;
i++)
15986 const char *colName,
15997 Datum repl_val[Natts_pg_attribute];
15998 bool repl_null[Natts_pg_attribute];
15999 bool repl_repl[Natts_pg_attribute];
16014 (
errcode(ERRCODE_UNDEFINED_OBJECT),
16015 errmsg(
"foreign table \"%s\" does not exist",
16028 (
errcode(ERRCODE_UNDEFINED_COLUMN),
16029 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
16034 attnum = atttableform->attnum;
16037 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16038 errmsg(
"cannot alter system column \"%s\"", colName)));
16042 memset(repl_val, 0,
sizeof(repl_val));
16043 memset(repl_null,
false,
sizeof(repl_null));
16044 memset(repl_repl,
false,
sizeof(repl_repl));
16049 Anum_pg_attribute_attfdwoptions,
16061 repl_val[Anum_pg_attribute_attfdwoptions - 1] = datum;
16063 repl_null[Anum_pg_attribute_attfdwoptions - 1] =
true;
16065 repl_repl[Anum_pg_attribute_attfdwoptions - 1] =
true;
16070 repl_val, repl_null, repl_repl);
16076 atttableform->attnum);
16120 elog(
ERROR,
"cache lookup failed for relation %u", relationOid);
16124 switch (tuple_class->relkind)
16126 case RELKIND_RELATION:
16128 case RELKIND_MATVIEW:
16129 case RELKIND_FOREIGN_TABLE:
16130 case RELKIND_PARTITIONED_TABLE:
16133 case RELKIND_INDEX:
16143 if (tuple_class->relowner != newOwnerId)
16145 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16146 errmsg(
"cannot change owner of index \"%s\"",
16147 NameStr(tuple_class->relname)),
16148 errhint(
"Change the ownership of the index's table instead.")));
16150 newOwnerId = tuple_class->relowner;
16153 case RELKIND_PARTITIONED_INDEX:
16157 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16158 errmsg(
"cannot change owner of index \"%s\"",
16159 NameStr(tuple_class->relname)),
16160 errhint(
"Change the ownership of the index's table instead.")));
16162 case RELKIND_SEQUENCE:
16164 tuple_class->relowner != newOwnerId)
16173 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16174 errmsg(
"cannot change owner of sequence \"%s\"",
16175 NameStr(tuple_class->relname)),
16176 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
16177 NameStr(tuple_class->relname),
16181 case RELKIND_COMPOSITE_TYPE:
16185 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16186 errmsg(
"\"%s\" is a composite type",
16187 NameStr(tuple_class->relname)),
16192 case RELKIND_TOASTVALUE:
16198 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16199 errmsg(
"cannot change owner of relation \"%s\"",
16200 NameStr(tuple_class->relname)),
16208 if (tuple_class->relowner != newOwnerId)
16210 Datum repl_val[Natts_pg_class];
16211 bool repl_null[Natts_pg_class];
16212 bool repl_repl[Natts_pg_class];
16224 Oid namespaceOid = tuple_class->relnamespace;
16236 aclresult =
object_aclcheck(NamespaceRelationId, namespaceOid, newOwnerId,
16244 memset(repl_null,
false,
sizeof(repl_null));
16245 memset(repl_repl,
false,
sizeof(repl_repl));
16247 repl_repl[Anum_pg_class_relowner - 1] =
true;
16255 Anum_pg_class_relacl,
16260 tuple_class->relowner, newOwnerId);
16261 repl_repl[Anum_pg_class_relacl - 1] =
true;
16276 tuple_class->relowner,
16284 if (tuple_class->relkind != RELKIND_COMPOSITE_TYPE &&
16285 tuple_class->relkind != RELKIND_INDEX &&
16286 tuple_class->relkind != RELKIND_PARTITIONED_INDEX &&
16287 tuple_class->relkind != RELKIND_TOASTVALUE)
16302 if (tuple_class->relkind == RELKIND_RELATION ||
16303 tuple_class->relkind == RELKIND_PARTITIONED_TABLE ||
16304 tuple_class->relkind == RELKIND_MATVIEW ||
16305 tuple_class->relkind == RELKIND_TOASTVALUE)
16307 List *index_oid_list;
16314 foreach(
i, index_oid_list)
16321 if (tuple_class->reltoastrelid !=
InvalidOid)
16352 Anum_pg_attribute_attrelid,
16356 true, NULL, 1,
key);
16360 Datum repl_val[Natts_pg_attribute];
16361 bool repl_null[Natts_pg_attribute];
16362 bool repl_repl[Natts_pg_attribute];
16369 if (att->attisdropped)
16373 Anum_pg_attribute_attacl,
16380 memset(repl_null,
false,
sizeof(repl_null));
16381 memset(repl_repl,
false,
sizeof(repl_repl));
16384 oldOwnerId, newOwnerId);
16385 repl_repl[Anum_pg_attribute_attacl - 1] =
true;
16390 repl_val, repl_null, repl_repl);
16422 Anum_pg_depend_refclassid,
16426 Anum_pg_depend_refobjid,
16440 if (depForm->refobjsubid == 0 ||
16441 depForm->classid != RelationRelationId ||
16442 depForm->objsubid != 0 ||
16486 (
errcode(ERRCODE_UNDEFINED_OBJECT),
16487 errmsg(
"index \"%s\" for table \"%s\" does not exist",
16497 RelationRelationId, indexOid);
16530 if (amname != NULL)
16532 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
16538 if (rel->
rd_rel->relam == amoid)
16558 Oid oldAccessMethodId;
16574 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
16578 oldAccessMethodId = rd_rel->relam;
16579 rd_rel->relam = newAccessMethodId;
16582 if (rd_rel->relam == oldAccessMethodId)
16618 AccessMethodRelationId,
16628 AccessMethodRelationId,
16629 oldAccessMethodId, rd_rel->relam);
16665 (
errcode(ERRCODE_SYNTAX_ERROR),
16666 errmsg(
"cannot have multiple SET TABLESPACE subcommands")));
16684 Datum repl_val[Natts_pg_class];
16685 bool repl_null[Natts_pg_class];
16686 bool repl_repl[Natts_pg_class];
16698 elog(
ERROR,
"cache lookup failed for relation %u", relid);
16724 switch (rel->
rd_rel->relkind)
16726 case RELKIND_RELATION:
16727 case RELKIND_MATVIEW:
16730 case RELKIND_PARTITIONED_TABLE:
16736 case RELKIND_INDEX:
16737 case RELKIND_PARTITIONED_INDEX:
16740 case RELKIND_TOASTVALUE:
16744 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16745 errmsg(
"cannot set options for relation \"%s\"",
16752 if (rel->
rd_rel->relkind == RELKIND_VIEW)
16757 bool check_option =
false;
16759 foreach(cell, view_options)
16763 if (strcmp(defel->
defname,
"check_option") == 0)
16764 check_option =
true;
16773 const char *view_updatable_error =
16776 if (view_updatable_error)
16778 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16779 errmsg(
"WITH CHECK OPTION is supported only on automatically updatable views"),
16780 errhint(
"%s",
_(view_updatable_error))));
16788 memset(repl_val, 0,
sizeof(repl_val));
16789 memset(repl_null,
false,
sizeof(repl_null));
16790 memset(repl_repl,
false,
sizeof(repl_repl));
16792 if (newOptions != (
Datum) 0)
16793 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
16795 repl_null[Anum_pg_class_reloptions - 1] =
true;
16797 repl_repl[Anum_pg_class_reloptions - 1] =
true;
16800 repl_val, repl_null, repl_repl);
16815 Oid toastid = rel->
rd_rel->reltoastrelid;
16822 elog(
ERROR,
"cache lookup failed for relation %u", toastid);
16848 memset(repl_val, 0,
sizeof(repl_val));
16849 memset(repl_null,
false,
sizeof(repl_null));
16850 memset(repl_repl,
false,
sizeof(repl_repl));
16852 if (newOptions != (
Datum) 0)
16853 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
16855 repl_null[Anum_pg_class_reloptions - 1] =
true;
16857 repl_repl[Anum_pg_class_reloptions - 1] =
true;
16860 repl_val, repl_null, repl_repl);
16906 reltoastrelid = rel->
rd_rel->reltoastrelid;
16921 rel->
rd_rel->relpersistence);
16925 newrlocator.
relNumber = newrelfilenumber;
16926 newrlocator.
spcOid = newTableSpace;
16929 if (rel->
rd_rel->relkind == RELKIND_INDEX)
16961 foreach(lc, reltoastidxids)
17023 Oid orig_tablespaceoid;
17024 Oid new_tablespaceoid;
17031 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17032 errmsg(
"only tables, indexes, and materialized views exist in tablespaces")));
17040 if (orig_tablespaceoid == GLOBALTABLESPACE_OID ||
17041 new_tablespaceoid == GLOBALTABLESPACE_OID)
17043 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
17044 errmsg(
"cannot move relations in to or out of pg_global tablespace")));
17073 if (orig_tablespaceoid == new_tablespaceoid)
17074 return new_tablespaceoid;
17081 Anum_pg_class_reltablespace,
17090 Oid relOid = relForm->oid;
17101 relForm->relisshared ||
17108 relForm->relkind != RELKIND_RELATION &&
17109 relForm->relkind != RELKIND_PARTITIONED_TABLE) ||
17111 relForm->relkind != RELKIND_INDEX &&
17112 relForm->relkind != RELKIND_PARTITIONED_INDEX) ||
17114 relForm->relkind != RELKIND_MATVIEW))
17132 if (
stmt->nowait &&
17135 (
errcode(ERRCODE_OBJECT_IN_USE),
17136 errmsg(
"aborting because lock on relation \"%s.%s\" is not available",
17138 NameStr(relForm->relname))));
17149 if (relations ==
NIL)
17151 (
errcode(ERRCODE_NO_DATA_FOUND),
17152 errmsg(
"no matching relations in tablespace \"%s\" found",
17153 orig_tablespaceoid ==
InvalidOid ?
"(database default)" :
17157 foreach(l, relations)
17163 cmd->
name =
stmt->new_tablespacename;
17173 return new_tablespaceoid;
17200 rel->
rd_rel->relpersistence);
17215 (rel->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
17219 rel->
rd_rel->relpersistence);
17235 char fires_when,
bool skip_system,
bool recurse,
17239 fires_when, skip_system, recurse,
17253 char fires_when,
LOCKMODE lockmode)
17271 if (child_rel->
rd_rel->reloftype)
17273 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17274 errmsg(
"cannot change inheritance of typed table")));
17276 if (child_rel->
rd_rel->relispartition)
17278 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17279 errmsg(
"cannot change inheritance of a partition")));
17281 if (child_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
17283 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17284 errmsg(
"cannot change inheritance of partitioned table")));
17296 const char *trigger_name;
17312 if (parent_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
17313 child_rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
17315 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17316 errmsg(
"cannot inherit from temporary relation \"%s\"",
17322 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17323 errmsg(
"cannot inherit from temporary relation of another session")));
17328 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17329 errmsg(
"cannot inherit to temporary relation of another session")));
17332 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
17334 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17335 errmsg(
"cannot inherit from partitioned table \"%s\"",
17339 if (parent_rel->
rd_rel->relispartition)
17341 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17342 errmsg(
"cannot inherit from a partition")));
17363 (
errcode(ERRCODE_DUPLICATE_TABLE),
17364 errmsg(
"circular inheritance not allowed"),
17365 errdetail(
"\"%s\" is already a child of \"%s\".",
17375 if (trigger_name != NULL)
17377 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17378 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming an inheritance child",
17380 errdetail(
"ROW triggers with transition tables are not supported in inheritance hierarchies.")));
17423 Anum_pg_inherits_inhrelid,
17427 true, NULL, 1, &
key);
17437 (
errcode(ERRCODE_DUPLICATE_TABLE),
17438 errmsg(
"relation \"%s\" would be inherited from more than once",
17441 if (inh->inhseqno > inhseqno)
17442 inhseqno = inh->inhseqno;
17459 parent_rel->
rd_rel->relkind ==
17460 RELKIND_PARTITIONED_TABLE);
17479 attr =
heap_getattr(contup, Anum_pg_constraint_conbin, tupdesc, &isnull);
17481 elog(
ERROR,
"null conbin for constraint %u", con->oid);
17504 if (acon->condeferrable != bcon->condeferrable ||
17505 acon->condeferred != bcon->condeferred ||
17536 for (
AttrNumber parent_attno = 1; parent_attno <= parent_desc->
natts; parent_attno++)
17539 char *parent_attname =
NameStr(parent_att->attname);
17543 if (parent_att->attisdropped)
17552 if (parent_att->atttypid != child_att->atttypid ||
17553 parent_att->atttypmod != child_att->atttypmod)
17555 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17556 errmsg(
"child table \"%s\" has different type for column \"%s\"",
17559 if (parent_att->attcollation != child_att->attcollation)
17561 (
errcode(ERRCODE_COLLATION_MISMATCH),
17562 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
17571 if (parent_att->attnotnull && !child_att->attnotnull)
17576 parent_att->attnum);
17580 errcode(ERRCODE_DATATYPE_MISMATCH),
17581 errmsg(
"column \"%s\" in child table \"%s\" must be marked NOT NULL",
17588 if (parent_att->attgenerated && !child_att->attgenerated)
17590 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17591 errmsg(
"column \"%s\" in child table must be a generated column", parent_attname)));
17592 if (child_att->attgenerated && !parent_att->attgenerated)
17594 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17595 errmsg(
"column \"%s\" in child table must not be a generated column", parent_attname)));
17597 if (parent_att->attgenerated && child_att->attgenerated && child_att->attgenerated != parent_att->attgenerated)
17599 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17600 errmsg(
"column \"%s\" inherits from generated column of different kind", parent_attname),
17601 errdetail(
"Parent column is %s, child column is %s.",
17602 parent_att->attgenerated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL",
17603 child_att->attgenerated == ATTRIBUTE_GENERATED_STORED ?
"STORED" :
"VIRTUAL")));
17611 child_att->attidentity = parent_att->attidentity;
17618 &child_att->attinhcount))
17620 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
17621 errmsg(
"too many inheritance parents"));
17628 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
17630 Assert(child_att->attinhcount == 1);
17631 child_att->attislocal =
false;
17640 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17641 errmsg(
"child table is missing column \"%s\"", parent_attname)));
17679 Anum_pg_constraint_conrelid,
17683 true, NULL, 1, &parent_key);
17696 bool found =
false;
17698 if (parent_con->contype != CONSTRAINT_CHECK &&
17699 parent_con->contype != CONSTRAINT_NOTNULL)
17703 if (parent_con->connoinherit)
17706 if (parent_con->contype == CONSTRAINT_NOTNULL)
17713 Anum_pg_constraint_conrelid,
17717 true, NULL, 1, &child_key);
17724 if (child_con->contype != parent_con->contype)
17731 if (child_con->contype == CONSTRAINT_CHECK)
17733 if (strcmp(
NameStr(parent_con->conname),
17734 NameStr(child_con->conname)) != 0)
17737 else if (child_con->contype == CONSTRAINT_NOTNULL)
17745 if (parent_attno != attmap->
attnums[child_attno - 1])
17750 if (parent_attr->attisdropped || child_attr->attisdropped)
17751 elog(
ERROR,
"found not-null constraint on dropped columns");
17754 if (child_con->contype == CONSTRAINT_CHECK &&
17757 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17758 errmsg(
"child table \"%s\" has different definition for check constraint \"%s\"",
17764 if (child_con->connoinherit)
17766 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
17767 errmsg(
"constraint \"%s\" conflicts with non-inherited constraint on child table \"%s\"",
17774 if (parent_con->convalidated && child_con->conenforced &&
17775 !child_con->convalidated)
17777 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
17778 errmsg(
"constraint \"%s\" conflicts with NOT VALID constraint on child table \"%s\"",
17786 if (parent_con->conenforced && !child_con->conenforced)
17788 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
17789 errmsg(
"constraint \"%s\" conflicts with NOT ENFORCED constraint on child table \"%s\"",
17800 &child_con->coninhcount))
17802 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
17803 errmsg(
"too many inheritance parents"));
17810 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
17812 Assert(child_con->coninhcount == 1);
17813 child_con->conislocal =
false;
17827 if (parent_con->contype == CONSTRAINT_NOTNULL)
17829 errcode(ERRCODE_DATATYPE_MISMATCH),
17830 errmsg(
"column \"%s\" in child table \"%s\" must be marked NOT NULL",
17837 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17838 errmsg(
"child table is missing constraint \"%s\"",
17839 NameStr(parent_con->conname))));
17858 if (rel->
rd_rel->relispartition)
17860 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17861 errmsg(
"cannot change inheritance of a partition")));
17901 bool found =
false;
17903 Assert(parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
17911 Anum_pg_inherits_inhparent,
17915 true, NULL, 1, &
key);
17922 if (inhForm->inhdetachpending)
17924 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
17925 errmsg(
"partition \"%s\" already pending detach in partitioned table \"%s.%s\"",
17929 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
17954 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
17989 bool is_partitioning;
17991 is_partitioning = (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
17999 if (is_partitioning)
18002 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
18008 errmsg(
"relation \"%s\" is not a parent of relation \"%s\"",
18018 Anum_pg_attribute_attrelid,
18022 true, NULL, 1,
key);
18028 if (att->attisdropped)
18030 if (att->attinhcount <= 0)
18040 copy_att->attinhcount--;
18041 if (copy_att->attinhcount == 0)
18042 copy_att->attislocal =
true;
18066 Anum_pg_constraint_conrelid,
18070 true, NULL, 1,
key);
18079 if (con->connoinherit)
18082 if (con->contype == CONSTRAINT_CHECK)
18084 if (con->contype == CONSTRAINT_NOTNULL)
18096 Anum_pg_constraint_conrelid,
18100 true, NULL, 1,
key);
18105 bool match =
false;
18111 if (con->contype == CONSTRAINT_CHECK)
18115 if (con->contype == CONSTRAINT_CHECK &&
18116 strcmp(
NameStr(con->conname), chkname) == 0)
18124 else if (con->contype == CONSTRAINT_NOTNULL)
18130 if (prevattno == child_attno)
18147 if (copy_con->coninhcount <= 0)
18148 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
18151 copy_con->coninhcount--;
18152 if (copy_con->coninhcount == 0)
18153 copy_con->conislocal =
true;
18161 if (connames !=
NIL || nncolumns !=
NIL)
18162 elog(
ERROR,
"%d unmatched constraints while removing inheritance from \"%s\" to \"%s\"",
18170 RelationRelationId,
18203 Anum_pg_depend_classid,
18207 Anum_pg_depend_objid,
18211 Anum_pg_depend_objsubid,
18222 if (dep->refclassid == refclassid &&
18223 dep->refobjid == refobjid &&
18224 dep->refobjsubid == 0 &&
18225 dep->deptype == deptype)
18266 typeid = typeform->oid;
18271 Anum_pg_inherits_inhrelid,
18275 true, NULL, 1, &
key);
18278 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18279 errmsg(
"typed tables cannot inherit")));
18290 for (type_attno = 1; type_attno <= typeTupleDesc->
natts; type_attno++)
18294 const char *type_attname,
18299 if (type_attr->attisdropped)
18301 type_attname =
NameStr(type_attr->attname);
18306 if (table_attno > tableTupleDesc->
natts)
18308 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18309 errmsg(
"table is missing column \"%s\"",
18311 table_attr =
TupleDescAttr(tableTupleDesc, table_attno - 1);
18313 }
while (table_attr->attisdropped);
18314 table_attname =
NameStr(table_attr->attname);
18317 if (strncmp(table_attname, type_attname,
NAMEDATALEN) != 0)
18319 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18320 errmsg(
"table has column \"%s\" where type requires \"%s\"",
18321 table_attname, type_attname)));
18324 if (table_attr->atttypid != type_attr->atttypid ||
18325 table_attr->atttypmod != type_attr->atttypmod ||
18326 table_attr->attcollation != type_attr->attcollation)
18328 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18329 errmsg(
"table \"%s\" has different type for column \"%s\"",
18335 for (; table_attno <= tableTupleDesc->
natts; table_attno++)
18340 if (!table_attr->attisdropped)
18342 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18343 errmsg(
"table has extra column \"%s\"",
18344 NameStr(table_attr->attname))));
18348 if (rel->
rd_rel->reloftype)
18353 tableobj.
classId = RelationRelationId;
18356 typeobj.
classId = TypeRelationId;
18365 elog(
ERROR,
"cache lookup failed for relation %u", relid);
18394 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18395 errmsg(
"\"%s\" is not a typed table",
18410 elog(
ERROR,
"cache lookup failed for relation %u", relid);
18448 elog(
ERROR,
"cache lookup failed for relation \"%s\"",
18451 if (pg_class_form->relreplident != ri_type)
18453 pg_class_form->relreplident = ri_type;
18466 bool dirty =
false;
18471 elog(
ERROR,
"cache lookup failed for index %u", thisIndexOid);
18474 if (thisIndexOid == indexOid)
18477 if (!pg_index_form->indisreplident)
18480 pg_index_form->indisreplident =
true;
18486 if (pg_index_form->indisreplident)
18489 pg_index_form->indisreplident =
false;
18524 if (
stmt->identity_type == REPLICA_IDENTITY_DEFAULT)
18529 else if (
stmt->identity_type == REPLICA_IDENTITY_FULL)
18534 else if (
stmt->identity_type == REPLICA_IDENTITY_NOTHING)
18539 else if (
stmt->identity_type == REPLICA_IDENTITY_INDEX)
18544 elog(
ERROR,
"unexpected identity type %u",
stmt->identity_type);
18550 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18551 errmsg(
"index \"%s\" for table \"%s\" does not exist",
18560 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18561 errmsg(
"\"%s\" is not an index for table \"%s\"",
18571 !indexRel->
rd_index->indisunique) &&
18574 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18575 errmsg(
"cannot use non-unique index \"%s\" as replica identity",
18578 if (!indexRel->
rd_index->indimmediate)
18580 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18581 errmsg(
"cannot use non-immediate index \"%s\" as replica identity",
18586 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18587 errmsg(
"cannot use expression index \"%s\" as replica identity",
18592 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18593 errmsg(
"cannot use partial index \"%s\" as replica identity",
18609 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
18610 errmsg(
"index \"%s\" cannot be used as replica identity because column %d is a system column",
18614 if (!attr->attnotnull)
18616 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18617 errmsg(
"index \"%s\" cannot be used as replica identity because column \"%s\" is nullable",
18646 elog(
ERROR,
"cache lookup failed for relation %u", relid);
18675 elog(
ERROR,
"cache lookup failed for relation %u", relid);
18698 Datum repl_val[Natts_pg_foreign_table];
18699 bool repl_null[Natts_pg_foreign_table];
18700 bool repl_repl[Natts_pg_foreign_table];
18713 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18714 errmsg(
"foreign table \"%s\" does not exist",
18720 memset(repl_val, 0,
sizeof(repl_val));
18721 memset(repl_null,
false,
sizeof(repl_null));
18722 memset(repl_repl,
false,
sizeof(repl_repl));
18727 Anum_pg_foreign_table_ftoptions,
18739 repl_val[Anum_pg_foreign_table_ftoptions - 1] = datum;
18741 repl_null[Anum_pg_foreign_table_ftoptions - 1] =
true;
18743 repl_repl[Anum_pg_foreign_table_ftoptions - 1] =
true;
18748 repl_val, repl_null, repl_repl);
18773 const char *column,
18785 compression =
strVal(newValue);
18793 (
errcode(ERRCODE_UNDEFINED_COLUMN),
18794 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
18799 attnum = atttableform->attnum;
18802 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18803 errmsg(
"cannot alter system column \"%s\"", column)));
18812 atttableform->attcompression = cmethod;
18861 switch (rel->
rd_rel->relpersistence)
18863 case RELPERSISTENCE_TEMP:
18865 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
18866 errmsg(
"cannot change logged status of table \"%s\" because it is temporary",
18870 case RELPERSISTENCE_PERMANENT:
18875 case RELPERSISTENCE_UNLOGGED:
18889 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
18890 errmsg(
"cannot change table \"%s\" to unlogged because it is part of a publication",
18892 errdetail(
"Unlogged relations cannot be replicated.")));
18906 toLogged ? Anum_pg_constraint_conrelid :
18907 Anum_pg_constraint_confrelid,
18911 toLogged ? ConstraintRelidTypidNameIndexId :
InvalidOid,
18912 true, NULL, 1, skey);
18918 if (con->contype == CONSTRAINT_FOREIGN)
18924 foreignrelid = toLogged ? con->confrelid : con->conrelid;
18936 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
18937 errmsg(
"could not change table \"%s\" to logged because it references unlogged table \"%s\"",
18946 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
18947 errmsg(
"could not change table \"%s\" to unlogged because it references logged table \"%s\"",
18992 (
errmsg(
"relation \"%s\" does not exist, skipping",
18993 stmt->relation->relname)));
19002 if (rel->
rd_rel->relkind == RELKIND_SEQUENCE)
19010 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19011 errmsg(
"cannot move an owned sequence into another schema"),
19012 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
19031 *oldschema = oldNspOid;
19050 Assert(objsMoved != NULL);
19056 nspOid,
true, objsMoved);
19083 Oid oldNspOid,
Oid newNspOid,
19084 bool hasDependEntry,
19090 bool already_done =
false;
19095 elog(
ERROR,
"cache lookup failed for relation %u", relOid);
19098 Assert(classForm->relnamespace == oldNspOid);
19100 thisobj.
classId = RelationRelationId;
19110 if (!already_done && oldNspOid != newNspOid)
19118 (
errcode(ERRCODE_DUPLICATE_TABLE),
19119 errmsg(
"relation \"%s\" already exists in schema \"%s\"",
19124 classForm->relnamespace = newNspOid;
19131 if (hasDependEntry &&
19134 NamespaceRelationId,
19137 elog(
ERROR,
"could not change schema dependency for relation \"%s\"",
19138 NameStr(classForm->relname));
19167 foreach(l, indexList)
19172 thisobj.
classId = RelationRelationId;
19187 oldNspOid, newNspOid,
19220 Anum_pg_depend_refclassid,
19224 Anum_pg_depend_refobjid,
19238 if (depForm->refobjsubid == 0 ||
19239 depForm->classid != RelationRelationId ||
19240 depForm->objsubid != 0 ||
19257 oldNspOid, newNspOid,
19333 if (oc->
relid == relid)
19351 List *oids_to_truncate =
NIL;
19392 if (oids_to_truncate !=
NIL)
19395 if (oids_to_drop !=
NIL)
19399 foreach(l, oids_to_drop)
19403 object.
classId = RelationRelationId;
19405 object.objectSubId = 0;
19427#ifdef USE_ASSERT_CHECKING
19540 if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE &&
19541 relkind != RELKIND_MATVIEW && relkind != RELKIND_PARTITIONED_TABLE)
19543 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19544 errmsg(
"\"%s\" is not a table or materialized view", relation->
relname)));
19569 elog(
ERROR,
"cache lookup failed for relation %u", relId);
19593 elog(
ERROR,
"cache lookup failed for relation %u", relId);
19602 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
19603 errmsg(
"permission denied: \"%s\" is a system catalog",
19628 relkind = classform->relkind;
19637 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
19638 errmsg(
"permission denied: \"%s\" is a system catalog",
19649 aclresult =
object_aclcheck(NamespaceRelationId, classform->relnamespace,
19676 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19679 if (reltype ==
OBJECT_VIEW && relkind != RELKIND_VIEW)
19681 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19686 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19687 errmsg(
"\"%s\" is not a materialized view", rv->
relname)));
19691 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19694 if (reltype ==
OBJECT_TYPE && relkind != RELKIND_COMPOSITE_TYPE)
19696 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19699 if (reltype ==
OBJECT_INDEX && relkind != RELKIND_INDEX &&
19700 relkind != RELKIND_PARTITIONED_INDEX
19703 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19710 if (reltype !=
OBJECT_TYPE && relkind == RELKIND_COMPOSITE_TYPE)
19712 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19724 if (relkind == RELKIND_INDEX || relkind == RELKIND_PARTITIONED_INDEX)
19726 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19727 errmsg(
"cannot change schema of index \"%s\"",
19729 errhint(
"Change the schema of the table instead.")));
19730 else if (relkind == RELKIND_COMPOSITE_TYPE)
19732 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19733 errmsg(
"cannot change schema of composite type \"%s\"",
19738 else if (relkind == RELKIND_TOASTVALUE)
19740 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19741 errmsg(
"cannot change schema of TOAST table \"%s\"",
19743 errhint(
"Change the schema of the table instead.")));
19772 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19773 errmsg(
"cannot use \"list\" partition strategy with more than one column")));
19781 NULL,
false,
true);
19814 List **partexprs,
Oid *partopclass,
Oid *partcollation,
19822 foreach(lc, partParams)
19828 if (pelem->
name != NULL)
19838 (
errcode(ERRCODE_UNDEFINED_COLUMN),
19839 errmsg(
"column \"%s\" named in partition key does not exist",
19844 if (attform->attnum <= 0)
19846 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19847 errmsg(
"cannot use system column \"%s\" in partition key",
19858 if (attform->attgenerated)
19860 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19861 errmsg(
"cannot use generated column in partition key"),
19862 errdetail(
"Column \"%s\" is a generated column.",
19866 partattrs[attn] = attform->attnum;
19867 atttype = attform->atttypid;
19868 attcollation = attform->attcollation;
19875 char partattname[16];
19889 snprintf(partattname,
sizeof(partattname),
"%d", attn + 1);
19891 atttype, attcollation,
19929 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19930 errmsg(
"partition key expressions cannot contain system column references")));
19942 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19943 errmsg(
"cannot use generated column in partition key"),
19944 errdetail(
"Column \"%s\" is a generated column.",
19950 ((
Var *) expr)->varattno > 0)
19957 partattrs[attn] = ((
Var *) expr)->varattno;
19961 partattrs[attn] = 0;
19962 *partexprs =
lappend(*partexprs, expr);
19993 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19994 errmsg(
"functions in partition key expression must be marked IMMUTABLE")));
20002 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
20003 errmsg(
"cannot use constant expression as partition key")));
20023 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
20024 errmsg(
"could not determine which collation to use for partition expression"),
20025 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
20031 (
errcode(ERRCODE_DATATYPE_MISMATCH),
20032 errmsg(
"collations are not supported by type %s",
20036 partcollation[attn] = attcollation;
20044 am_oid = HASH_AM_OID;
20046 am_oid = BTREE_AM_OID;
20056 (
errcode(ERRCODE_UNDEFINED_OBJECT),
20057 errmsg(
"data type %s has no default operator class for access method \"%s\"",
20059 errhint(
"You must specify a hash operator class or define a default hash operator class for the data type.")));
20062 (
errcode(ERRCODE_UNDEFINED_OBJECT),
20063 errmsg(
"data type %s has no default operator class for access method \"%s\"",
20065 errhint(
"You must specify a btree operator class or define a default btree operator class for the data type.")));
20071 am_oid == HASH_AM_OID ?
"hash" :
"btree",
20088 List *partConstraint)
20098 for (
i = 1;
i <= natts;
i++)
20110 wholeatt->atttypid,
20111 wholeatt->atttypmod,
20112 wholeatt->attcollation,
20121 ntest->argisrow =
false;
20123 existConstraint =
lappend(existConstraint, ntest);
20149 num_check = (constr != NULL) ? constr->
num_check : 0;
20150 for (
i = 0;
i < num_check;
i++)
20206 List *partConstraint,
20207 bool validate_default)
20215 if (!validate_default)
20217 (
errmsg_internal(
"partition constraint for table \"%s\" is implied by existing constraints",
20221 (
errmsg_internal(
"updated partition constraint for default partition \"%s\" is implied by existing constraints",
20231 if (scanrel->
rd_rel->relkind == RELKIND_RELATION)
20241 else if (scanrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
20249 List *thisPartConstraint;
20260 thisPartConstraint =
20262 part_rel, scanrel);
20265 thisPartConstraint,
20317 List *attachrel_children;
20318 List *partConstraint;
20325 const char *trigger_name;
20326 Oid defaultPartOid;
20327 List *partBoundConstraint;
20356 if (attachrel->
rd_rel->relispartition)
20358 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20359 errmsg(
"\"%s\" is already a partition",
20364 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20365 errmsg(
"cannot attach a typed table as partition")));
20373 Anum_pg_inherits_inhrelid,
20380 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20381 errmsg(
"cannot attach inheritance child as partition")));
20386 Anum_pg_inherits_inhparent,
20392 attachrel->
rd_rel->relkind == RELKIND_RELATION)
20394 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20395 errmsg(
"cannot attach inheritance parent as partition")));
20418 (
errcode(ERRCODE_DUPLICATE_TABLE),
20419 errmsg(
"circular inheritance not allowed"),
20420 errdetail(
"\"%s\" is already a child of \"%s\".",
20425 if (rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
20426 attachrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
20428 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20429 errmsg(
"cannot attach a temporary relation as partition of permanent relation \"%s\"",
20433 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
20434 attachrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
20436 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20437 errmsg(
"cannot attach a permanent relation as partition of temporary relation \"%s\"",
20443 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20444 errmsg(
"cannot attach as partition of temporary relation of another session")));
20449 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20450 errmsg(
"cannot attach temporary relation of another session as partition")));
20457 natts = tupleDesc->
natts;
20458 for (attno = 1; attno <= natts; attno++)
20461 char *attributeName =
NameStr(attribute->attname);
20464 if (attribute->attisdropped)
20467 if (attribute->attidentity)
20469 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20470 errmsg(
"table \"%s\" being attached contains an identity column \"%s\"",
20472 errdetail(
"The new partition may not contain an identity column."));
20479 (
errcode(ERRCODE_DATATYPE_MISMATCH),
20480 errmsg(
"table \"%s\" contains column \"%s\" not found in parent \"%s\"",
20483 errdetail(
"The new partition may contain only the columns present in parent.")));
20492 if (trigger_name != NULL)
20494 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20495 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming a partition",
20497 errdetail(
"ROW triggers with transition tables are not supported on partitions.")));
20505 cmd->
bound, pstate);
20525 if (partConstraint)
20534 (
Node *) partConstraint);
20561 List *defPartConstraint;
20567 defPartConstraint =
20574 defPartConstraint =
20576 1, defaultrel, rel);
20578 defPartConstraint,
true);
20592 if (attachrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
20596 foreach(l, attachrel_children)
20620 List *attachRelIdxs;
20628 "AttachPartitionEnsureIndexes",
20652 if (attachrel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
20654 foreach(cell, idxes)
20659 if (idxRel->
rd_index->indisunique ||
20662 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
20663 errmsg(
"cannot attach foreign table \"%s\" as partition of partitioned table \"%s\"",
20666 errdetail(
"Partitioned table \"%s\" contains unique indexes.",
20678 foreach(cell, idxes)
20684 bool found =
false;
20691 if (idxRel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
20715 if (attachrelIdxRels[
i]->rd_rel->relispartition)
20719 if (!attachrelIdxRels[
i]->rd_index->indisvalid)
20723 attachrelIdxRels[
i]->rd_indcollation,
20780 true,
false,
false,
false,
false);
20812 true, NULL, 1, &
key);
20831 if (!TRIGGER_FOR_ROW(trigForm->tgtype))
20838 if (trigForm->tgisinternal)
20844 if (!TRIGGER_FOR_BEFORE(trigForm->tgtype) &&
20845 !TRIGGER_FOR_AFTER(trigForm->tgtype))
20846 elog(
ERROR,
"unexpected trigger \"%s\" found",
20862 partition, parent);
20864 partition, parent);
20871 if (trigForm->tgattr.dim1 > 0)
20875 for (
i = 0;
i < trigForm->tgattr.dim1;
i++)
20880 trigForm->tgattr.values[
i] - 1);
20887 if (trigForm->tgnargs > 0)
20894 elog(
ERROR,
"tgargs is null for trigger \"%s\" in partition \"%s\"",
20899 for (
int i = 0;
i < trigForm->tgnargs;
i++)
20902 p += strlen(p) + 1;
20912 trigStmt->
args = trigargs;
20913 trigStmt->
row =
true;
20914 trigStmt->
timing = trigForm->tgtype & TRIGGER_TYPE_TIMING_MASK;
20915 trigStmt->
events = trigForm->tgtype & TRIGGER_TYPE_EVENT_MASK;
20919 trigStmt->
deferrable = trigForm->tgdeferrable;
20925 trigForm->tgfoid, trigForm->oid, qual,
20926 false,
true, trigForm->tgenabled);
20962 Oid defaultPartOid;
20989 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20990 errmsg(
"cannot detach partitions concurrently when a default partition exists")));
21032 char *parentrelname;
21088 if (partRel != NULL)
21089 elog(
WARNING,
"dangling partition \"%s\" remains, can't fix",
21092 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
21093 errmsg(
"partitioned table \"%s\" was removed concurrently",
21096 if (partRel == NULL)
21098 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
21099 errmsg(
"partition \"%s\" was removed concurrently", partrelname)));
21131 Oid defaultPartOid)
21137 Datum new_val[Natts_pg_class];
21138 bool new_null[Natts_pg_class],
21139 new_repl[Natts_pg_class];
21196 if (conform->contype != CONSTRAINT_FOREIGN ||
21218 Oid insertTriggerOid,
21223 &insertTriggerOid, &updateTriggerOid);
21250 int numfkdelsetcols;
21266 fkconstraint->
contype = CONSTRAINT_FOREIGN;
21268 fkconstraint->
deferrable = conform->condeferrable;
21270 fkconstraint->
is_enforced = conform->conenforced;
21274 fkconstraint->
pktable = NULL;
21286 for (
int i = 0;
i < numfks;
i++)
21313 conform->conperiod);
21336 ConstraintRelationId,
21346 foreach(cell, indexes)
21352 Oid parentConstrOid;
21384 elog(
ERROR,
"cache lookup failed for relation %u",
21389 memset(new_val, 0,
sizeof(new_val));
21390 memset(new_null,
false,
sizeof(new_null));
21391 memset(new_repl,
false,
sizeof(new_repl));
21392 new_val[Anum_pg_class_relpartbound - 1] = (
Datum) 0;
21393 new_null[Anum_pg_class_relpartbound - 1] =
true;
21394 new_repl[Anum_pg_class_relpartbound - 1] =
true;
21396 new_val, new_null, new_repl);
21410 if (!attr->attisdropped && attr->attidentity)
21444 if (partRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
21450 foreach(cell, children)
21515 true, NULL, 1, &skey);
21541 RelationRelationId,
21580 if (!
state->lockedParentTbl)
21583 state->lockedParentTbl =
true;
21606 if (classform->relkind != RELKIND_PARTITIONED_INDEX &&
21607 classform->relkind != RELKIND_INDEX)
21609 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
21644 state.lockedParentTbl =
false;
21652 (
errcode(ERRCODE_UNDEFINED_OBJECT),
21653 errmsg(
"index \"%s\" does not exist",
name->relname)));
21665 currParent = partIdx->
rd_rel->relispartition ?
21686 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
21687 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
21690 errdetail(
"Index \"%s\" is already attached to another index.",
21698 if (partDesc->
oids[
i] ==
state.partitionOid)
21706 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
21707 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
21710 errdetail(
"Index \"%s\" is not an index on any partition of table \"%s\".",
21727 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
21728 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
21731 errdetail(
"The index definitions do not match.")));
21746 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
21747 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
21750 errdetail(
"The index \"%s\" belongs to a constraint in table \"%s\" but no constraint exists for index \"%s\".",
21760 if (parentIdx->
rd_index->indisprimary)
21795 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
21796 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
21799 errdetail(
"Another index \"%s\" is already attached for partition \"%s\".",
21818 bool updated =
false;
21820 Assert(partedIdx->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX);
21842 elog(
ERROR,
"cache lookup failed for index %u", inhForm->inhrelid);
21844 if (indexForm->indisvalid)
21867 elog(
ERROR,
"cache lookup failed for index %u",
21871 indexForm->indisvalid =
true;
21884 if (updated && partedIdx->
rd_rel->relispartition)
21920 if (!att->attnotnull)
21922 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
21923 errmsg(
"invalid primary key definition"),
21924 errdetail(
"Column \"%s\" of relation \"%s\" is not marked NOT NULL.",
21973 constraints =
lappend_oid(constraints, constrForm->oid);
21979 return constraints;
21995 foreach(cell, constraints)
22005 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
22041 if (compression == NULL || strcmp(compression,
"default") == 0)
22058 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
22059 errmsg(
"column data type %s does not support compression",
22065 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
22066 errmsg(
"invalid compression method \"%s\"", compression)));
22080 cstorage = TYPSTORAGE_PLAIN;
22082 cstorage = TYPSTORAGE_EXTERNAL;
22084 cstorage = TYPSTORAGE_EXTENDED;
22086 cstorage = TYPSTORAGE_MAIN;
22091 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
22092 errmsg(
"invalid storage type \"%s\"",
22101 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
22102 errmsg(
"column data type %s can only have storage PLAIN",
22123 switch (con->contype)
22137 elog(
ERROR,
"unrecognized constraint type: %d",
22138 (
int) con->contype);
22162 if (!ex->is_generated)
22173 switch (con->contype)
22176 if (!
ExecCheck(con->qualstate, econtext))
22178 errcode(ERRCODE_CHECK_VIOLATION),
22179 errmsg(
"check constraint \"%s\" of relation \"%s\" is violated by some row",
22188 elog(
ERROR,
"unrecognized constraint type: %d",
22189 (
int) con->contype);
22206 for (parent_attno = 1; parent_attno <= modelDesc->
natts;
22214 if (attribute->attisdropped)
22218 attribute->atttypmod, attribute->attcollation);
22223 def->
identity = attribute->attidentity;
22226 def->
generated = attribute->attgenerated;
22228 def->
storage = attribute->attstorage;
22238 colList =
lappend(colList, def);
22260 List *cookedConstraints =
NIL;
22263 constr = tupleDesc->
constr;
22278 for (parent_attno = 1; parent_attno <= tupleDesc->
natts; parent_attno++)
22284 if (attribute->attisdropped)
22288 if (attribute->atthasdef)
22290 Node *this_default = NULL;
22291 bool found_whole_row;
22296 if (attribute->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
22301 if (this_default == NULL)
22302 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
22306 num = attmap->
attnums[parent_attno - 1];
22309 if (found_whole_row && attribute->attgenerated !=
'\0')
22310 elog(
ERROR,
"cannot convert whole-row table reference");
22321 if (attribute->attgenerated == ATTRIBUTE_GENERATED_STORED)
22326 newval->is_generated = (attribute->attgenerated !=
'\0');
22333 for (ccnum = 0; ccnum < constr->
num_check; ccnum++)
22341 bool found_whole_row;
22359 if (found_whole_row)
22360 elog(
ERROR,
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
22376 constraints =
lappend(constraints, constr);
22381 false,
true,
true, NULL);
22394 if (!ccon->skip_validation)
22413 newcon->
name = ccon->name;
22415 newcon->
qual = qual;
22428 List *nnconstraints;
22474 errcode(ERRCODE_WRONG_OBJECT_TYPE),
22475 errmsg(
"cannot create as partition of temporary relation of another session"));
22484 relamId = (parent_relform->relam !=
InvalidOid) ? parent_relform->relam : HEAP_TABLE_AM_OID;
22491 errcode(ERRCODE_DUPLICATE_TABLE),
22492 errmsg(
"relation \"%s\" already exists", newPartName->
relname));
22500 if (parent_relform->relpersistence != RELPERSISTENCE_TEMP &&
22503 errcode(ERRCODE_WRONG_OBJECT_TYPE),
22504 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
22509 parent_relform->relpersistence == RELPERSISTENCE_TEMP)
22511 errcode(ERRCODE_WRONG_OBJECT_TYPE),
22512 errmsg(
"cannot create a permanent relation as partition of temporary relation \"%s\"",
22518 parent_relform->reltablespace,
22653 insertslot = dstslot;
22679 insertslot, econtext);
22683 ti_options, bistate);
22709 foreach(ltab, *wqueue)
22750 List *mergingPartitions =
NIL;
22751 Oid defaultPartOid;
22755 int save_sec_context;
22756 int save_nestlevel;
22778 if (ownerId != mergingPartition->
rd_rel->relowner)
22780 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
22781 errmsg(
"partitions being merged have different owners"));
22784 ownerId = mergingPartition->
rd_rel->relowner;
22787 mergingPartitions =
lappend_oid(mergingPartitions,
22832 errcode(ERRCODE_DUPLICATE_TABLE),
22841 foreach_oid(mergingPartitionOid, mergingPartitions)
22861 foreach_oid(mergingPartitionOid, mergingPartitions)
22866 object.
objectId = mergingPartitionOid;
22867 object.classId = RelationRelationId;
22868 object.objectSubId = 0;
22898 foreach_oid(mergingPartitionOid, mergingPartitions)
22902 object.
objectId = mergingPartitionOid;
22903 object.classId = RelationRelationId;
22904 object.objectSubId = 0;
22982 foreach(ltab, *wqueue)
23008 List *partlist,
List *newPartRels)
23030 forboth(listptr, partlist, listptr2, newPartRels)
23047 defaultPartCtx = pc;
23051 List *partConstraint;
23057 (
Node *) partConstraint);
23068 pc->partqualstate =
23070 Assert(pc->partqualstate != NULL);
23074 partContexts =
lappend(partContexts, pc);
23103 bool found =
false;
23111 foreach(listptr, partContexts)
23116 if (pc->partqualstate &&
ExecCheck(pc->partqualstate, econtext))
23125 if (defaultPartCtx)
23126 pc = defaultPartCtx;
23129 errcode(ERRCODE_CHECK_VIOLATION),
23130 errmsg(
"can not find partition for split partition row"),
23145 insertslot = pc->dstslot;
23171 insertslot, econtext);
23175 ti_options, pc->bistate);
23207 bool isSameName =
false;
23211 Oid defaultPartOid;
23213 int save_sec_context;
23214 int save_nestlevel;
23238 if (existingRelid == splitRelOid && !isSameName)
23243 errcode(ERRCODE_DUPLICATE_TABLE),
23244 errmsg(
"relation \"%s\" already exists", sps->name->relname));
23259 object.objectId = splitRelOid;
23260 object.classId = RelationRelationId;
23261 object.objectSubId = 0;
23292 splitRel->
rd_rel->relowner);
23293 newPartRels =
lappend(newPartRels, newPartRel);
23331 object.classId = RelationRelationId;
23332 object.objectId = splitRelOid;
23333 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(ParseState *pstate, 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)
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
const 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)