96 #include "utils/fmgroids.h"
164 #define AT_NUM_PASSES (AT_PASS_MISC + 1)
263 gettext_noop(
"sequence \"%s\" does not exist, skipping"),
265 gettext_noop(
"Use DROP SEQUENCE to remove a sequence.")},
274 gettext_noop(
"materialized view \"%s\" does not exist"),
275 gettext_noop(
"materialized view \"%s\" does not exist, skipping"),
277 gettext_noop(
"Use DROP MATERIALIZED VIEW to remove a materialized view.")},
279 ERRCODE_UNDEFINED_OBJECT,
284 {RELKIND_COMPOSITE_TYPE,
285 ERRCODE_UNDEFINED_OBJECT,
290 {RELKIND_FOREIGN_TABLE,
291 ERRCODE_UNDEFINED_OBJECT,
293 gettext_noop(
"foreign table \"%s\" does not exist, skipping"),
295 gettext_noop(
"Use DROP FOREIGN TABLE to remove a foreign table.")},
296 {RELKIND_PARTITIONED_TABLE,
302 {RELKIND_PARTITIONED_INDEX,
303 ERRCODE_UNDEFINED_OBJECT,
308 {
'\0', 0, NULL, NULL, NULL, NULL}
326 #define ATT_TABLE 0x0001
327 #define ATT_VIEW 0x0002
328 #define ATT_MATVIEW 0x0004
329 #define ATT_INDEX 0x0008
330 #define ATT_COMPOSITE_TYPE 0x0010
331 #define ATT_FOREIGN_TABLE 0x0020
332 #define ATT_PARTITIONED_INDEX 0x0040
333 #define ATT_SEQUENCE 0x0080
354 #define child_dependency_type(child_is_partition) \
355 ((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
363 bool is_partition,
List **supconstr,
371 bool child_is_partition);
374 bool child_is_partition);
382 bool recurse,
bool recursing,
LOCKMODE lockmode);
388 bool recurse,
bool recursing,
LOCKMODE lockmode);
394 Oid *opclasses,
bool *pk_has_without_overlaps);
396 int numattrs,
int16 *attnums,
397 bool with_period,
Oid *opclasses,
398 bool *pk_has_without_overlaps);
404 Oid pkindOid,
Oid constraintOid,
bool hasperiod);
409 bool recurse,
bool recursing,
LOCKMODE lockmode,
441 bool recurse,
bool recursing,
453 char *constrname,
char *colName,
454 bool recurse,
bool recursing,
457 const char *colName,
LOCKMODE lockmode);
460 List *testConstraint,
List *provenConstraint);
466 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
468 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
470 bool recurse,
bool recursing);
486 bool recurse,
bool recursing,
497 Constraint *newConstraint,
bool recurse,
bool is_readd,
505 bool recurse,
bool recursing,
bool is_readd,
509 bool recurse,
bool recursing,
514 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
515 int numfkdelsetcols,
int16 *fkdelsetcols,
517 Oid parentDelTrigger,
Oid parentUpdTrigger,
520 int numfksetcols,
const int16 *fksetcolsattnums,
525 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
526 int numfkdelsetcols,
int16 *fkdelsetcols,
527 bool old_check_ok,
LOCKMODE lockmode,
528 Oid parentInsTrigger,
Oid parentUpdTrigger,
539 Oid parentInsTrigger,
Oid parentUpdTrigger,
540 Oid *insertTrigOid,
Oid *updateTrigOid);
544 Oid parentDelTrigger,
Oid parentUpdTrigger,
545 Oid *deleteTrigOid,
Oid *updateTrigOid);
548 Oid parentConstrOid,
int numfks,
551 Oid parentInsTrigger,
552 Oid parentUpdTrigger,
556 Oid *deleteTriggerOid,
557 Oid *updateTriggerOid);
560 Oid *insertTriggerOid,
561 Oid *updateTriggerOid);
564 bool missing_ok,
LOCKMODE lockmode);
567 bool recurse,
bool recursing,
568 bool missing_ok,
List **readyRels,
572 bool recurse,
bool recursing,
590 const char *conname);
596 Oid oldOwnerId,
Oid newOwnerId);
606 const char *tablespacename,
LOCKMODE lockmode);
613 char fires_when,
bool skip_system,
bool recurse,
616 char fires_when,
LOCKMODE lockmode);
635 Oid oldRelOid,
void *
arg);
640 List **partexprs,
Oid *partopclass,
Oid *partcollation,
644 bool expect_detached);
652 List *partConstraint,
653 bool validate_default);
661 bool concurrent,
Oid defaultPartOid);
710 List *old_constraints;
713 List *cookedDefaults;
735 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
737 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
738 errmsg(
"ON COMMIT can only be used on temporary tables")));
740 if (
stmt->partspec != NULL)
742 if (relkind != RELKIND_RELATION)
743 elog(
ERROR,
"unexpected relkind: %d", (
int) relkind);
745 relkind = RELKIND_PARTITIONED_TABLE;
765 if (
stmt->relation->relpersistence == RELPERSISTENCE_TEMP
768 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
769 errmsg(
"cannot create temporary table within security-restricted operation")));
792 foreach(listptr,
stmt->inhRelations)
804 (
errcode(ERRCODE_DUPLICATE_TABLE),
805 errmsg(
"relation \"%s\" would be inherited from more than once",
815 if (
stmt->tablespacename)
821 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
822 errmsg(
"cannot specify default tablespace for partitioned relations")));
824 else if (
stmt->partbound)
850 if (tablespaceId == GLOBALTABLESPACE_OID)
852 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
853 errmsg(
"only shared relations can be placed in pg_global tablespace")));
870 case RELKIND_PARTITIONED_TABLE:
877 if (
stmt->ofTypename)
897 stmt->relation->relpersistence,
898 stmt->partbound != NULL,
899 &old_constraints, &old_notnulls);
922 cookedDefaults =
NIL;
925 foreach(listptr,
stmt->tableElts)
944 rawDefaults =
lappend(rawDefaults, rawEnt);
945 attr->atthasdef =
true;
961 cookedDefaults =
lappend(cookedDefaults, cooked);
962 attr->atthasdef =
true;
971 if (
stmt->accessMethod != NULL)
973 Assert(RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE);
976 else if (RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE)
984 if (RELKIND_HAS_TABLE_AM(relkind) && !
OidIsValid(accessMethodId))
1005 stmt->relation->relpersistence,
1044 true,
true,
false, queryString);
1052 if (
stmt->partbound)
1069 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1071 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1072 errmsg(
"\"%s\" is not partitioned",
1110 NULL,
false,
false);
1165 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1166 errmsg(
"cannot partition using more than %d columns",
1178 partattrs, &partexprs, partopclass,
1179 partcollation,
stmt->partspec->strategy);
1183 partopclass, partcollation);
1196 if (
stmt->partbound)
1210 foreach(cell, idxlist)
1217 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1221 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1222 errmsg(
"cannot create foreign partition of partitioned table \"%s\"",
1224 errdetail(
"Table \"%s\" contains indexes that are unique.",
1238 attmap, &constraintOid);
1245 false,
false,
false,
false,
false);
1273 if (
stmt->constraints)
1275 true,
true,
false, queryString);
1285 foreach(listptr, nncols)
1325 has_not_null =
false;
1353 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1354 errmsg(
"too many array dimensions"));
1358 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1359 errmsg(
"column \"%s\" cannot be declared SETOF",
1363 atttypid, atttypmod, attdim);
1373 att->attinhcount = entry->
inhcount;
1374 att->attidentity = entry->
identity;
1378 att->attstorage = entry->
storage;
1392 constr->
check = NULL;
1419 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1425 (
errmsg(
"schema \"%s\" does not exist, skipping",
1433 if (rentry->
kind == rightkind)
1463 if (rentry->
kind == rightkind)
1468 if (wentry->
kind == wrongkind)
1473 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1504 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1505 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1508 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1509 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1522 relkind = RELKIND_RELATION;
1526 relkind = RELKIND_INDEX;
1530 relkind = RELKIND_SEQUENCE;
1534 relkind = RELKIND_VIEW;
1538 relkind = RELKIND_MATVIEW;
1542 relkind = RELKIND_FOREIGN_TABLE;
1546 elog(
ERROR,
"unrecognized drop object type: %d",
1575 state.expected_relkind = relkind;
1598 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1610 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1612 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1613 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1623 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1625 state.heap_lockmode,
1629 obj.
classId = RelationRelationId;
1657 bool invalid_system_index =
false;
1692 is_partition = classform->relispartition;
1695 state->actual_relkind = classform->relkind;
1696 state->actual_relpersistence = classform->relpersistence;
1706 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1708 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1715 state->expected_relkind);
1730 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1744 indisvalid = indexform->indisvalid;
1749 invalid_system_index =
true;
1755 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1756 errmsg(
"permission denied: \"%s\" is a system catalog",
1770 relOid != oldRelOid)
1783 if (is_partition && relOid != oldRelOid)
1817 foreach(cell,
stmt->relations)
1821 bool recurse = rv->
inh;
1847 relids_logged =
lappend_oid(relids_logged, myrelid);
1856 foreach(child, children)
1895 relids_logged =
lappend_oid(relids_logged, childrelid);
1898 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1900 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1901 errmsg(
"cannot truncate only a partitioned table"),
1902 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1906 stmt->behavior,
stmt->restart_seqs,
false);
1933 List *relids_logged,
1935 bool run_as_table_owner)
1939 HTAB *ft_htab = NULL;
1965 if (newrelids ==
NIL)
1968 foreach(cell, newrelids)
1975 (
errmsg(
"truncate cascades to table \"%s\"",
1985 relids_logged =
lappend_oid(relids_logged, relid);
1995 #ifdef USE_ASSERT_CHECKING
2016 foreach(seqcell, seqlist)
2050 resultRelInfo = resultRelInfos;
2071 resultRelInfo = resultRelInfos;
2076 if (run_as_table_owner)
2080 if (run_as_table_owner)
2095 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2105 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2116 memset(&hctl, 0,
sizeof(
HASHCTL));
2121 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2181 toast_relid = rel->
rd_rel->reltoastrelid;
2188 toastrel->
rd_rel->relpersistence);
2234 foreach(cell, seq_relids)
2248 if (relids_logged !=
NIL)
2257 foreach(cell, relids_logged)
2280 resultRelInfo = resultRelInfos;
2285 if (run_as_table_owner)
2289 if (run_as_table_owner)
2328 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2335 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2336 errmsg(
"cannot truncate foreign table \"%s\"",
2339 else if (reltuple->relkind != RELKIND_RELATION &&
2340 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2342 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2355 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2356 errmsg(
"permission denied: \"%s\" is a system catalog",
2392 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2393 errmsg(
"cannot truncate temporary tables of other sessions")));
2411 case TYPSTORAGE_PLAIN:
2413 case TYPSTORAGE_EXTERNAL:
2415 case TYPSTORAGE_EXTENDED:
2417 case TYPSTORAGE_MAIN:
2492 bool is_partition,
List **supconstr,
List **supnotnulls)
2497 bool have_bogus_defaults =
false;
2499 static Node bogus_marker = {0};
2516 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2517 errmsg(
"tables can have at most %d columns",
2534 for (
int coldefpos = 0; coldefpos <
list_length(columns); coldefpos++)
2538 if (!is_partition && coldef->
typeName == NULL)
2547 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2548 errmsg(
"column \"%s\" does not exist",
2553 for (
int restpos = coldefpos + 1; restpos <
list_length(columns);)
2573 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2574 errmsg(
"column \"%s\" specified more than once",
2589 saved_columns = columns;
2605 List *inherited_defaults;
2606 List *cols_with_defaults;
2628 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !is_partition)
2630 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2631 errmsg(
"cannot inherit from partitioned table \"%s\"",
2633 if (relation->
rd_rel->relispartition && !is_partition)
2635 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2636 errmsg(
"cannot inherit from partition \"%s\"",
2639 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2640 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2641 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2643 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2644 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2652 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2653 relpersistence == RELPERSISTENCE_TEMP)
2655 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2656 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2660 if (relpersistence != RELPERSISTENCE_TEMP &&
2661 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2663 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2665 ?
"cannot inherit from temporary relation \"%s\""
2666 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2670 if (relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
2673 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2675 ?
"cannot inherit from temporary relation of another session"
2676 :
"cannot create as partition of temporary relation of another session")));
2687 constr = tupleDesc->
constr;
2697 inherited_defaults = cols_with_defaults =
NIL;
2709 foreach(lc1, nnconstrs)
2718 char *attributeName =
NameStr(attribute->attname);
2726 if (attribute->attisdropped)
2733 attribute->atttypmod, attribute->attcollation);
2734 newdef->
storage = attribute->attstorage;
2735 newdef->
generated = attribute->attgenerated;
2746 newdef->
identity = attribute->attidentity;
2753 if (exist_attno > 0)
2760 newattmap->
attnums[parent_attno - 1] = exist_attno;
2775 inh_columns =
lappend(inh_columns, newdef);
2777 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2795 if (!is_partition &&
2813 nnconstraints =
lappend(nnconstraints, nn);
2819 if (attribute->atthasdef)
2824 if (this_default == NULL)
2825 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2834 inherited_defaults =
lappend(inherited_defaults, this_default);
2835 cols_with_defaults =
lappend(cols_with_defaults, mergeddef);
2843 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2847 bool found_whole_row;
2861 if (found_whole_row)
2863 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2864 errmsg(
"cannot convert whole-row table reference"),
2865 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2881 have_bogus_defaults =
true;
2898 bool found_whole_row;
2901 if (check[
i].ccnoinherit)
2915 if (found_whole_row)
2917 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2918 errmsg(
"cannot convert whole-row table reference"),
2919 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2931 foreach(lc1, nnconstrs)
2941 nnconstraints =
lappend(nnconstraints, nn);
2960 if (inh_columns !=
NIL)
2962 int newcol_attno = 0;
2964 foreach(lc, columns)
2967 char *attributeName = newdef->
colname;
2982 if (exist_attno > 0)
2994 inh_columns =
lappend(inh_columns, newdef);
2998 columns = inh_columns;
3006 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
3007 errmsg(
"tables can have at most %d columns",
3018 foreach(lc, saved_columns)
3043 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3044 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3048 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3049 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3056 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3057 errmsg(
"child column \"%s\" specifies generation expression",
3059 errhint(
"A child table column cannot be generated unless its parent column is.")));
3084 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3085 errmsg(
"column \"%s\" does not exist",
3094 if (have_bogus_defaults)
3096 foreach(lc, columns)
3104 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3105 errmsg(
"column \"%s\" inherits conflicting generation expressions",
3107 errhint(
"To resolve the conflict, specify a generation expression explicitly.")));
3110 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3111 errmsg(
"column \"%s\" inherits conflicting default values",
3113 errhint(
"To resolve the conflict, specify a default explicitly.")));
3118 *supconstr = constraints;
3119 *supnotnulls = nnconstraints;
3146 foreach(lc, constraints)
3162 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3163 errmsg(
"too many inheritance parents"));
3169 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3180 newcon->
expr = expr;
3182 return lappend(constraints, newcon);
3209 char *attributeName = newdef->
colname;
3218 if (exist_attno == newcol_attno)
3220 (
errmsg(
"merging column \"%s\" with inherited definition",
3224 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
3225 errdetail(
"User-specified column moved to the position of the inherited column.")));
3234 if (inhtypeid != newtypeid || inhtypmod != newtypmod)
3236 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3237 errmsg(
"column \"%s\" has a type conflict",
3248 if (inhcollid != newcollid)
3250 (
errcode(ERRCODE_COLLATION_MISMATCH),
3251 errmsg(
"column \"%s\" has a collation conflict",
3270 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3271 errmsg(
"column \"%s\" has a storage parameter conflict",
3286 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3287 errmsg(
"column \"%s\" has a compression method conflict",
3315 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3316 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3320 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3321 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3328 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3329 errmsg(
"child column \"%s\" specifies generation expression",
3331 errhint(
"A child table column cannot be generated unless its parent column is.")));
3372 char *attributeName = newdef->
colname;
3382 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
3391 if (prevtypeid != newtypeid || prevtypmod != newtypmod)
3393 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3394 errmsg(
"inherited column \"%s\" has a type conflict",
3405 if (prevcollid != newcollid)
3407 (
errcode(ERRCODE_COLLATION_MISMATCH),
3408 errmsg(
"inherited column \"%s\" has a collation conflict",
3421 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3422 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
3435 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3436 errmsg(
"column \"%s\" has a compression method conflict",
3445 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3446 errmsg(
"inherited column \"%s\" has a generation conflict",
3456 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3457 errmsg(
"too many inheritance parents"));
3470 bool child_is_partition)
3496 foreach(entry, supers)
3501 child_is_partition);
3515 bool child_is_partition)
3526 parentobject.
classId = RelationRelationId;
3529 childobject.
classId = RelationRelationId;
3563 foreach(lc, columns)
3600 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3603 if (classtuple->relhassubclass != relhassubclass)
3605 classtuple->relhassubclass = relhassubclass;
3631 Oid oldTableSpaceId;
3637 oldTableSpaceId = rel->
rd_rel->reltablespace;
3638 if (newTableSpaceId == oldTableSpaceId ||
3648 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3649 errmsg(
"cannot move system relation \"%s\"",
3653 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3655 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3656 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3664 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3665 errmsg(
"cannot move temporary tables of other sessions")));
3687 Oid newTableSpaceId,
3702 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3709 rd_rel->relfilenode = newRelFilenumber;
3716 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3718 rd_rel->reltablespace);
3730 char relkind = classform->relkind;
3732 if (classform->reloftype && !recursing)
3734 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3735 errmsg(
"cannot rename column of typed table")));
3744 if (relkind != RELKIND_RELATION &&
3745 relkind != RELKIND_VIEW &&
3746 relkind != RELKIND_MATVIEW &&
3747 relkind != RELKIND_COMPOSITE_TYPE &&
3748 relkind != RELKIND_INDEX &&
3749 relkind != RELKIND_PARTITIONED_INDEX &&
3750 relkind != RELKIND_FOREIGN_TABLE &&
3751 relkind != RELKIND_PARTITIONED_TABLE)
3753 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3754 errmsg(
"cannot rename columns of relation \"%s\"",
3766 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3767 errmsg(
"permission denied: \"%s\" is a system catalog",
3768 NameStr(classform->relname))));
3778 const char *oldattname,
3779 const char *newattname,
3782 int expected_parents,
3826 forboth(lo, child_oids, li, child_numparents)
3831 if (childrelid == myrelid)
3834 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3845 if (expected_parents == 0 &&
3848 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3849 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3854 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3863 foreach(lo, child_oids)
3872 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3873 errmsg(
"column \"%s\" does not exist",
3877 attnum = attform->attnum;
3880 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3881 errmsg(
"cannot rename system column \"%s\"",
3893 if (attform->attinhcount > expected_parents)
3895 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3896 errmsg(
"cannot rename inherited column \"%s\"",
3957 (
errmsg(
"relation \"%s\" does not exist, skipping",
3958 stmt->relation->relname)));
3966 stmt->relation->inh,
3982 const char *oldconname,
3983 const char *newconname,
3986 int expected_parents)
3994 Assert(!myrelid || !mytypid);
4015 elog(
ERROR,
"cache lookup failed for constraint %u",
4020 (con->contype == CONSTRAINT_CHECK ||
4021 con->contype == CONSTRAINT_NOTNULL) &&
4034 forboth(lo, child_oids, li, child_numparents)
4039 if (childrelid == myrelid)
4047 if (expected_parents == 0 &&
4050 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4051 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
4055 if (con->coninhcount > expected_parents)
4057 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4058 errmsg(
"cannot rename inherited constraint \"%s\"",
4063 && (con->contype == CONSTRAINT_PRIMARY
4064 || con->contype == CONSTRAINT_UNIQUE
4065 || con->contype == CONSTRAINT_EXCLUSION))
4103 elog(
ERROR,
"cache lookup failed for type %u", typid);
4118 (
errmsg(
"relation \"%s\" does not exist, skipping",
4119 stmt->relation->relname)));
4129 stmt->relation->inh),
4170 (
errmsg(
"relation \"%s\" does not exist, skipping",
4171 stmt->relation->relname)));
4182 obj_is_index = (relkind == RELKIND_INDEX ||
4183 relkind == RELKIND_PARTITIONED_INDEX);
4184 if (obj_is_index || is_index_stmt == obj_is_index)
4188 is_index_stmt = obj_is_index;
4231 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4236 (
errcode(ERRCODE_DUPLICATE_TABLE),
4237 errmsg(
"relation \"%s\" already exists",
4247 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4248 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
4269 newrelname, namespaceId);
4274 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4275 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
4306 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4348 int expected_refcnt;
4353 (
errcode(ERRCODE_OBJECT_IN_USE),
4355 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4358 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4359 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4362 (
errcode(ERRCODE_OBJECT_IN_USE),
4364 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4471 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4756 elog(
ERROR,
"unrecognized alter table type: %d",
4764 if (cmd_lockmode > lockmode)
4765 lockmode = cmd_lockmode;
4814 bool recurse,
bool recursing,
LOCKMODE lockmode,
4827 if (rel->
rd_rel->relispartition &&
4831 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4832 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4834 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
5037 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5038 errmsg(
"cannot change persistence setting twice")));
5052 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5053 errmsg(
"cannot change persistence setting twice")));
5073 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5074 errmsg(
"cannot have multiple SET ACCESS METHOD subcommands")));
5185 elog(
ERROR,
"unrecognized alter table type: %d",
5219 foreach(ltab, *wqueue)
5235 foreach(lcmd, subcmds)
5257 foreach(ltab, *wqueue)
5266 if (((tab->
relkind == RELKIND_RELATION ||
5267 tab->
relkind == RELKIND_PARTITIONED_TABLE) &&
5269 tab->
relkind == RELKIND_MATVIEW)
5319 cmd->
recurse,
false, NULL, lockmode);
5375 cmd->
recurse,
false, lockmode);
5380 true,
true, lockmode);
5440 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
5451 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
5452 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
5561 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
5573 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5585 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5593 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5598 elog(
ERROR,
"unrecognized alter table type: %d",
5658 foreach(lc, beforeStmts)
5667 foreach(lc, atstmt->
cmds)
5729 if (pass < cur_pass)
5732 elog(
ERROR,
"ALTER TABLE scheduling failure: too late for pass %d",
5735 else if (pass > cur_pass)
5752 elog(
ERROR,
"ALTER TABLE scheduling failure: bogus item for pass %d",
5773 foreach(ltab, *wqueue)
5778 if (!RELKIND_HAS_STORAGE(tab->
relkind))
5819 Oid NewAccessMethod;
5832 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5833 errmsg(
"cannot rewrite system relation \"%s\"",
5838 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5839 errmsg(
"cannot rewrite table \"%s\" used as a catalog table",
5848 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5849 errmsg(
"cannot rewrite temporary tables of other sessions")));
5858 NewTableSpace = OldHeap->
rd_rel->reltablespace;
5867 NewAccessMethod = OldHeap->
rd_rel->relam;
5910 persistence, lockmode);
5969 foreach(lc, seqlist)
5985 foreach(ltab, *wqueue)
5992 if (!RELKIND_HAS_STORAGE(tab->
relkind))
6031 foreach(ltab, *wqueue)
6058 bool needscan =
false;
6059 List *notnull_attrs;
6120 elog(
ERROR,
"unrecognized constraint type: %d",
6140 notnull_attrs =
NIL;
6149 for (
i = 0;
i < newTupDesc->
natts;
i++)
6153 if (attr->attnotnull && !attr->attisdropped)
6160 if (newrel || needscan)
6230 for (
i = 0;
i < newTupDesc->
natts;
i++)
6266 foreach(lc, dropped_attrs)
6320 insertslot = newslot;
6329 insertslot = oldslot;
6335 foreach(l, notnull_attrs)
6344 (
errcode(ERRCODE_NOT_NULL_VIOLATION),
6345 errmsg(
"column \"%s\" of relation \"%s\" contains null values",
6361 (
errcode(ERRCODE_CHECK_VIOLATION),
6362 errmsg(
"check constraint \"%s\" of relation \"%s\" is violated by some row",
6372 elog(
ERROR,
"unrecognized constraint type: %d",
6377 if (partqualstate && !
ExecCheck(partqualstate, econtext))
6381 (
errcode(ERRCODE_CHECK_VIOLATION),
6382 errmsg(
"updated partition constraint for default partition \"%s\" would be violated by some row",
6387 (
errcode(ERRCODE_CHECK_VIOLATION),
6388 errmsg(
"partition constraint of relation \"%s\" is violated by some row",
6396 ti_options, bistate);
6435 foreach(ltab, *wqueue)
6438 if (tab->
relid == relid)
6457 *wqueue =
lappend(*wqueue, tab);
6469 return "ADD COLUMN";
6472 return "ALTER COLUMN ... SET DEFAULT";
6474 return "ALTER COLUMN ... DROP NOT NULL";
6476 return "ALTER COLUMN ... SET NOT NULL";
6480 return "ALTER COLUMN ... SET EXPRESSION";
6482 return "ALTER COLUMN ... DROP EXPRESSION";
6484 return "ALTER COLUMN ... SET STATISTICS";
6486 return "ALTER COLUMN ... SET";
6488 return "ALTER COLUMN ... RESET";
6490 return "ALTER COLUMN ... SET STORAGE";
6492 return "ALTER COLUMN ... SET COMPRESSION";
6494 return "DROP COLUMN";
6502 return "ADD CONSTRAINT";
6504 return "ALTER CONSTRAINT";
6506 return "VALIDATE CONSTRAINT";
6508 return "DROP CONSTRAINT";
6512 return "ALTER COLUMN ... SET DATA TYPE";
6514 return "ALTER COLUMN ... OPTIONS";
6518 return "CLUSTER ON";
6520 return "SET WITHOUT CLUSTER";
6522 return "SET ACCESS METHOD";
6524 return "SET LOGGED";
6526 return "SET UNLOGGED";
6528 return "SET WITHOUT OIDS";
6530 return "SET TABLESPACE";
6538 return "ENABLE TRIGGER";
6540 return "ENABLE ALWAYS TRIGGER";
6542 return "ENABLE REPLICA TRIGGER";
6544 return "DISABLE TRIGGER";
6546 return "ENABLE TRIGGER ALL";
6548 return "DISABLE TRIGGER ALL";
6550 return "ENABLE TRIGGER USER";
6552 return "DISABLE TRIGGER USER";
6554 return "ENABLE RULE";
6556 return "ENABLE ALWAYS RULE";
6558 return "ENABLE REPLICA RULE";
6560 return "DISABLE RULE";
6564 return "NO INHERIT";
6570 return "REPLICA IDENTITY";
6572 return "ENABLE ROW SECURITY";
6574 return "DISABLE ROW SECURITY";
6576 return "FORCE ROW SECURITY";
6578 return "NO FORCE ROW SECURITY";
6582 return "ATTACH PARTITION";
6584 return "DETACH PARTITION";
6586 return "DETACH PARTITION ... FINALIZE";
6588 return "SPLIT PARTITION";
6590 return "MERGE PARTITIONS";
6592 return "ALTER COLUMN ... ADD IDENTITY";
6594 return "ALTER COLUMN ... SET";
6596 return "ALTER COLUMN ... DROP IDENTITY";
6616 switch (rel->
rd_rel->relkind)
6618 case RELKIND_RELATION:
6619 case RELKIND_PARTITIONED_TABLE:
6625 case RELKIND_MATVIEW:
6631 case RELKIND_PARTITIONED_INDEX:
6634 case RELKIND_COMPOSITE_TYPE:
6637 case RELKIND_FOREIGN_TABLE:
6640 case RELKIND_SEQUENCE:
6649 if ((actual_target & allowed_targets) == 0)
6655 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6657 errmsg(
"ALTER action %s cannot be performed on relation \"%s\"",
6662 elog(
ERROR,
"invalid ALTER action attempted on relation \"%s\"",
6673 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6674 errmsg(
"permission denied: \"%s\" is a system catalog",
6695 if (recurse && rel->
rd_rel->relhassubclass)
6708 foreach(child, children)
6713 if (childrelid == relid)
6734 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
6768 Assert(rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
6774 foreach(child, children)
6808 const char *origTypeName)
6825 Anum_pg_depend_refclassid,
6829 Anum_pg_depend_refobjid,
6844 if (pg_depend->classid == TypeRelationId)
6853 origRelation, origTypeName);
6858 if (pg_depend->classid != RelationRelationId)
6877 if (pg_depend->objsubid > 0 && pg_depend->objsubid <= tupleDesc->
natts)
6882 for (
int attno = 1; attno <= tupleDesc->
natts; attno++)
6885 if (att->atttypid == typeOid && !att->attisdropped)
6906 if (RELKIND_HAS_STORAGE(rel->
rd_rel->relkind) ||
6907 RELKIND_HAS_PARTITIONS(rel->
rd_rel->relkind))
6911 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6912 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
6916 else if (origRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
6918 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6919 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
6923 else if (origRelation->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
6925 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6926 errmsg(
"cannot alter foreign table \"%s\" because column \"%s.%s\" uses its row type",
6932 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6933 errmsg(
"cannot alter table \"%s\" because column \"%s.%s\" uses its row type",
6945 origRelation, origTypeName);
6976 Anum_pg_class_reloftype,
6988 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
6989 errmsg(
"cannot alter type \"%s\" because it is the type of a typed table",
6991 errhint(
"Use ALTER ... CASCADE to alter the typed tables too.")));
7017 bool typeOk =
false;
7019 if (typ->typtype == TYPTYPE_COMPOSITE)
7025 typeOk = (typeRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
7036 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7037 errmsg(
"type %s is not a composite type",
7061 if (rel->
rd_rel->reloftype && !recursing)
7063 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7064 errmsg(
"cannot add column to typed table")));
7066 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
7069 if (recurse && !is_view)
7088 bool if_not_exists = (*cmd)->missing_ok;
7109 if (rel->
rd_rel->relispartition && !recursing)
7111 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7112 errmsg(
"cannot add column to a partition")));
7137 if (ctypeId != childatt->atttypid ||
7138 ctypmod != childatt->atttypmod)
7140 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7141 errmsg(
"child table \"%s\" has different type for column \"%s\"",
7144 if (ccollid != childatt->attcollation)
7146 (
errcode(ERRCODE_COLLATION_MISMATCH),
7147 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
7154 childatt->attinhcount++;
7155 if (childatt->attinhcount < 0)
7157 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
7158 errmsg(
"too many inheritance parents"));
7165 (
errmsg(
"merging definition of column \"%s\" for child \"%s\"",
7195 if (
context != NULL && !recursing)
7214 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE &&
7217 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7218 errmsg(
"cannot recursively add identity column to table that has child tables")));
7224 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
7231 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
7232 errmsg(
"tables can have at most %d columns",
7243 attribute->attnum = newattnum;
7279 rawEnt->
attnum = attribute->attnum;
7296 false,
true,
false, NULL);
7342 if (RELKIND_HAS_STORAGE(relkind))
7353 nve->
typeId = attribute->atttypid;
7355 defval = (
Expr *) nve;
7369 baseTypeMod = attribute->atttypmod;
7376 attribute->atttypid,
7377 attribute->atttypmod,
7382 elog(
ERROR,
"failed to coerce base type to domain");
7390 newval->attnum = attribute->attnum;
7428 if (children && !recurse)
7430 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7431 errmsg(
"column must be added to child tables too")));
7444 foreach(child, children)
7459 &childcmd, recurse,
true,
7500 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7501 errmsg(
"column name \"%s\" conflicts with a system column name",
7508 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7509 errmsg(
"column \"%s\" of relation \"%s\" already exists, skipping",
7515 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7516 errmsg(
"column \"%s\" of relation \"%s\" already exists",
7532 myself.
classId = RelationRelationId;
7535 referenced.
classId = TypeRelationId;
7553 myself.
classId = RelationRelationId;
7556 referenced.
classId = CollationRelationId;
7589 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7590 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7598 if (!attTup->attnotnull)
7607 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7608 errmsg(
"cannot alter system column \"%s\"",
7611 if (attTup->attidentity)
7613 (
errcode(ERRCODE_SYNTAX_ERROR),
7614 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
7623 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
7629 if (partdesc->
nparts > 0)
7631 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7632 errmsg(
"cannot remove constraint from only the partitioned table when partitions exist"),
7633 errhint(
"Do not specify the ONLY keyword."));
7635 else if (rel->
rd_rel->relhassubclass &&
7639 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7640 errmsg(
"not-null constraint on column \"%s\" must be removed in child tables too",
7642 errhint(
"Do not specify the ONLY keyword."));
7649 if (rel->
rd_rel->relispartition)
7656 parent_attnum =
get_attnum(parentId, colName);
7659 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7660 errmsg(
"column \"%s\" is marked NOT NULL in parent table",
7688 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7689 errmsg(
"column \"%s\" is in a primary key", colName));
7695 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7696 errmsg(
"column \"%s\" is in index used as replica identity",
7700 attTup->attnotnull =
false;
7708 false, &readyRels, lockmode);
7737 bool retval =
false;
7744 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
7747 if (!attForm->attnotnull)
7753 attForm->attnotnull =
true;
7783 foreach(lc, children)
7817 bool recurse,
bool recursing,
List **readyRels,
7829 bool is_no_inherit =
false;
7840 if (readyRels == NULL)
7859 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7860 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7866 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7867 errmsg(
"cannot alter system column \"%s\"",
7873 Anum_pg_constraint_conrelid,
7882 bool changed =
false;
7885 if (conForm->contype != CONSTRAINT_NOTNULL)
7901 conForm->coninhcount++;
7904 else if (!conForm->conislocal)
7906 conForm->conislocal =
true;
7937 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
7939 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7940 errmsg(
"constraint must be added to child tables too"),
7941 errhint(
"Do not specify the ONLY keyword."));
7943 is_no_inherit =
true;
7954 colName,
"not_null",
7960 constraint->
conname = conName;
7966 constraint->
inhcount = recursing ? 1 : 0;
7972 false, !recursing,
false, NULL);
7996 foreach(lc, children)
8003 conName, colName, recurse,
true,
8004 readyRels, lockmode);
8021 const char *colName,
LOCKMODE lockmode)
8029 errcode(ERRCODE_UNDEFINED_COLUMN),
8030 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8066 nnulltest->argisrow =
false;
8072 (
errmsg_internal(
"existing constraints on column \"%s.%s\" are sufficient to prove that it does not contain nulls",
8099 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8100 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8106 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8107 errmsg(
"cannot alter system column \"%s\"",
8112 (
errcode(ERRCODE_SYNTAX_ERROR),
8113 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
8116 newDefault ? 0 :
errhint(
"Use %s instead.",
8117 "ALTER TABLE ... ALTER COLUMN ... DROP IDENTITY")));
8121 (
errcode(ERRCODE_SYNTAX_ERROR),
8122 errmsg(
"column \"%s\" of relation \"%s\" is a generated column",
8126 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... SET EXPRESSION") :
8128 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... DROP EXPRESSION") : 0)));
8140 newDefault != NULL);
8158 false,
true,
false, NULL);
8202 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing)
8212 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8213 if (ispartitioned && !recurse)
8215 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8216 errmsg(
"cannot add identity to a column of only the partitioned table"),
8217 errhint(
"Do not specify the ONLY keyword.")));
8219 if (rel->
rd_rel->relispartition && !recursing)
8221 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8222 errmsg(
"cannot add identity to a column of a partition"));
8229 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8230 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8238 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8239 errmsg(
"cannot alter system column \"%s\"",
8247 if (!attTup->attnotnull)
8249 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8250 errmsg(
"column \"%s\" of relation \"%s\" must be declared NOT NULL before identity can be added",
8253 if (attTup->attidentity)
8255 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8256 errmsg(
"column \"%s\" of relation \"%s\" is already an identity column",
8259 if (attTup->atthasdef)
8261 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8262 errmsg(
"column \"%s\" of relation \"%s\" already has a default value",
8265 attTup->attidentity = cdef->
identity;
8281 if (recurse && ispartitioned)
8288 foreach(lc, children)
8308 LOCKMODE lockmode,
bool recurse,
bool recursing)
8319 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8320 if (ispartitioned && !recurse)
8322 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8323 errmsg(
"cannot change identity column of only the partitioned table"),
8324 errhint(
"Do not specify the ONLY keyword.")));
8326 if (rel->
rd_rel->relispartition && !recursing)
8328 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8329 errmsg(
"cannot change identity column of a partition"));
8335 if (strcmp(defel->
defname,
"generated") == 0)
8339 (
errcode(ERRCODE_SYNTAX_ERROR),
8340 errmsg(
"conflicting or redundant options")));
8341 generatedEl = defel;
8344 elog(
ERROR,
"option \"%s\" not recognized",
8358 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8359 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8367 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8368 errmsg(
"cannot alter system column \"%s\"",
8371 if (!attTup->attidentity)
8373 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8374 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8398 if (generatedEl && recurse && ispartitioned)
8405 foreach(lc, children)
8425 bool recurse,
bool recursing)
8436 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8437 if (ispartitioned && !recurse)
8439 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8440 errmsg(
"cannot drop identity from a column of only the partitioned table"),
8441 errhint(
"Do not specify the ONLY keyword.")));
8443 if (rel->
rd_rel->relispartition && !recursing)
8445 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8446 errmsg(
"cannot drop identity from a column of a partition"));
8452 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8453 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8461 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8462 errmsg(
"cannot alter system column \"%s\"",
8465 if (!attTup->attidentity)
8469 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8470 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8475 (
errmsg(
"column \"%s\" of relation \"%s\" is not an identity column, skipping",
8483 attTup->attidentity =
'\0';
8499 if (recurse && ispartitioned)
8506 foreach(lc, children)
8523 seqaddress.
classId = RelationRelationId;
8553 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8554 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8562 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8563 errmsg(
"cannot alter system column \"%s\"",
8566 if (attTup->attgenerated != ATTRIBUTE_GENERATED_STORED)
8568 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8569 errmsg(
"column \"%s\" of relation \"%s\" is not a generated column",
8596 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8616 rawEnt->
generated = ATTRIBUTE_GENERATED_STORED;
8620 false,
true,
false, NULL);
8631 newval->is_generated =
true;
8666 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8667 errmsg(
"ALTER TABLE / DROP EXPRESSION must be applied to child tables too")));
8680 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8681 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8686 if (attTup->attinhcount > 0)
8688 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8689 errmsg(
"cannot drop generation expression from inherited column")));
8710 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8711 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8719 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8720 errmsg(
"cannot alter system column \"%s\"",
8723 if (attTup->attgenerated != ATTRIBUTE_GENERATED_STORED)
8727 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8728 errmsg(
"column \"%s\" of relation \"%s\" is not a stored generated column",
8733 (
errmsg(
"column \"%s\" of relation \"%s\" is not a stored generated column, skipping",
8745 attTup->attgenerated =
'\0';
8762 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8791 bool newtarget_default;
8798 Datum repl_val[Natts_pg_attribute];
8799 bool repl_null[Natts_pg_attribute];
8800 bool repl_repl[Natts_pg_attribute];
8806 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
8807 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
8810 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8811 errmsg(
"cannot refer to non-index column by number")));
8814 if (newValue &&
intVal(newValue) != -1)
8816 newtarget =
intVal(newValue);
8817 newtarget_default =
false;
8820 newtarget_default =
true;
8822 if (!newtarget_default)
8830 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8831 errmsg(
"statistics target %d is too low",
8838 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8839 errmsg(
"lowering statistics target to %d",
8852 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8853 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8862 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8863 errmsg(
"column number %d of relation \"%s\" does not exist",
8869 attnum = attrtuple->attnum;
8872 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8873 errmsg(
"cannot alter system column \"%s\"",
8876 if (rel->
rd_rel->relkind == RELKIND_INDEX ||
8877 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
8881 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8882 errmsg(
"cannot alter statistics on included column \"%s\" of index \"%s\"",
8886 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8887 errmsg(
"cannot alter statistics on non-expression column \"%s\" of index \"%s\"",
8889 errhint(
"Alter statistics on table column instead.")));
8893 memset(repl_null,
false,
sizeof(repl_null));
8894 memset(repl_repl,
false,
sizeof(repl_repl));
8895 if (!newtarget_default)
8896 repl_val[Anum_pg_attribute_attstattarget - 1] = newtarget;
8898 repl_null[Anum_pg_attribute_attstattarget - 1] =
true;
8899 repl_repl[Anum_pg_attribute_attstattarget - 1] =
true;
8901 repl_val, repl_null, repl_repl);
8935 Datum repl_val[Natts_pg_attribute];
8936 bool repl_null[Natts_pg_attribute];
8937 bool repl_repl[Natts_pg_attribute];
8945 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8946 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8950 attnum = attrtuple->attnum;
8953 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8954 errmsg(
"cannot alter system column \"%s\"",
8967 memset(repl_null,
false,
sizeof(repl_null));
8968 memset(repl_repl,
false,
sizeof(repl_repl));
8969 if (newOptions != (
Datum) 0)
8970 repl_val[Anum_pg_attribute_attoptions - 1] = newOptions;
8972 repl_null[Anum_pg_attribute_attoptions - 1] =
true;
8973 repl_repl[Anum_pg_attribute_attoptions - 1] =
true;
8975 repl_val, repl_null, repl_repl);
9004 bool setstorage,
char newstorage,
9005 bool setcompression,
char newcompression,
9019 for (
int i = 0;
i < indrel->
rd_index->indnatts;
i++)
9041 attrtuple->attstorage = newstorage;
9044 attrtuple->attcompression = newcompression;
9079 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9080 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9084 attnum = attrtuple->attnum;
9087 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9088 errmsg(
"cannot alter system column \"%s\"",
9104 true, attrtuple->attstorage,
9132 if (rel->
rd_rel->reloftype && !recursing)
9134 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9135 errmsg(
"cannot drop column from typed table")));
9137 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
9158 bool recurse,
bool recursing,
9159 bool missing_ok,
LOCKMODE lockmode,
9174 Assert(!recursing || addrs != NULL);
9191 (
errcode(ERRCODE_UNDEFINED_COLUMN),
9192 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
9198 (
errmsg(
"column \"%s\" of relation \"%s\" does not exist, skipping",
9205 attnum = targetatt->attnum;
9210 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9211 errmsg(
"cannot drop system column \"%s\"",
9218 if (targetatt->attinhcount > 0 && !recursing)
9220 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9221 errmsg(
"cannot drop inherited column \"%s\"",
9233 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9234 errmsg(
"cannot drop column \"%s\" because it is part of the partition key of relation \"%s\"",
9256 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !recurse)
9258 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9259 errmsg(
"cannot drop column from only the partitioned table when partitions exist"),
9260 errhint(
"Do not specify the ONLY keyword.")));
9263 foreach(child, children)
9275 elog(
ERROR,
"cache lookup failed for attribute \"%s\" of relation %u",
9276 colName, childrelid);
9279 if (childatt->attinhcount <= 0)
9280 elog(
ERROR,
"relation %u has non-inherited attribute \"%s\"",
9281 childrelid, colName);
9290 if (childatt->attinhcount == 1 && !childatt->attislocal)
9294 behavior,
true,
true,
9295 false, lockmode, addrs);
9300 childatt->attinhcount--;
9315 childatt->attinhcount--;
9316 childatt->attislocal =
true;
9332 object.classId = RelationRelationId;
9334 object.objectSubId =
attnum;
9367 if (rel->
rd_rel->relkind != RELKIND_RELATION ||
9368 !rel->
rd_rel->relhassubclass)
9386 Assert(elem->expr == NULL);
9399 newconstrs =
lappend(newconstrs, nnconstr);
9413 foreach(lc2, newconstrs)
9419 true,
false, lockmode,
context);
9451 check_rights = !is_rebuild;
9523 Oid index_oid =
stmt->indexOid;
9527 char *constraintName;
9528 char constraintType;
9540 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
9542 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9543 errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables")));
9553 elog(
ERROR,
"index \"%s\" is not unique", indexName);
9562 constraintName =
stmt->idxname;
9563 if (constraintName == NULL)
9564 constraintName = indexName;
9565 else if (strcmp(constraintName, indexName) != 0)
9568 (
errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index \"%s\" to \"%s\"",
9569 indexName, constraintName)));
9579 constraintType = CONSTRAINT_PRIMARY;
9581 constraintType = CONSTRAINT_UNIQUE;
9613 Constraint *newConstraint,
bool recurse,
bool is_readd,
9625 switch (newConstraint->
contype)
9631 newConstraint, recurse,
false, is_readd,
9647 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
9666 elog(
ERROR,
"unrecognized constraint type: %d",
9667 (
int) newConstraint->
contype);
9693 foreach(lc, colnames)
9698 buf[buflen++] =
'_';
9705 buflen += strlen(
buf + buflen);
9729 Constraint *constr,
bool recurse,
bool recursing,
9757 recursing || is_readd,
9767 foreach(lcon, newcons)
9832 if (!recurse && children !=
NIL)
9834 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9835 errmsg(
"constraint must be added to child tables too")));
9843 foreach(child, children)
9862 constr, recurse,
true, is_readd, lockmode);
9888 bool recurse,
bool recursing,
LOCKMODE lockmode)
9901 bool pk_has_without_overlaps;
9924 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
9928 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9929 errmsg(
"cannot use ONLY for foreign key on partitioned table \"%s\" referencing relation \"%s\"",
9934 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9935 errmsg(
"cannot add NOT VALID foreign key on partitioned table \"%s\" referencing relation \"%s\"",
9938 errdetail(
"This feature is not yet supported on partitioned tables.")));
9941 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
9942 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
9944 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9945 errmsg(
"referenced relation \"%s\" is not a table",
9950 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9951 errmsg(
"permission denied: \"%s\" is a system catalog",
9962 switch (rel->
rd_rel->relpersistence)
9964 case RELPERSISTENCE_PERMANENT:
9967 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9968 errmsg(
"constraints on permanent tables may reference only permanent tables")));
9970 case RELPERSISTENCE_UNLOGGED:
9972 && pkrel->
rd_rel->relpersistence != RELPERSISTENCE_UNLOGGED)
9974 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9975 errmsg(
"constraints on unlogged tables may reference only permanent or unlogged tables")));
9977 case RELPERSISTENCE_TEMP:
9978 if (pkrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
9980 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9981 errmsg(
"constraints on temporary tables may reference only temporary tables")));
9984 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9985 errmsg(
"constraints on temporary tables must involve temporary tables of this session")));
9995 fkattnum, fktypoid);
9999 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10000 errmsg(
"foreign key uses PERIOD on the referenced table but not the referencing table"));
10004 fkdelsetcols, NULL);
10006 numfkdelsetcols, fkdelsetcols,
10019 pkattnum, pktypoid,
10020 opclasses, &pk_has_without_overlaps);
10025 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10026 errmsg(
"foreign key uses PERIOD on the referenced table but not the referencing table"));
10032 pkattnum, pktypoid);
10037 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10038 errmsg(
"foreign key uses PERIOD on the referencing table but not the referenced table"));
10042 with_period, opclasses, &pk_has_without_overlaps);
10049 if (pk_has_without_overlaps && !with_period)
10051 errcode(ERRCODE_INVALID_FOREIGN_KEY),
10052 errmsg(
"foreign key must use PERIOD when referencing a primary using WITHOUT OVERLAPS"));
10062 for (
i = 0;
i < numfks;
i++)
10075 (
errcode(ERRCODE_SYNTAX_ERROR),
10076 errmsg(
"invalid %s action for foreign key constraint containing generated column",
10081 (
errcode(ERRCODE_SYNTAX_ERROR),
10082 errmsg(
"invalid %s action for foreign key constraint containing generated column",
10096 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10097 errmsg(
"unsupported %s action for foreign key constraint using PERIOD",
10104 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10105 errmsg(
"unsupported %s action for foreign key constraint using PERIOD",
10117 if (numfks != numpks)
10119 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
10120 errmsg(
"number of referencing and referenced columns for foreign key disagree")));
10129 for (
i = 0;
i < numpks;
i++)
10131 Oid pktype = pktypoid[
i];
10132 Oid fktype = fktypoid[
i];
10148 elog(
ERROR,
"cache lookup failed for opclass %u", opclasses[
i]);
10150 amid = cla_tup->opcmethod;
10151 opfamily = cla_tup->opcfamily;
10152 opcintype = cla_tup->opcintype;
10158 bool for_overlaps = with_period &&
i == numpks - 1;
10164 if (amid != GIST_AM_OID)
10165 elog(
ERROR,
"only GiST indexes are supported for temporal foreign keys");
10181 elog(
ERROR,
"cache lookup failed for operator class %u", opclasses[
i]);
10184 errcode(ERRCODE_UNDEFINED_OBJECT),
10186 ?
errmsg(
"could not identify an overlaps operator for foreign key")
10187 :
errmsg(
"could not identify an equality operator for foreign key"),
10188 errdetail(
"Could not translate strategy number %d for operator class \"%s\" for access method \"%s\".",
10201 if (amid != BTREE_AM_OID)
10202 elog(
ERROR,
"only b-tree indexes are supported for foreign keys");
10214 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
10215 eqstrategy, opcintype, opcintype, opfamily);
10227 pfeqop_right = fktyped;
10249 Oid input_typeids[2];
10250 Oid target_typeids[2];
10252 input_typeids[0] = pktype;
10253 input_typeids[1] = fktype;
10254 target_typeids[0] = opcintype;
10255 target_typeids[1] = opcintype;
10259 pfeqop = ffeqop = ppeqop;
10260 pfeqop_right = opcintype;
10266 (
errcode(ERRCODE_DATATYPE_MISMATCH),
10267 errmsg(
"foreign key constraint \"%s\" cannot be implemented",
10269 errdetail(
"Key columns \"%s\" and \"%s\" "
10270 "are of incompatible types: %s and %s.",
10284 old_check_ok = (pfeqop ==
lfirst_oid(old_pfeqop_item));
10304 old_fktype = attr->atttypid;
10305 new_fktype = fktype;
10343 old_check_ok = (new_pathtype == old_pathtype &&
10344 new_castfunc == old_castfunc &&
10345 (!IsPolymorphicType(pfeqop_right) ||
10346 new_fktype == old_fktype));
10349 pfeqoperators[
i] = pfeqop;
10350 ppeqoperators[
i] = ppeqop;
10351 ffeqoperators[
i] = ffeqop;
10365 Oid aggedperiodoperoid;
10421 int numfksetcols,
const int16 *fksetcolsattnums,
10424 for (
int i = 0;
i < numfksetcols;
i++)
10426 int16 setcol_attnum = fksetcolsattnums[
i];
10429 for (
int j = 0;
j < numfks;
j++)
10431 if (fkattnums[
j] == setcol_attnum)
10443 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
10444 errmsg(
"column \"%s\" referenced in ON DELETE SET action must be part of foreign key", col)));
10486 Oid *ppeqoperators,
Oid *ffeqoperators,
10487 int numfkdelsetcols,
int16 *fkdelsetcols,
10489 Oid parentDelTrigger,
Oid parentUpdTrigger,
10498 Oid deleteTriggerOid,
10505 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
10506 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
10508 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10509 errmsg(
"referenced relation \"%s\" is not a table",
10524 conname = fkconstraint->
conname;
10528 conislocal =
false;
10530 connoinherit =
false;
10540 connoinherit = rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE;
10548 CONSTRAINT_FOREIGN,
10603 constrOid, indexOid,
10604 parentDelTrigger, parentUpdTrigger,
10605 &deleteTriggerOid, &updateTriggerOid);
10612 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10635 for (
int j = 0;
j < numfks;
j++)
10636 mapped_pkattnum[
j] = map->
attnums[pkattnum[
j] - 1];
10639 mapped_pkattnum = pkattnum;
10644 elog(
ERROR,
"index for %u not found in partition %s",
10647 partIndexId, constrOid, numfks,
10648 mapped_pkattnum, fkattnum,
10649 pfeqoperators, ppeqoperators, ffeqoperators,
10650 numfkdelsetcols, fkdelsetcols,
10652 deleteTriggerOid, updateTriggerOid,
10659 pfree(mapped_pkattnum);
10707 int numfks,
int16 *pkattnum,
int16 *fkattnum,
10708 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
10709 int numfkdelsetcols,
int16 *fkdelsetcols,
10710 bool old_check_ok,
LOCKMODE lockmode,
10711 Oid parentInsTrigger,
Oid parentUpdTrigger,
10714 Oid insertTriggerOid,
10719 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
10721 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10722 errmsg(
"foreign key constraints are not supported on foreign tables")));
10735 parentInsTrigger, parentUpdTrigger,
10736 &insertTriggerOid, &updateTriggerOid);
10738 if (rel->
rd_rel->relkind == RELKIND_RELATION)
10759 newcon->
conid = parentConstr;
10761 newcon->
qual = (
Node *) fkconstraint;
10766 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10803 for (
int j = 0;
j < numfks;
j++)
10804 mapped_fkattnum[
j] = attmap->
attnums[fkattnum[
j] - 1];
10809 foreach(cell, partFKs)
10846 conname = fkconstraint->
conname;
10850 CONSTRAINT_FOREIGN,
10937 Assert(parentRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
11014 foreach(cell, clone)
11028 int numfkdelsetcols;
11031 Oid deleteTriggerOid,
11036 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
11068 indexOid = constrForm->conindid;
11079 for (
int i = 0;
i < numfks;
i++)
11080 mapped_confkey[
i] = attmap->
attnums[confkey[
i] - 1];
11083 fkconstraint->
contype = CONSTRAINT_FOREIGN;
11085 fkconstraint->
deferrable = constrForm->condeferrable;
11088 fkconstraint->
pktable = NULL;
11091 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
11101 for (
int i = 0;
i < numfks;
i++)
11118 elog(
ERROR,
"index for %u not found in partition %s",
11127 constrForm->confrelid, constrForm->conrelid,
11128 &deleteTriggerOid, &updateTriggerOid);
11147 constrForm->conperiod);
11193 if (partRel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
11195 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11196 errmsg(
"foreign key constraints are not supported on foreign tables")));
11216 foreach(cell, clone)
11229 int numfkdelsetcols;
11238 Oid insertTriggerOid,
11244 elog(
ERROR,
"cache lookup failed for constraint %u",
11260 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11265 conpfeqop, conppeqop, conffeqop,
11266 &numfkdelsetcols, confdelsetcols);
11267 for (
int i = 0;
i < numfks;
i++)
11268 mapped_conkey[
i] = attmap->
attnums[conkey[
i] - 1];
11280 constrForm->confrelid, constrForm->conrelid,
11281 &insertTriggerOid, &updateTriggerOid);
11291 foreach(lc, partFKs)
11319 fkconstraint->
contype = CONSTRAINT_FOREIGN;
11321 fkconstraint->
deferrable = constrForm->condeferrable;
11324 fkconstraint->
pktable = NULL;
11327 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
11335 for (
int i = 0;
i < numfks;
i++)
11340 mapped_conkey[
i] - 1);
11346 NameStr(constrForm->conname)))
11355 indexOid = constrForm->conindid;
11356 with_period = constrForm->conperiod;
11359 constrForm->connamespace,
11360 CONSTRAINT_FOREIGN,
11363 constrForm->convalidated,
11371 constrForm->confrelid,
11444 Oid parentConstrOid,
11449 Oid parentInsTrigger,
11450 Oid parentUpdTrigger,
11460 Oid insertTriggerOid,
11466 elog(
ERROR,
"cache lookup failed for constraint %u", parentConstrOid);
11473 if (fk->
confrelid != parentConstr->confrelid || fk->
nkeys != numfks)
11478 for (
int i = 0;
i < numfks;
i++)
11480 if (fk->conkey[
i] != mapped_conkey[
i] ||
11481 fk->confkey[
i] != confkey[
i] ||
11482 fk->conpfeqop[
i] != conpfeqop[
i])
11500 !partConstr->convalidated ||
11501 partConstr->condeferrable != parentConstr->condeferrable ||
11502 partConstr->condeferred != parentConstr->condeferred ||
11503 partConstr->confupdtype != parentConstr->confupdtype ||
11504 partConstr->confdeltype != parentConstr->confdeltype ||
11505 partConstr->confmatchtype != parentConstr->confmatchtype)
11523 Anum_pg_trigger_tgconstraint,
11533 if (trgform->tgconstrrelid != fk->
conrelid)
11567 &insertTriggerOid, &updateTriggerOid);
11586 Oid conoid,
Oid confrelid,
Oid conrelid,
11587 Oid *deleteTriggerOid,
11588 Oid *updateTriggerOid)
11594 *deleteTriggerOid = *updateTriggerOid =
InvalidOid;
11596 Anum_pg_trigger_tgconstraint,
11606 if (trgform->tgconstrrelid != conrelid)
11608 if (trgform->tgrelid != confrelid)
11613 if (TRIGGER_FOR_DELETE(trgform->tgtype))
11616 *deleteTriggerOid = trgform->oid;
11618 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
11621 *updateTriggerOid = trgform->oid;
11623 #ifndef USE_ASSERT_CHECKING
11631 elog(
ERROR,
"could not find ON DELETE action trigger of foreign key constraint %u",
11634 elog(
ERROR,
"could not find ON UPDATE action trigger of foreign key constraint %u",
11647 Oid conoid,
Oid confrelid,
Oid conrelid,
11648 Oid *insertTriggerOid,
11649 Oid *updateTriggerOid)
11655 *insertTriggerOid = *updateTriggerOid =
InvalidOid;
11657 Anum_pg_trigger_tgconstraint,
11667 if (trgform->tgconstrrelid != confrelid)
11669 if (trgform->tgrelid != conrelid)
11674 if (TRIGGER_FOR_INSERT(trgform->tgtype))
11677 *insertTriggerOid = trgform->oid;
11679 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
11682 *updateTriggerOid = trgform->oid;
11684 #ifndef USE_ASSERT_CHECKING
11692 elog(
ERROR,
"could not find ON INSERT check triggers of foreign key constraint %u",
11695 elog(
ERROR,
"could not find ON UPDATE check triggers of foreign key constraint %u",
11713 bool recursing,
LOCKMODE lockmode)
11735 Anum_pg_constraint_conrelid,
11739 Anum_pg_constraint_contypid,
11743 Anum_pg_constraint_conname,
11747 true, NULL, 3, skey);
11752 (
errcode(ERRCODE_UNDEFINED_OBJECT),
11753 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
11757 if (currcon->contype != CONSTRAINT_FOREIGN)
11759 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11760 errmsg(
"constraint \"%s\" of relation \"%s\" is not a foreign key constraint",
11775 Oid parent = currcon->conparentid;
11776 char *ancestorname = NULL;
11777 char *ancestortable = NULL;
11793 parent = contup->conparentid;
11798 (
errmsg(
"cannot alter constraint \"%s\" on relation \"%s\"",
11800 ancestorname && ancestortable ?
11801 errdetail(
"Constraint \"%s\" is derived from constraint \"%s\" of relation \"%s\".",
11802 cmdcon->
conname, ancestorname, ancestortable) : 0,
11803 errhint(
"You may alter the constraint it derives from instead.")));
11812 if (currcon->condeferrable != cmdcon->
deferrable ||
11814 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11817 &otherrelids, lockmode))
11826 foreach(lc, otherrelids)
11856 bool changed =
false;
11862 conoid = currcon->oid;
11863 refrelid = currcon->confrelid;
11871 if (currcon->condeferrable != cmdcon->
deferrable ||
11882 copy_con->condeferrable = cmdcon->
deferrable;
11900 Anum_pg_trigger_tgconstraint,
11927 if (tgform->tgfoid != F_RI_FKEY_NOACTION_DEL &&
11928 tgform->tgfoid != F_RI_FKEY_NOACTION_UPD &&
11929 tgform->tgfoid != F_RI_FKEY_CHECK_INS &&
11930 tgform->tgfoid != F_RI_FKEY_CHECK_UPD)
11956 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
11964 Anum_pg_constraint_conparentid,
11969 true, NULL, 1, &pkey);
11976 childrel =
table_open(childcon->conrelid, lockmode);
11978 otherrelids, lockmode);
12001 bool recurse,
bool recursing,
LOCKMODE lockmode)
12016 Anum_pg_constraint_conrelid,
12020 Anum_pg_constraint_contypid,
12024 Anum_pg_constraint_conname,
12028 true, NULL, 3, skey);
12033 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12034 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12038 if (con->contype != CONSTRAINT_FOREIGN &&
12039 con->contype != CONSTRAINT_CHECK)
12041 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
12042 errmsg(
"constraint \"%s\" of relation \"%s\" is not a foreign key or check constraint",
12045 if (!con->convalidated)
12051 if (con->contype == CONSTRAINT_FOREIGN)
12059 fkconstraint->
conname = constrName;
12062 newcon->
name = constrName;
12064 newcon->
refrelid = con->confrelid;
12066 newcon->
conid = con->oid;
12067 newcon->
qual = (
Node *) fkconstraint;
12078 else if (con->contype == CONSTRAINT_CHECK)
12091 if (!recursing && !con->connoinherit)
12103 foreach(child, children)
12118 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12119 errmsg(
"constraint must be validated on child tables too")));
12131 newcon->
name = constrName;
12135 newcon->
conid = con->oid;
12138 Anum_pg_constraint_conbin);
12158 copy_con->convalidated =
true;
12196 foreach(l, colList)
12205 (
errcode(ERRCODE_UNDEFINED_COLUMN),
12206 errmsg(
"column \"%s\" referenced in foreign key constraint does not exist",
12209 if (attform->attnum < 0)
12211 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12212 errmsg(
"system columns cannot be used in foreign keys")));
12215 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
12216 errmsg(
"cannot have more than %d keys in a foreign key",
12218 attnums[
attnum] = attform->attnum;
12219 if (atttypids != NULL)
12220 atttypids[
attnum] = attform->atttypid;
12243 List **attnamelist,
12245 Oid *opclasses,
bool *pk_has_without_overlaps)
12247 List *indexoidlist;
12251 Datum indclassDatum;
12264 foreach(indexoidscan, indexoidlist)
12270 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
12272 if (indexStruct->indisprimary && indexStruct->indisvalid)
12279 if (!indexStruct->indimmediate)
12281 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12282 errmsg(
"cannot use a deferrable primary key for referenced table \"%s\"",
12285 *indexOid = indexoid;
12298 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12299 errmsg(
"there is no primary key for referenced table \"%s\"",
12304 Anum_pg_index_indclass);
12311 *attnamelist =
NIL;
12312 for (
i = 0;
i < indexStruct->indnkeyatts;
i++)
12314 int pkattno = indexStruct->indkey.values[
i];
12316 attnums[
i] = pkattno;
12318 opclasses[
i] = indclass->
values[
i];
12319 *attnamelist =
lappend(*attnamelist,
12323 *pk_has_without_overlaps = indexStruct->indisexclusion;
12345 int numattrs,
int16 *attnums,
12346 bool with_period,
Oid *opclasses,
12347 bool *pk_has_without_overlaps)
12350 bool found =
false;
12351 bool found_deferrable =
false;
12352 List *indexoidlist;
12364 for (
i = 0;
i < numattrs;
i++)
12366 for (
j =
i + 1;
j < numattrs;
j++)
12368 if (attnums[
i] == attnums[
j])
12370 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
12371 errmsg(
"foreign key referenced-columns list must not contain duplicates")));
12382 foreach(indexoidscan, indexoidlist)
12390 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
12398 if (indexStruct->indnkeyatts == numattrs &&
12399 (with_period ? indexStruct->indisexclusion : indexStruct->indisunique) &&
12400 indexStruct->indisvalid &&
12404 Datum indclassDatum;
12409 Anum_pg_index_indclass);
12422 for (
i = 0;
i < numattrs;
i++)
12425 for (
j = 0;
j < numattrs;
j++)
12427 if (attnums[
i] == indexStruct->indkey.values[
j])
12429 opclasses[
i] = indclass->
values[
j];
12438 if (found && with_period)
12440 int16 periodattnum = attnums[numattrs - 1];
12442 found = (periodattnum == indexStruct->indkey.values[numattrs - 1]);
12450 if (found && !indexStruct->indimmediate)
12456 found_deferrable =
true;
12462 *pk_has_without_overlaps = indexStruct->indisexclusion;
12471 if (found_deferrable)
12473 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12474 errmsg(
"cannot use a deferrable unique constraint for referenced table \"%s\"",
12478 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
12479 errmsg(
"there is no unique constraint matching given keys for referenced table \"%s\"",
12499 if (targetTypeId == sourceTypeId)
12510 elog(
ERROR,
"could not find cast from %u to %u",
12511 sourceTypeId, targetTypeId);
12536 for (
i = 0;
i < natts;
i++)
12568 (
errmsg_internal(
"validating foreign key constraint \"%s\"", conname)));
12603 "validateForeignKeyConstraint",
12624 trigdata.
type = T_TriggerData;
12631 fcinfo->context = (
Node *) &trigdata;
12654 Oid constraintOid,
Oid indexOid,
Oid parentTrigOid,
12672 fk_trigger->
trigname =
"RI_ConstraintTrigger_c";
12679 fk_trigger->
events = TRIGGER_TYPE_INSERT;
12684 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
12688 fk_trigger->
row =
true;
12689 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12697 trigAddress =
CreateTrigger(fk_trigger, NULL, myRelOid, refRelOid,
12699 parentTrigOid, NULL,
true,
false);
12717 Oid constraintOid,
Oid indexOid,
12718 Oid parentDelTrigger,
Oid parentUpdTrigger,
12719 Oid *deleteTrigOid,
Oid *updateTrigOid)
12731 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
12734 fk_trigger->
row =
true;
12735 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12736 fk_trigger->
events = TRIGGER_TYPE_DELETE;
12770 elog(
ERROR,
"unrecognized FK action type: %d",
12778 parentDelTrigger, NULL,
true,
false);
12780 *deleteTrigOid = trigAddress.
objectId;
12792 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
12795 fk_trigger->
row =
true;
12796 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12797 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
12831 elog(
ERROR,
"unrecognized FK action type: %d",
12839 parentUpdTrigger, NULL,
true,
false);
12841 *updateTrigOid = trigAddress.
objectId;
12856 Oid parentInsTrigger,
Oid parentUpdTrigger,
12857 Oid *insertTrigOid,
Oid *updateTrigOid)
12860 constraintOid, indexOid,
12861 parentInsTrigger,
true);
12863 constraintOid, indexOid,
12864 parentUpdTrigger,
false);
12875 bool missing_ok,
LOCKMODE lockmode)
12881 bool found =
false;
12889 Anum_pg_constraint_conrelid,
12893 Anum_pg_constraint_contypid,
12897 Anum_pg_constraint_conname,
12901 true, NULL, 3, skey);
12909 missing_ok, &readyRels, lockmode);
12919 errcode(ERRCODE_UNDEFINED_OBJECT),
12920 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12924 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist, skipping",
12941 bool recurse,
bool recursing,
bool missing_ok,
List **readyRels,
12948 bool is_no_inherit_constraint =
false;
12950 List *unconstrained_cols =
NIL;
12951 char *colname = NULL;
12952 bool dropping_pk =
false;
12968 constrName =
NameStr(con->conname);
12979 if (con->contype == CONSTRAINT_NOTNULL &&
12980 con->conislocal && con->coninhcount > 0)
12986 con->conislocal =
false;
12996 if (con->coninhcount > 0 && !recursing)
12998 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12999 errmsg(
"cannot drop inherited constraint \"%s\" of relation \"%s\"",
13007 if (con->contype == CONSTRAINT_NOTNULL)
13016 else if (con->contype == CONSTRAINT_PRIMARY)
13024 dropping_pk =
true;
13026 adatum =
heap_getattr(constraintTup, Anum_pg_constraint_conkey,
13029 elog(
ERROR,
"null conkey for constraint %u", con->oid);
13036 elog(
ERROR,
"conkey is not a 1-D smallint array");
13039 for (
int i = 0;
i < numkeys;
i++)
13040 unconstrained_cols =
lappend_int(unconstrained_cols, attnums[
i]);
13043 is_no_inherit_constraint = con->connoinherit;
13052 if (con->contype == CONSTRAINT_FOREIGN &&
13073 if (unconstrained_cols !=
NIL)
13088 pkcols = dropping_pk ? NULL :
13105 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
13108 attidentity = attForm->attidentity;
13129 if (attidentity !=
'\0')
13131 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
13132 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
13143 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13144 errmsg(
"column \"%s\" is in index used as replica identity",
13154 if (con->contype != CONSTRAINT_CHECK &&
13155 con->contype != CONSTRAINT_NOTNULL &&
13156 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
13167 if (!is_no_inherit_constraint)
13177 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
13178 children !=
NIL && !recurse)
13180 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13181 errmsg(
"cannot remove constraint from only the partitioned table when partitions exist"),
13182 errhint(
"Do not specify the ONLY keyword.")));
13201 if (con->contype == CONSTRAINT_NOTNULL)
13205 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\" of relation %u",
13214 Anum_pg_constraint_conrelid,
13218 Anum_pg_constraint_contypid,
13222 Anum_pg_constraint_conname,
13226 true, NULL, 3, skey);
13231 (
errcode(ERRCODE_UNDEFINED_OBJECT),
13232 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
13242 if (childcon->contype != CONSTRAINT_CHECK &&
13243 childcon->contype != CONSTRAINT_NOTNULL)
13244 elog(
ERROR,
"inherited constraint is not a CHECK or not-null constraint");
13246 if (childcon->coninhcount <= 0)
13247 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
13248 childrelid,
NameStr(childcon->conname));
13256 if (childcon->coninhcount == 1 && !childcon->conislocal)
13260 recurse,
true, missing_ok, readyRels,
13266 childcon->coninhcount--;
13281 childcon->coninhcount--;
13282 if (childcon->coninhcount == 0)
13283 childcon->conislocal =
true;
13302 if (con->contype == CONSTRAINT_PRIMARY &&
13303 rel->
rd_rel->relkind == RELKIND_RELATION &&
13304 rel->
rd_rel->relhassubclass)
13341 if (contup == NULL)
13342 elog(
ERROR,
"cache lookup failed for not-null constraint on column \"%s\", relation \"%s\"",
13383 bool recurse,
bool recursing,
13387 char *colName = cmd->
name;
13395 int32 targettypmod;
13402 if (rel->
rd_rel->reloftype && !recursing)
13404 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
13405 errmsg(
"cannot alter column type of typed table")));
13411 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13412 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
13415 attnum = attTup->attnum;
13420 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13421 errmsg(
"cannot alter system column \"%s\"",
13429 if (attTup->attinhcount > 0 && !recursing)
13431 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13432 errmsg(
"cannot alter inherited column \"%s\"",
13440 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13441 errmsg(
"cannot alter column \"%s\" because it is part of the partition key of relation \"%s\"",
13459 if (tab->
relkind == RELKIND_RELATION ||
13460 tab->
relkind == RELKIND_PARTITIONED_TABLE)
13474 attTup->atttypid, attTup->atttypmod,
13475 attTup->attcollation,
13481 targettype, targettypmod,
13485 if (transform == NULL)
13490 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13491 errmsg(
"result of USING clause for column \"%s\""
13492 " cannot be cast automatically to type %s",
13494 errhint(
"You might need to add an explicit cast.")));
13497 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13498 errmsg(
"column \"%s\" cannot be cast automatically to type %s",
13501 errhint(
"You might need to specify \"USING %s::%s\".",
13520 newval->is_generated =
false;
13526 else if (transform)
13528 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
13529 errmsg(
"\"%s\" is not a table",
13532 if (!RELKIND_HAS_STORAGE(tab->
relkind))
13560 &child_numparents);
13567 forboth(lo, child_oids, li, child_numparents)
13575 if (childrelid == relid)
13592 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13593 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
13597 if (childattTup->attinhcount > numparents)
13599 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13600 errmsg(
"cannot alter inherited column \"%s\" of relation \"%s\"",
13612 bool found_whole_row;
13625 if (found_whole_row)
13627 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13628 errmsg(
"cannot convert whole-row table reference"),
13629 errdetail(
"USING expression contains a whole-row table reference.")));
13636 else if (!recursing &&
13639 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13640 errmsg(
"type of inherited column \"%s\" must be changed in child tables too",
13643 if (tab->
relkind == RELKIND_COMPOSITE_TYPE)
13669 if (
IsA(expr,
Var) && ((
Var *) expr)->varattno == varattno)
13687 case F_TIMESTAMPTZ_TIMESTAMP:
13688 case F_TIMESTAMP_TIMESTAMPTZ:
13712 char *colName = cmd->
name;
13722 int32 targettypmod;
13753 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13754 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
13757 attnum = attTup->attnum;
13761 if (attTup->atttypid != attOldTup->atttypid ||
13762 attTup->atttypmod != attOldTup->atttypmod)
13764 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13765 errmsg(
"cannot alter type of column \"%s\" twice",
13769 typeTuple =
typenameType(NULL, typeName, &targettypmod);
13771 targettype = tform->oid;
13787 if (attTup->atthasdef)
13793 defaultexpr,
exprType(defaultexpr),
13794 targettype, targettypmod,
13798 if (defaultexpr == NULL)
13800 if (attTup->attgenerated)
13802 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13803 errmsg(
"generation expression for column \"%s\" cannot be cast automatically to type %s",
13807 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13808 errmsg(
"default for column \"%s\" cannot be cast automatically to type %s",
13813 defaultexpr = NULL;
13834 Anum_pg_depend_classid,
13838 Anum_pg_depend_objid,
13842 Anum_pg_depend_objsubid,
13854 foundObject.
classId = foundDep->refclassid;
13855 foundObject.
objectId = foundDep->refobjid;
13859 elog(
ERROR,
"found unexpected dependency type '%c'",
13860 foundDep->deptype);
13861 if (!(foundDep->refclassid == TypeRelationId &&
13862 foundDep->refobjid == attTup->atttypid) &&
13863 !(foundDep->refclassid == CollationRelationId &&
13864 foundDep->refobjid == attTup->attcollation))
13865 elog(
ERROR,
"found unexpected dependency for column: %s",
13880 if (attTup->atthasmissing)
13890 Anum_pg_attribute_attmissingval,
13891 attrelation->rd_att,
13907 Datum valuesAtt[Natts_pg_attribute] = {0};
13908 bool nullsAtt[Natts_pg_attribute] = {0};
13909 bool replacesAtt[Natts_pg_attribute] = {0};
13927 valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
13928 replacesAtt[Anum_pg_attribute_attmissingval - 1] =
true;
13929 nullsAtt[Anum_pg_attribute_attmissingval - 1] =
false;
13932 valuesAtt, nullsAtt, replacesAtt);
13939 attTup->atttypid = targettype;
13940 attTup->atttypmod = targettypmod;
13941 attTup->attcollation = targetcollid;
13944 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
13945 errmsg(
"too many array dimensions"));
13946 attTup->attndims =
list_length(typeName->arrayBounds);
13947 attTup->attlen = tform->typlen;
13948 attTup->attbyval = tform->typbyval;
13949 attTup->attalign = tform->typalign;
13950 attTup->attstorage = tform->typstorage;
13985 if (attTup->attgenerated)
13990 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
14039 Anum_pg_depend_refclassid,
14043 Anum_pg_depend_refobjid,
14047 Anum_pg_depend_refobjsubid,
14059 foundObject.
classId = foundDep->classid;
14060 foundObject.
objectId = foundDep->objid;
14065 case RelationRelationId:
14069 if (relKind == RELKIND_INDEX ||
14070 relKind == RELKIND_PARTITIONED_INDEX)
14075 else if (relKind == RELKIND_SEQUENCE)
14086 elog(
ERROR,
"unexpected object depending on column: %s",
14092 case ConstraintRelationId:
14097 case RewriteRelationId:
14101 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14102 errmsg(
"cannot alter type of a column used by a view or rule"),
14103 errdetail(
"%s depends on column \"%s\"",
14108 case TriggerRelationId:
14121 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14122 errmsg(
"cannot alter type of a column used in a trigger definition"),
14123 errdetail(
"%s depends on column \"%s\"",
14128 case PolicyRelationId:
14140 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14141 errmsg(
"cannot alter type of a column used in a policy definition"),
14142 errdetail(
"%s depends on column \"%s\"",
14147 case AttrDefaultRelationId:
14171 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14172 errmsg(
"cannot alter type of a column used by a generated column"),
14173 errdetail(
"Column \"%s\" is used by generated column \"%s\".",
14182 case StatisticExtRelationId:
14197 elog(
ERROR,
"unexpected object depending on column: %s",
14218 elog(
ERROR,
"relation %u has multiple indexes marked as replica identity", tab->
relid);
14233 elog(
ERROR,
"relation %u has multiple clustered indexes", tab->
relid);
14403 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
14406 relid = con->conrelid;
14412 elog(
ERROR,
"could not identify relation associated with constraint %u", oldId);
14414 confrelid = con->confrelid;
14415 contype = con->contype;
14416 conislocal = con->conislocal;
14438 if (relid != tab->
relid && contype == CONSTRAINT_FOREIGN)
14442 (
char *)
lfirst(def_item),
14443 wqueue, lockmode, tab->
rewrite);
14445 forboth(oid_item, tab->changedIndexOids,
14446 def_item, tab->changedIndexDefs)
14453 (
char *)
lfirst(def_item),
14454 wqueue, lockmode, tab->rewrite);
14461 forboth(oid_item, tab->changedStatisticsOids,
14462 def_item, tab->changedStatisticsDefs)
14469 (
char *)
lfirst(def_item),
14470 wqueue, lockmode, tab->rewrite);
14479 if (tab->replicaIdentityIndex)
14485 subcmd->
name = tab->replicaIdentityIndex;
14497 if (tab->clusterOnIndex)
14502 cmd->
name = tab->clusterOnIndex;
14535 List *raw_parsetree_list;
14536 List *querytree_list;
14547 querytree_list =
NIL;
14548 foreach(list_item, raw_parsetree_list)
14554 querytree_list =
lappend(querytree_list,
14568 querytree_list =
list_concat(querytree_list, beforeStmts);
14570 querytree_list =
list_concat(querytree_list, afterStmts);
14573 querytree_list =
lappend(querytree_list,
14592 foreach(list_item, querytree_list)
14606 stmt->reset_default_tblspc =
true;
14621 foreach(lcmd,
stmt->cmds)
14637 RelationRelationId, 0);
14659 !rewrite && tab->
rewrite == 0)
14689 elog(
ERROR,
"unexpected statement subtype: %d",
14697 if (
stmt->subtype ==
'C')
14716 elog(
ERROR,
"unexpected statement subtype: %d",
14717 (
int)
stmt->subtype);
14725 stmt->stxcomment =
GetComment(oldId, StatisticExtRelationId, 0);
14734 elog(
ERROR,
"unexpected statement type: %d",
14754 const char *conname)
14761 comment_str =
GetComment(objid, ConstraintRelationId, 0);
14762 if (comment_str == NULL)
14799 stmt->accessMethod,
14801 stmt->excludeOpNames,
14802 stmt->iswithoutoverlaps))
14807 if (irel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
14839 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
14842 Anum_pg_constraint_conpfeqop);
14849 elog(
ERROR,
"conpfeqop is not a 1-D Oid array");
14853 for (
i = 0;
i < numkeys;
i++)
14866 const char *colName,
14877 Datum repl_val[Natts_pg_attribute];
14878 bool repl_null[Natts_pg_attribute];
14879 bool repl_repl[Natts_pg_attribute];
14894 (
errcode(ERRCODE_UNDEFINED_OBJECT),
14895 errmsg(
"foreign table \"%s\" does not exist",
14908 (
errcode(ERRCODE_UNDEFINED_COLUMN),
14909 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
14914 attnum = atttableform->attnum;
14917 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14918 errmsg(
"cannot alter system column \"%s\"", colName)));
14922 memset(repl_val, 0,
sizeof(repl_val));
14923 memset(repl_null,
false,
sizeof(repl_null));
14924 memset(repl_repl,
false,
sizeof(repl_repl));
14929 Anum_pg_attribute_attfdwoptions,
14941 repl_val[Anum_pg_attribute_attfdwoptions - 1] = datum;
14943 repl_null[Anum_pg_attribute_attfdwoptions - 1] =
true;
14945 repl_repl[Anum_pg_attribute_attfdwoptions - 1] =
true;
14950 repl_val, repl_null, repl_repl);
14956 atttableform->attnum);
15000 elog(
ERROR,
"cache lookup failed for relation %u", relationOid);
15004 switch (tuple_class->relkind)
15006 case RELKIND_RELATION:
15008 case RELKIND_MATVIEW:
15009 case RELKIND_FOREIGN_TABLE:
15010 case RELKIND_PARTITIONED_TABLE:
15013 case RELKIND_INDEX:
15023 if (tuple_class->relowner != newOwnerId)
15025 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15026 errmsg(
"cannot change owner of index \"%s\"",
15027 NameStr(tuple_class->relname)),
15028 errhint(
"Change the ownership of the index's table instead.")));
15030 newOwnerId = tuple_class->relowner;
15033 case RELKIND_PARTITIONED_INDEX:
15037 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15038 errmsg(
"cannot change owner of index \"%s\"",
15039 NameStr(tuple_class->relname)),
15040 errhint(
"Change the ownership of the index's table instead.")));
15042 case RELKIND_SEQUENCE:
15044 tuple_class->relowner != newOwnerId)
15053 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15054 errmsg(
"cannot change owner of sequence \"%s\"",
15055 NameStr(tuple_class->relname)),
15056 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
15057 NameStr(tuple_class->relname),
15061 case RELKIND_COMPOSITE_TYPE:
15065 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15066 errmsg(
"\"%s\" is a composite type",
15067 NameStr(tuple_class->relname)),
15072 case RELKIND_TOASTVALUE:
15078 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15079 errmsg(
"cannot change owner of relation \"%s\"",
15080 NameStr(tuple_class->relname)),
15088 if (tuple_class->relowner != newOwnerId)
15090 Datum repl_val[Natts_pg_class];
15091 bool repl_null[Natts_pg_class];
15092 bool repl_repl[Natts_pg_class];
15104 Oid namespaceOid = tuple_class->relnamespace;
15116 aclresult =
object_aclcheck(NamespaceRelationId, namespaceOid, newOwnerId,
15124 memset(repl_null,
false,
sizeof(repl_null));
15125 memset(repl_repl,
false,
sizeof(repl_repl));
15127 repl_repl[Anum_pg_class_relowner - 1] =
true;
15135 Anum_pg_class_relacl,
15140 tuple_class->relowner, newOwnerId);
15141 repl_repl[Anum_pg_class_relacl - 1] =
true;
15156 tuple_class->relowner,
15164 if (tuple_class->relkind != RELKIND_COMPOSITE_TYPE &&
15165 tuple_class->relkind != RELKIND_INDEX &&
15166 tuple_class->relkind != RELKIND_PARTITIONED_INDEX &&
15167 tuple_class->relkind != RELKIND_TOASTVALUE)
15182 if (tuple_class->relkind == RELKIND_RELATION ||
15183 tuple_class->relkind == RELKIND_PARTITIONED_TABLE ||
15184 tuple_class->relkind == RELKIND_MATVIEW ||
15185 tuple_class->relkind == RELKIND_TOASTVALUE)
15187 List *index_oid_list;
15194 foreach(
i, index_oid_list)
15201 if (tuple_class->reltoastrelid !=
InvalidOid)
15232 Anum_pg_attribute_attrelid,
15236 true, NULL, 1,
key);
15240 Datum repl_val[Natts_pg_attribute];
15241 bool repl_null[Natts_pg_attribute];
15242 bool repl_repl[Natts_pg_attribute];
15249 if (att->attisdropped)
15253 Anum_pg_attribute_attacl,
15260 memset(repl_null,
false,
sizeof(repl_null));
15261 memset(repl_repl,
false,
sizeof(repl_repl));
15264 oldOwnerId, newOwnerId);
15265 repl_repl[Anum_pg_attribute_attacl - 1] =
true;
15270 repl_val, repl_null, repl_repl);
15302 Anum_pg_depend_refclassid,
15306 Anum_pg_depend_refobjid,
15320 if (depForm->refobjsubid == 0 ||
15321 depForm->classid != RelationRelationId ||
15322 depForm->objsubid != 0 ||
15366 (
errcode(ERRCODE_UNDEFINED_OBJECT),
15367 errmsg(
"index \"%s\" for table \"%s\" does not exist",
15377 RelationRelationId, indexOid);
15410 if (amname != NULL)
15412 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
15418 if (rel->
rd_rel->relam == amoid)
15438 Oid oldAccessMethodId;
15454 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
15458 oldAccessMethodId = rd_rel->relam;
15459 rd_rel->relam = newAccessMethodId;
15462 if (rd_rel->relam == oldAccessMethodId)
15498 AccessMethodRelationId,
15508 AccessMethodRelationId,
15509 oldAccessMethodId, rd_rel->relam);
15545 (
errcode(ERRCODE_SYNTAX_ERROR),
15546 errmsg(
"cannot have multiple SET TABLESPACE subcommands")));
15565 Datum repl_val[Natts_pg_class];
15566 bool repl_null[Natts_pg_class];
15567 bool repl_repl[Natts_pg_class];
15579 elog(
ERROR,
"cache lookup failed for relation %u", relid);
15599 defList, NULL, validnsps,
false,
15603 switch (rel->
rd_rel->relkind)
15605 case RELKIND_RELATION:
15606 case RELKIND_TOASTVALUE:
15607 case RELKIND_MATVIEW:
15610 case RELKIND_PARTITIONED_TABLE:
15616 case RELKIND_INDEX:
15617 case RELKIND_PARTITIONED_INDEX:
15622 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15623 errmsg(
"cannot set options for relation \"%s\"",
15630 if (rel->
rd_rel->relkind == RELKIND_VIEW)
15635 bool check_option =
false;
15637 foreach(cell, view_options)
15641 if (strcmp(defel->
defname,
"check_option") == 0)
15642 check_option =
true;
15651 const char *view_updatable_error =
15654 if (view_updatable_error)
15656 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15657 errmsg(
"WITH CHECK OPTION is supported only on automatically updatable views"),
15658 errhint(
"%s",
_(view_updatable_error))));
15666 memset(repl_val, 0,
sizeof(repl_val));
15667 memset(repl_null,
false,
sizeof(repl_null));
15668 memset(repl_repl,
false,
sizeof(repl_repl));
15670 if (newOptions != (
Datum) 0)
15671 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
15673 repl_null[Anum_pg_class_reloptions - 1] =
true;
15675 repl_repl[Anum_pg_class_reloptions - 1] =
true;
15678 repl_val, repl_null, repl_repl);
15692 Oid toastid = rel->
rd_rel->reltoastrelid;
15699 elog(
ERROR,
"cache lookup failed for relation %u", toastid);
15718 defList,
"toast", validnsps,
false,
15723 memset(repl_val, 0,
sizeof(repl_val));
15724 memset(repl_null,
false,
sizeof(repl_null));
15725 memset(repl_repl,
false,
sizeof(repl_repl));
15727 if (newOptions != (
Datum) 0)
15728 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
15730 repl_null[Anum_pg_class_reloptions - 1] =
true;
15732 repl_repl[Anum_pg_class_reloptions - 1] =
true;
15735 repl_val, repl_null, repl_repl);
15781 reltoastrelid = rel->
rd_rel->reltoastrelid;
15796 rel->
rd_rel->relpersistence);
15800 newrlocator.
relNumber = newrelfilenumber;
15801 newrlocator.
spcOid = newTableSpace;
15804 if (rel->
rd_rel->relkind == RELKIND_INDEX)
15836 foreach(lc, reltoastidxids)
15898 Oid orig_tablespaceoid;
15899 Oid new_tablespaceoid;
15906 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15907 errmsg(
"only tables, indexes, and materialized views exist in tablespaces")));
15915 if (orig_tablespaceoid == GLOBALTABLESPACE_OID ||
15916 new_tablespaceoid == GLOBALTABLESPACE_OID)
15918 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15919 errmsg(
"cannot move relations in to or out of pg_global tablespace")));
15948 if (orig_tablespaceoid == new_tablespaceoid)
15949 return new_tablespaceoid;
15956 Anum_pg_class_reltablespace,
15965 Oid relOid = relForm->oid;
15976 relForm->relisshared ||
15983 relForm->relkind != RELKIND_RELATION &&
15984 relForm->relkind != RELKIND_PARTITIONED_TABLE) ||
15986 relForm->relkind != RELKIND_INDEX &&
15987 relForm->relkind != RELKIND_PARTITIONED_INDEX) ||
15989 relForm->relkind != RELKIND_MATVIEW))
16007 if (
stmt->nowait &&
16010 (
errcode(ERRCODE_OBJECT_IN_USE),
16011 errmsg(
"aborting because lock on relation \"%s.%s\" is not available",
16013 NameStr(relForm->relname))));
16024 if (relations ==
NIL)
16026 (
errcode(ERRCODE_NO_DATA_FOUND),
16027 errmsg(
"no matching relations in tablespace \"%s\" found",
16028 orig_tablespaceoid ==
InvalidOid ?
"(database default)" :
16032 foreach(l, relations)
16038 cmd->
name =
stmt->new_tablespacename;
16048 return new_tablespaceoid;
16075 rel->
rd_rel->relpersistence);
16090 (rel->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
16094 rel->
rd_rel->relpersistence);
16110 char fires_when,
bool skip_system,
bool recurse,
16114 fires_when, skip_system, recurse,
16128 char fires_when,
LOCKMODE lockmode)
16146 if (child_rel->
rd_rel->reloftype)
16148 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16149 errmsg(
"cannot change inheritance of typed table")));
16151 if (child_rel->
rd_rel->relispartition)
16153 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16154 errmsg(
"cannot change inheritance of a partition")));
16156 if (child_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
16158 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16159 errmsg(
"cannot change inheritance of partitioned table")));
16171 const char *trigger_name;
16186 if (parent_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
16187 child_rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
16189 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16190 errmsg(
"cannot inherit from temporary relation \"%s\"",
16194 if (parent_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
16197 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16198 errmsg(
"cannot inherit from temporary relation of another session")));
16201 if (child_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
16204 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16205 errmsg(
"cannot inherit to temporary relation of another session")));
16208 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
16210 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16211 errmsg(
"cannot inherit from partitioned table \"%s\"",
16215 if (parent_rel->
rd_rel->relispartition)
16217 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16218 errmsg(
"cannot inherit from a partition")));
16239 (
errcode(ERRCODE_DUPLICATE_TABLE),
16240 errmsg(
"circular inheritance not allowed"),
16241 errdetail(
"\"%s\" is already a child of \"%s\".",
16251 if (trigger_name != NULL)
16253 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16254 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming an inheritance child",
16256 errdetail(
"ROW triggers with transition tables are not supported in inheritance hierarchies.")));
16306 Anum_pg_inherits_inhrelid,
16310 true, NULL, 1, &
key);
16320 (
errcode(ERRCODE_DUPLICATE_TABLE),
16321 errmsg(
"relation \"%s\" would be inherited from more than once",
16324 if (inh->inhseqno > inhseqno)
16325 inhseqno = inh->inhseqno;
16342 parent_rel->
rd_rel->relkind ==
16343 RELKIND_PARTITIONED_TABLE);
16362 attr =
heap_getattr(contup, Anum_pg_constraint_conbin, tupdesc, &isnull);
16364 elog(
ERROR,
"null conbin for constraint %u", con->oid);
16384 if (acon->condeferrable != bcon->condeferrable ||
16385 acon->condeferred != bcon->condeferred ||
16416 for (
AttrNumber parent_attno = 1; parent_attno <= parent_desc->
natts; parent_attno++)
16419 char *parent_attname =
NameStr(parent_att->attname);
16423 if (parent_att->attisdropped)
16432 if (parent_att->atttypid != child_att->atttypid ||
16433 parent_att->atttypmod != child_att->atttypmod)
16435 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16436 errmsg(
"child table \"%s\" has different type for column \"%s\"",
16439 if (parent_att->attcollation != child_att->attcollation)
16441 (
errcode(ERRCODE_COLLATION_MISMATCH),
16442 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
16451 if (parent_att->attnotnull && !child_att->attnotnull)
16456 parent_att->attnum);
16460 errcode(ERRCODE_DATATYPE_MISMATCH),
16461 errmsg(
"column \"%s\" in child table must be marked NOT NULL",
16468 if (parent_att->attgenerated && !child_att->attgenerated)
16470 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16471 errmsg(
"column \"%s\" in child table must be a generated column", parent_attname)));
16472 if (child_att->attgenerated && !parent_att->attgenerated)
16474 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16475 errmsg(
"column \"%s\" in child table must not be a generated column", parent_attname)));
16483 child_att->attidentity = parent_att->attidentity;
16489 child_att->attinhcount++;
16490 if (child_att->attinhcount < 0)
16492 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
16493 errmsg(
"too many inheritance parents"));
16500 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
16502 Assert(child_att->attinhcount == 1);
16503 child_att->attislocal =
false;
16512 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16513 errmsg(
"child table is missing column \"%s\"", parent_attname)));
16550 Anum_pg_constraint_conrelid,
16554 true, NULL, 1, &parent_key);
16562 bool found =
false;
16564 if (parent_con->contype != CONSTRAINT_CHECK &&
16565 parent_con->contype != CONSTRAINT_NOTNULL)
16569 if (parent_con->connoinherit)
16574 Anum_pg_constraint_conrelid,
16578 true, NULL, 1, &child_key);
16585 if (child_con->contype != parent_con->contype)
16592 if (child_con->contype == CONSTRAINT_CHECK)
16594 if (strcmp(
NameStr(parent_con->conname),
16595 NameStr(child_con->conname)) != 0)
16598 else if (child_con->contype == CONSTRAINT_NOTNULL)
16603 if (strcmp(
get_attname(parent_relid, parent_attno,
false),
16609 if (child_con->contype == CONSTRAINT_CHECK &&
16612 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16613 errmsg(
"child table \"%s\" has different definition for check constraint \"%s\"",
16627 if (child_con->contype == CONSTRAINT_CHECK &&
16628 child_con->connoinherit)
16630 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
16631 errmsg(
"constraint \"%s\" conflicts with non-inherited constraint on child table \"%s\"",
16638 if (parent_con->convalidated && !child_con->convalidated)
16640 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
16641 errmsg(
"constraint \"%s\" conflicts with NOT VALID constraint on child table \"%s\"",
16650 child_con->coninhcount++;
16651 if (child_con->coninhcount < 0)
16653 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
16654 errmsg(
"too many inheritance parents"));
16655 if (child_con->contype == CONSTRAINT_NOTNULL &&
16656 child_con->connoinherit)
16664 if (child_rel->
rd_rel->relhassubclass)
16666 errmsg(
"cannot add NOT NULL constraint to column \"%s\" of relation \"%s\" with inheritance children",
16671 errdetail(
"Existing constraint \"%s\" is marked NO INHERIT.",
16672 NameStr(child_con->conname)));
16674 child_con->connoinherit =
false;
16682 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
16684 Assert(child_con->coninhcount == 1);
16685 child_con->conislocal =
false;
16699 if (parent_con->contype == CONSTRAINT_NOTNULL)
16701 errcode(ERRCODE_DATATYPE_MISMATCH),
16702 errmsg(
"column \"%s\" in child table must be marked NOT NULL",
16708 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16709 errmsg(
"child table is missing constraint \"%s\"",
16710 NameStr(parent_con->conname))));
16729 if (rel->
rd_rel->relispartition)
16731 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16732 errmsg(
"cannot change inheritance of a partition")));
16784 bool found =
false;
16786 Assert(parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
16794 Anum_pg_inherits_inhparent,
16798 true, NULL, 1, &
key);
16805 if (inhForm->inhdetachpending)
16807 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
16808 errmsg(
"partition \"%s\" already pending detach in partitioned table \"%s.%s\"",
16812 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
16837 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
16871 bool is_partitioning;
16873 is_partitioning = (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
16881 if (is_partitioning)
16884 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
16890 errmsg(
"relation \"%s\" is not a parent of relation \"%s\"",
16900 Anum_pg_attribute_attrelid,
16904 true, NULL, 1,
key);
16910 if (att->attisdropped)
16912 if (att->attinhcount <= 0)
16922 copy_att->attinhcount--;
16923 if (copy_att->attinhcount == 0)
16924 copy_att->attislocal =
true;
16943 Anum_pg_constraint_conrelid,
16947 true, NULL, 1,
key);
16956 if (con->contype == CONSTRAINT_CHECK)
16958 if (con->contype == CONSTRAINT_NOTNULL)
16966 Anum_pg_constraint_conrelid,
16970 true, NULL, 1,
key);
16975 bool match =
false;
16982 if (con->contype == CONSTRAINT_CHECK)
16984 foreach(lc, connames)
16986 if (con->contype == CONSTRAINT_CHECK &&
16994 else if (con->contype == CONSTRAINT_NOTNULL)
16998 foreach(lc, nncolumns)
17016 if (copy_con->coninhcount <= 0)
17017 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
17020 copy_con->coninhcount--;
17021 if (copy_con->coninhcount == 0)
17022 copy_con->conislocal =
true;
17033 RelationRelationId,
17063 if (!parent_rel->
rd_rel->relhasindex)
17068 if (pkattnos != NULL)
17114 Anum_pg_depend_classid,
17118 Anum_pg_depend_objid,
17122 Anum_pg_depend_objsubid,
17133 if (dep->refclassid == refclassid &&
17134 dep->refobjid == refobjid &&
17135 dep->refobjsubid == 0 &&
17136 dep->deptype == deptype)
17177 typeid = typeform->oid;
17182 Anum_pg_inherits_inhrelid,
17186 true, NULL, 1, &
key);
17189 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17190 errmsg(
"typed tables cannot inherit")));
17201 for (type_attno = 1; type_attno <= typeTupleDesc->
natts; type_attno++)
17205 const char *type_attname,
17210 if (type_attr->attisdropped)
17212 type_attname =
NameStr(type_attr->attname);
17217 if (table_attno > tableTupleDesc->
natts)
17219 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17220 errmsg(
"table is missing column \"%s\"",
17222 table_attr =
TupleDescAttr(tableTupleDesc, table_attno - 1);
17224 }
while (table_attr->attisdropped);
17225 table_attname =
NameStr(table_attr->attname);
17228 if (strncmp(table_attname, type_attname,
NAMEDATALEN) != 0)
17230 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17231 errmsg(
"table has column \"%s\" where type requires \"%s\"",
17232 table_attname, type_attname)));
17235 if (table_attr->atttypid != type_attr->atttypid ||
17236 table_attr->atttypmod != type_attr->atttypmod ||
17237 table_attr->attcollation != type_attr->attcollation)
17239 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17240 errmsg(
"table \"%s\" has different type for column \"%s\"",
17246 for (; table_attno <= tableTupleDesc->
natts; table_attno++)
17251 if (!table_attr->attisdropped)
17253 (
errcode(ERRCODE_DATATYPE_MISMATCH),
17254 errmsg(
"table has extra column \"%s\"",
17255 NameStr(table_attr->attname))));
17259 if (rel->
rd_rel->reloftype)
17264 tableobj.
classId = RelationRelationId;
17267 typeobj.
classId = TypeRelationId;
17276 elog(
ERROR,
"cache lookup failed for relation %u", relid);
17305 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17306 errmsg(
"\"%s\" is not a typed table",
17321 elog(
ERROR,
"cache lookup failed for relation %u", relid);
17359 elog(
ERROR,
"cache lookup failed for relation \"%s\"",
17362 if (pg_class_form->relreplident != ri_type)
17364 pg_class_form->relreplident = ri_type;
17377 bool dirty =
false;
17382 elog(
ERROR,
"cache lookup failed for index %u", thisIndexOid);
17385 if (thisIndexOid == indexOid)
17388 if (!pg_index_form->indisreplident)
17391 pg_index_form->indisreplident =
true;
17397 if (pg_index_form->indisreplident)
17400 pg_index_form->indisreplident =
false;
17435 if (
stmt->identity_type == REPLICA_IDENTITY_DEFAULT)
17440 else if (
stmt->identity_type == REPLICA_IDENTITY_FULL)
17445 else if (
stmt->identity_type == REPLICA_IDENTITY_NOTHING)
17450 else if (
stmt->identity_type == REPLICA_IDENTITY_INDEX)
17455 elog(
ERROR,
"unexpected identity type %u",
stmt->identity_type);
17461 (
errcode(ERRCODE_UNDEFINED_OBJECT),
17462 errmsg(
"index \"%s\" for table \"%s\" does not exist",
17471 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17472 errmsg(
"\"%s\" is not an index for table \"%s\"",
17479 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17480 errmsg(
"cannot use non-unique index \"%s\" as replica identity",
17483 if (!indexRel->
rd_index->indimmediate)
17485 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17486 errmsg(
"cannot use non-immediate index \"%s\" as replica identity",
17491 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17492 errmsg(
"cannot use expression index \"%s\" as replica identity",
17497 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17498 errmsg(
"cannot use partial index \"%s\" as replica identity",
17514 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
17515 errmsg(
"index \"%s\" cannot be used as replica identity because column %d is a system column",
17519 if (!attr->attnotnull)
17521 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17522 errmsg(
"index \"%s\" cannot be used as replica identity because column \"%s\" is nullable",
17551 elog(
ERROR,
"cache lookup failed for relation %u", relid);
17580 elog(
ERROR,
"cache lookup failed for relation %u", relid);
17603 Datum repl_val[Natts_pg_foreign_table];
17604 bool repl_null[Natts_pg_foreign_table];
17605 bool repl_repl[Natts_pg_foreign_table];
17618 (
errcode(ERRCODE_UNDEFINED_OBJECT),
17619 errmsg(
"foreign table \"%s\" does not exist",
17625 memset(repl_val, 0,
sizeof(repl_val));
17626 memset(repl_null,
false,
sizeof(repl_null));
17627 memset(repl_repl,
false,
sizeof(repl_repl));
17632 Anum_pg_foreign_table_ftoptions,
17644 repl_val[Anum_pg_foreign_table_ftoptions - 1] = datum;
17646 repl_null[Anum_pg_foreign_table_ftoptions - 1] =
true;
17648 repl_repl[Anum_pg_foreign_table_ftoptions - 1] =
true;
17653 repl_val, repl_null, repl_repl);
17678 const char *column,
17690 compression =
strVal(newValue);
17698 (
errcode(ERRCODE_UNDEFINED_COLUMN),
17699 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
17704 attnum = atttableform->attnum;
17707 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17708 errmsg(
"cannot alter system column \"%s\"", column)));
17717 atttableform->attcompression = cmethod;
17769 switch (rel->
rd_rel->relpersistence)
17771 case RELPERSISTENCE_TEMP:
17773 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17774 errmsg(
"cannot change logged status of table \"%s\" because it is temporary",
17778 case RELPERSISTENCE_PERMANENT:
17783 case RELPERSISTENCE_UNLOGGED:
17797 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
17798 errmsg(
"cannot change table \"%s\" to unlogged because it is part of a publication",
17800 errdetail(
"Unlogged relations cannot be replicated.")));
17814 toLogged ? Anum_pg_constraint_conrelid :
17815 Anum_pg_constraint_confrelid,
17819 toLogged ? ConstraintRelidTypidNameIndexId :
InvalidOid,
17820 true, NULL, 1, skey);
17826 if (con->contype == CONSTRAINT_FOREIGN)
17832 foreignrelid = toLogged ? con->confrelid : con->conrelid;
17844 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17845 errmsg(
"could not change table \"%s\" to logged because it references unlogged table \"%s\"",
17854 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17855 errmsg(
"could not change table \"%s\" to unlogged because it references logged table \"%s\"",
17894 (
errmsg(
"relation \"%s\" does not exist, skipping",
17895 stmt->relation->relname)));
17904 if (rel->
rd_rel->relkind == RELKIND_SEQUENCE)
17912 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17913 errmsg(
"cannot move an owned sequence into another schema"),
17914 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
17933 *oldschema = oldNspOid;
17952 Assert(objsMoved != NULL);
17958 nspOid,
true, objsMoved);
17963 nspOid,
false,
false, objsMoved);
17982 Oid oldNspOid,
Oid newNspOid,
17983 bool hasDependEntry,
17989 bool already_done =
false;
17993 elog(
ERROR,
"cache lookup failed for relation %u", relOid);
17996 Assert(classForm->relnamespace == oldNspOid);
17998 thisobj.
classId = RelationRelationId;
18008 if (!already_done && oldNspOid != newNspOid)
18014 (
errcode(ERRCODE_DUPLICATE_TABLE),
18015 errmsg(
"relation \"%s\" already exists in schema \"%s\"",
18020 classForm->relnamespace = newNspOid;
18025 if (hasDependEntry &&
18028 NamespaceRelationId,
18031 elog(
ERROR,
"could not change schema dependency for relation \"%s\"",
18032 NameStr(classForm->relname));
18059 foreach(l, indexList)
18064 thisobj.
classId = RelationRelationId;
18079 oldNspOid, newNspOid,
18112 Anum_pg_depend_refclassid,
18116 Anum_pg_depend_refobjid,
18130 if (depForm->refobjsubid == 0 ||
18131 depForm->classid != RelationRelationId ||
18132 depForm->objsubid != 0 ||
18149 oldNspOid, newNspOid,
18225 if (oc->
relid == relid)
18243 List *oids_to_truncate =
NIL;
18284 if (oids_to_truncate !=
NIL)
18287 if (oids_to_drop !=
NIL)
18291 foreach(l, oids_to_drop)
18295 object.
classId = RelationRelationId;
18297 object.objectSubId = 0;
18319 #ifdef USE_ASSERT_CHECKING
18432 if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE &&
18433 relkind != RELKIND_MATVIEW && relkind != RELKIND_PARTITIONED_TABLE)
18435 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18436 errmsg(
"\"%s\" is not a table or materialized view", relation->
relname)));
18461 elog(
ERROR,
"cache lookup failed for relation %u", relId);
18485 elog(
ERROR,
"cache lookup failed for relation %u", relId);
18494 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
18495 errmsg(
"permission denied: \"%s\" is a system catalog",
18520 relkind = classform->relkind;
18529 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
18530 errmsg(
"permission denied: \"%s\" is a system catalog",
18541 aclresult =
object_aclcheck(NamespaceRelationId, classform->relnamespace,
18568 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18571 if (reltype ==
OBJECT_VIEW && relkind != RELKIND_VIEW)
18573 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18578 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18579 errmsg(
"\"%s\" is not a materialized view", rv->
relname)));
18583 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18586 if (reltype ==
OBJECT_TYPE && relkind != RELKIND_COMPOSITE_TYPE)
18588 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18591 if (reltype ==
OBJECT_INDEX && relkind != RELKIND_INDEX &&
18592 relkind != RELKIND_PARTITIONED_INDEX
18595 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18602 if (reltype !=
OBJECT_TYPE && relkind == RELKIND_COMPOSITE_TYPE)
18604 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18616 if (relkind == RELKIND_INDEX || relkind == RELKIND_PARTITIONED_INDEX)
18618 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18619 errmsg(
"cannot change schema of index \"%s\"",
18621 errhint(
"Change the schema of the table instead.")));
18622 else if (relkind == RELKIND_COMPOSITE_TYPE)
18624 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18625 errmsg(
"cannot change schema of composite type \"%s\"",
18630 else if (relkind == RELKIND_TOASTVALUE)
18632 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18633 errmsg(
"cannot change schema of TOAST table \"%s\"",
18635 errhint(
"Change the schema of the table instead.")));
18664 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18665 errmsg(
"cannot use \"list\" partition strategy with more than one column")));
18673 NULL,
false,
true);
18706 List **partexprs,
Oid *partopclass,
Oid *partcollation,
18714 foreach(lc, partParams)
18720 if (pelem->
name != NULL)
18730 (
errcode(ERRCODE_UNDEFINED_COLUMN),
18731 errmsg(
"column \"%s\" named in partition key does not exist",
18736 if (attform->attnum <= 0)
18738 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18739 errmsg(
"cannot use system column \"%s\" in partition key",
18747 if (attform->attgenerated)
18749 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18750 errmsg(
"cannot use generated column in partition key"),
18751 errdetail(
"Column \"%s\" is a generated column.",
18755 partattrs[attn] = attform->attnum;
18756 atttype = attform->atttypid;
18757 attcollation = attform->attcollation;
18764 char partattname[16];
18776 snprintf(partattname,
sizeof(partattname),
"%d", attn + 1);
18778 atttype, attcollation,
18789 ((
Var *) expr)->varattno > 0)
18795 partattrs[attn] = ((
Var *) expr)->varattno;
18802 partattrs[attn] = 0;
18803 *partexprs =
lappend(*partexprs, expr);
18822 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18823 errmsg(
"partition key expressions cannot contain system column references")));
18839 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18840 errmsg(
"cannot use generated column in partition key"),
18841 errdetail(
"Column \"%s\" is a generated column.",
18869 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18870 errmsg(
"functions in partition key expression must be marked IMMUTABLE")));
18878 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18879 errmsg(
"cannot use constant expression as partition key")));
18899 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
18900 errmsg(
"could not determine which collation to use for partition expression"),
18901 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
18907 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18908 errmsg(
"collations are not supported by type %s",
18912 partcollation[attn] = attcollation;
18920 am_oid = HASH_AM_OID;
18922 am_oid = BTREE_AM_OID;
18932 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18933 errmsg(
"data type %s has no default operator class for access method \"%s\"",
18935 errhint(
"You must specify a hash operator class or define a default hash operator class for the data type.")));
18938 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18939 errmsg(
"data type %s has no default operator class for access method \"%s\"",
18941 errhint(
"You must specify a btree operator class or define a default btree operator class for the data type.")));
18947 am_oid == HASH_AM_OID ?
"hash" :
"btree",
18964 List *partConstraint)
18974 for (
i = 1;
i <= natts;
i++)
18978 if (att->attnotnull && !att->attisdropped)
18995 ntest->argisrow =
false;
18997 existConstraint =
lappend(existConstraint, ntest);
19023 num_check = (constr != NULL) ? constr->
num_check : 0;
19024 for (
i = 0;
i < num_check;
i++)
19074 List *partConstraint,
19075 bool validate_default)
19083 if (!validate_default)
19085 (
errmsg_internal(
"partition constraint for table \"%s\" is implied by existing constraints",
19089 (
errmsg_internal(
"updated partition constraint for default partition \"%s\" is implied by existing constraints",
19099 if (scanrel->
rd_rel->relkind == RELKIND_RELATION)
19109 else if (scanrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
19117 List *thisPartConstraint;
19128 thisPartConstraint =
19130 part_rel, scanrel);
19133 thisPartConstraint,
19182 List *attachrel_children;
19183 List *partConstraint;
19190 const char *trigger_name;
19191 Oid defaultPartOid;
19192 List *partBoundConstraint;
19220 if (attachrel->
rd_rel->relispartition)
19222 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19223 errmsg(
"\"%s\" is already a partition",
19228 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19229 errmsg(
"cannot attach a typed table as partition")));
19237 Anum_pg_inherits_inhrelid,
19244 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19245 errmsg(
"cannot attach inheritance child as partition")));
19250 Anum_pg_inherits_inhparent,
19256 attachrel->
rd_rel->relkind == RELKIND_RELATION)
19258 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19259 errmsg(
"cannot attach inheritance parent as partition")));
19282 (
errcode(ERRCODE_DUPLICATE_TABLE),
19283 errmsg(
"circular inheritance not allowed"),
19284 errdetail(
"\"%s\" is already a child of \"%s\".",
19289 if (rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
19290 attachrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
19292 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19293 errmsg(
"cannot attach a temporary relation as partition of permanent relation \"%s\"",
19297 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
19298 attachrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
19300 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19301 errmsg(
"cannot attach a permanent relation as partition of temporary relation \"%s\"",
19305 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
19308 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19309 errmsg(
"cannot attach as partition of temporary relation of another session")));
19312 if (attachrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
19315 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19316 errmsg(
"cannot attach temporary relation of another session as partition")));
19323 natts = tupleDesc->
natts;
19324 for (attno = 1; attno <= natts; attno++)
19327 char *attributeName =
NameStr(attribute->attname);
19330 if (attribute->attisdropped)
19333 if (attribute->attidentity)
19335 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19336 errmsg(
"table \"%s\" being attached contains an identity column \"%s\"",
19338 errdetail(
"The new partition may not contain an identity column."));
19345 (
errcode(ERRCODE_DATATYPE_MISMATCH),
19346 errmsg(
"table \"%s\" contains column \"%s\" not found in parent \"%s\"",
19349 errdetail(
"The new partition may contain only the columns present in parent.")));
19358 if (trigger_name != NULL)
19360 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
19361 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming a partition",
19363 errdetail(
"ROW triggers with transition tables are not supported on partitions.")));
19371 cmd->
bound, pstate);
19382 partConstraint =
list_concat(partBoundConstraint,
19386 if (partConstraint)
19395 (
Node *) partConstraint);
19422 List *defPartConstraint;
19428 defPartConstraint =
19435 defPartConstraint =
19437 1, defaultrel, rel);
19439 defPartConstraint,
true);
19453 if (attachrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
19457 foreach(l, attachrel_children)
19481 List *attachRelIdxs;
19489 "AttachPartitionEnsureIndexes",
19499 foreach(cell, attachRelIdxs)
19514 if (attachrel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
19516 foreach(cell, idxes)
19521 if (idxRel->
rd_index->indisunique ||
19524 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
19525 errmsg(
"cannot attach foreign table \"%s\" as partition of partitioned table \"%s\"",
19528 errdetail(
"Partitioned table \"%s\" contains unique indexes.",
19540 foreach(cell, idxes)
19546 bool found =
false;
19553 if (idxRel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
19577 if (attachrelIdxRels[
i]->rd_rel->relispartition)
19581 if (!attachrelIdxRels[
i]->rd_index->indisvalid)
19585 attachrelIdxRels[
i]->rd_indcollation,
19662 true,
false,
false,
false,
false);
19694 true, NULL, 1, &
key);
19713 if (!TRIGGER_FOR_ROW(trigForm->tgtype))
19720 if (trigForm->tgisinternal)
19726 if (!TRIGGER_FOR_BEFORE(trigForm->tgtype) &&
19727 !TRIGGER_FOR_AFTER(trigForm->tgtype))
19728 elog(
ERROR,
"unexpected trigger \"%s\" found",
19744 partition, parent);
19746 partition, parent);
19753 if (trigForm->tgattr.dim1 > 0)
19757 for (
i = 0;
i < trigForm->tgattr.dim1;
i++)
19762 trigForm->tgattr.values[
i] - 1);
19769 if (trigForm->tgnargs > 0)
19776 elog(
ERROR,
"tgargs is null for trigger \"%s\" in partition \"%s\"",
19781 for (
int i = 0;
i < trigForm->tgnargs;
i++)
19784 p += strlen(p) + 1;
19794 trigStmt->
args = trigargs;
19795 trigStmt->
row =
true;
19796 trigStmt->
timing = trigForm->tgtype & TRIGGER_TYPE_TIMING_MASK;
19797 trigStmt->
events = trigForm->tgtype & TRIGGER_TYPE_EVENT_MASK;
19801 trigStmt->
deferrable = trigForm->tgdeferrable;
19807 trigForm->tgfoid, trigForm->oid, qual,
19808 false,
true, trigForm->tgenabled);
19844 Oid defaultPartOid;
19871 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19872 errmsg(
"cannot detach partitions concurrently when a default partition exists")));
19914 char *parentrelname;
19976 if (partRel != NULL)
19977 elog(
WARNING,
"dangling partition \"%s\" remains, can't fix",
19980 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19981 errmsg(
"partitioned table \"%s\" was removed concurrently",
19984 if (partRel == NULL)
19986 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19987 errmsg(
"partition \"%s\" was removed concurrently", partrelname)));
20011 Oid defaultPartOid)
20017 Datum new_val[Natts_pg_class];
20018 bool new_null[Natts_pg_class],
20019 new_repl[Natts_pg_class];
20049 Oid insertTriggerOid,
20058 if (conform->contype != CONSTRAINT_FOREIGN ||
20074 &insertTriggerOid, &updateTriggerOid);
20088 fkconstraint->
contype = CONSTRAINT_FOREIGN;
20090 fkconstraint->
deferrable = conform->condeferrable;
20093 fkconstraint->
pktable = NULL;
20106 fkconstraint, fk->
conoid,
20130 ConstraintRelationId,
20140 foreach(cell, indexes)
20169 elog(
ERROR,
"cache lookup failed for relation %u",
20174 memset(new_val, 0,
sizeof(new_val));
20175 memset(new_null,
false,
sizeof(new_null));
20176 memset(new_repl,
false,
sizeof(new_repl));
20177 new_val[Anum_pg_class_relpartbound - 1] = (
Datum) 0;
20178 new_null[Anum_pg_class_relpartbound - 1] =
true;
20179 new_repl[Anum_pg_class_relpartbound - 1] =
true;
20181 new_val, new_null, new_repl);
20195 if (!attr->attisdropped && attr->attidentity)
20229 if (partRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
20235 foreach(cell, children)
20286 List *constraintExpr;
20342 true, NULL, 1, &skey);
20368 RelationRelationId,
20407 if (!
state->lockedParentTbl)
20410 state->lockedParentTbl =
true;
20433 if (classform->relkind != RELKIND_PARTITIONED_INDEX &&
20434 classform->relkind != RELKIND_INDEX)
20436 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
20471 state.lockedParentTbl =
false;
20479 (
errcode(ERRCODE_UNDEFINED_OBJECT),
20480 errmsg(
"index \"%s\" does not exist",
name->relname)));
20492 currParent = partIdx->
rd_rel->relispartition ?
20513 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20514 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20517 errdetail(
"Index \"%s\" is already attached to another index.",
20525 if (partDesc->
oids[
i] ==
state.partitionOid)
20533 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20534 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20537 errdetail(
"Index \"%s\" is not an index on any partition of table \"%s\".",
20554 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
20555 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20558 errdetail(
"The index definitions do not match.")));
20573 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
20574 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20577 errdetail(
"The index \"%s\" belongs to a constraint in table \"%s\" but no constraint exists for index \"%s\".",
20587 if (parentIdx->
rd_index->indisprimary)
20622 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20623 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20626 errdetail(
"Another index is already attached for partition \"%s\".",
20644 bool updated =
false;
20646 Assert(partedIdx->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX);
20668 elog(
ERROR,
"cache lookup failed for index %u", inhForm->inhrelid);
20670 if (indexForm->indisvalid)
20693 elog(
ERROR,
"cache lookup failed for index %u",
20697 indexForm->indisvalid =
true;
20710 if (updated && partedIdx->
rd_rel->relispartition)
20746 if (!att->attnotnull)
20748 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
20749 errmsg(
"invalid primary key definition"),
20750 errdetail(
"Column \"%s\" of relation \"%s\" is not marked NOT NULL.",
20799 constraints =
lappend_oid(constraints, constrForm->oid);
20805 return constraints;
20821 foreach(cell, constraints)
20831 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
20867 if (compression == NULL || strcmp(compression,
"default") == 0)
20884 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20885 errmsg(
"column data type %s does not support compression",
20891 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20892 errmsg(
"invalid compression method \"%s\"", compression)));
20906 cstorage = TYPSTORAGE_PLAIN;
20908 cstorage = TYPSTORAGE_EXTERNAL;
20910 cstorage = TYPSTORAGE_EXTENDED;
20912 cstorage = TYPSTORAGE_MAIN;
20917 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20918 errmsg(
"invalid storage type \"%s\"",
20927 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20928 errmsg(
"column data type %s can only have storage PLAIN",
21013 bool isOldDefaultPart =
false;
21019 forboth(listptr, partlist, listptr2, newPartRels)
21028 defaultPartCtx = pc;
21032 List *partConstraint;
21038 (
Node *) partConstraint);
21049 pc->partqualstate =
21051 Assert(pc->partqualstate != NULL);
21055 partContexts =
lappend(partContexts, pc);
21062 if (!defaultPartCtx &&
OidIsValid(defaultPartOid))
21065 isOldDefaultPart =
true;
21096 bool found =
false;
21105 foreach(listptr, partContexts)
21109 if (pc->partqualstate &&
21110 ExecCheck(pc->partqualstate, econtext))
21120 if (defaultPartCtx)
21121 pc = defaultPartCtx;
21124 (
errcode(ERRCODE_CHECK_VIOLATION),
21125 errmsg(
"can not find partition for split partition row"),
21137 insertslot = pc->dstslot;
21151 ti_options, pc->bistate);
21170 foreach(listptr, partContexts)
21174 if (isOldDefaultPart)
21200 createStmt->
relation = newPartName;
21251 bool isSameName =
false;
21256 Oid defaultPartOid;
21271 Oid existing_relid;
21290 if (existing_relid == splitRelOid && !isSameName)
21295 (
errcode(ERRCODE_DUPLICATE_TABLE),
21339 newPartRels =
lappend(newPartRels, newPartRel);
21363 object.classId = RelationRelationId;
21364 object.objectId = splitRelOid;
21365 object.objectSubId = 0;
21397 foreach(listptr, mergingPartitionsList)
21435 insertslot = dstslot;
21449 ti_options, bistate);
21478 List *mergingPartitionsList =
NIL;
21479 Oid defaultPartOid;
21482 bool isSameName =
false;
21508 mergingPartitionsList =
lappend(mergingPartitionsList,
21515 foreach(listptr, mergingPartitionsList)
21556 foreach(listptr, mergingPartitionsList)
21563 object.classId = RelationRelationId;
21564 object.objectSubId = 0;
Datum idx(PG_FUNCTION_ARGS)
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
void check_can_set_role(Oid member, Oid role)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Oid get_table_am_oid(const char *amname, bool missing_ok)
#define DatumGetArrayTypeP(X)
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
void free_attrmap(AttrMap *map)
AttrMap * make_attrmap(int maplen)
AttrMap * build_attrmap_by_name_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
#define InvalidAttrNumber
char * get_tablespace_name(Oid spc_oid)
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Oid GetDefaultTablespace(char relpersistence, bool partitioned)
List * roleSpecsToIds(List *memberNames)
List * raw_parser(const char *str, RawParseMode mode)
bool TimestampTimestampTzRequiresRewrite(void)
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
void FlushRelationBuffers(Relation rel)
#define TextDatumGetCString(d)
#define InvalidSubTransactionId
#define Assert(condition)
#define PointerIsValid(pointer)
#define MemSet(start, val, len)
#define OidIsValid(objectId)
bool IsToastNamespace(Oid namespaceId)
bool IsSystemRelation(Relation relation)
RelFileNumber GetNewRelFileNumber(Oid reltablespace, Relation pg_class, char relpersistence)
bool IsCatalogNamespace(Oid namespaceId)
bool IsSystemClass(Oid relid, Form_pg_class reltuple)
bool contain_mutable_functions(Node *clause)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
void check_index_is_clusterable(Relation OldHeap, Oid indexOid, LOCKMODE lockmode)
void finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, bool is_system_catalog, bool swap_toast_by_content, bool check_constraints, bool is_internal, TransactionId frozenXid, MultiXactId cutoffMulti, char newrelpersistence)
Oid make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, Oid NewAccessMethod, char relpersistence, LOCKMODE lockmode)
void mark_index_clustered(Relation rel, Oid indexOid, bool is_internal)
void ResetSequence(Oid seq_relid)
void SequenceChangePersistence(Oid relid, char newrelpersistence)
int32 defGetInt32(DefElem *def)
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
void free_object_addresses(ObjectAddresses *addrs)
#define PERFORM_DELETION_CONCURRENTLY
@ DEPENDENCY_PARTITION_PRI
@ DEPENDENCY_PARTITION_SEC
#define PERFORM_DELETION_QUIETLY
#define PERFORM_DELETION_INTERNAL
DestReceiver * None_Receiver
void hash_destroy(HTAB *hashp)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
void EventTriggerAlterTableStart(Node *parsetree)
void EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
void EventTriggerAlterTableRelid(Oid objectId)
void EventTriggerAlterTableEnd(void)
void EventTriggerCollectAlterTableSubcmd(Node *subcmd, ObjectAddress address)
#define AT_REWRITE_ALTER_PERSISTENCE
#define AT_REWRITE_DEFAULT_VAL
#define AT_REWRITE_ACCESS_METHOD
#define AT_REWRITE_COLUMN_REWRITE
ExprState * ExecPrepareExpr(Expr *node, EState *estate)
bool ExecCheck(ExprState *state, ExprContext *econtext)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, ResultRelInfo *partition_root_rri, int instrument_options)
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
HeapTuple ExecFetchSlotHeapTuple(TupleTableSlot *slot, bool materialize, bool *shouldFree)
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
EState * CreateExecutorState(void)
void FreeExecutorState(EState *estate)
struct ResultRelInfo ResultRelInfo
#define GetPerTupleExprContext(estate)
#define ResetExprContext(econtext)
#define GetPerTupleMemoryContext(estate)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
#define palloc0_object(type)
#define DirectFunctionCall2(func, arg1, arg2)
#define DatumGetByteaPP(X)
#define SizeForFunctionCallInfo(nargs)
#define LOCAL_FCINFO(name, nargs)
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
ForeignServer * GetForeignServer(Oid serverid)
Oid GetForeignServerIdByRelId(Oid relid)
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Datum transformGenericOptions(Oid catalogId, Datum oldOptions, List *options, Oid fdwvalidator)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
StrategyNumber GistTranslateStratnum(Oid opclass, StrategyNumber strat)
bool allowSystemTableMods
void RelationClearMissing(Relation rel)
void StorePartitionKey(Relation rel, char strategy, int16 partnatts, AttrNumber *partattrs, List *partexprs, Oid *partopclass, Oid *partcollation)
List * heap_truncate_find_FKs(List *relationIds)
void RemoveStatistics(Oid relid, AttrNumber attnum)
List * AddRelationNotNullConstraints(Relation rel, List *constraints, List *old_notnulls)
Oid heap_create_with_catalog(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, Oid reltypeid, Oid reloftypeid, Oid ownerid, Oid accessmtd, TupleDesc tupdesc, List *cooked_constraints, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, OnCommitAction oncommit, Datum reloptions, bool use_user_acl, bool allow_system_table_mods, bool is_internal, Oid relrewrite, ObjectAddress *typaddress)
void heap_truncate(List *relids)
void CheckAttributeType(const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, int flags)
void heap_truncate_check_FKs(List *relations, bool tempTables)
void StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
void InsertPgAttributeTuples(Relation pg_attribute_rel, TupleDesc tupdesc, Oid new_rel_oid, const FormExtraData_pg_attribute tupdesc_extra[], CatalogIndexState indstate)
void heap_truncate_one_rel(Relation rel)
List * AddRelationNewConstraints(Relation rel, List *newColDefaults, List *newConstraints, bool allow_merge, bool is_local, bool is_internal, const char *queryString)
#define CHKATYPE_IS_PARTKEY
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
BulkInsertState GetBulkInsertState(void)
void FreeBulkInsertState(BulkInsertState bistate)
#define XLOG_HEAP_TRUNCATE
#define XLH_TRUNCATE_RESTART_SEQS
#define SizeOfHeapTruncate
#define XLH_TRUNCATE_CASCADE
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
HeapTuple heap_copytuple(HeapTuple tuple)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
#define MaxHeapAttributeNumber
Oid IndexGetRelation(Oid indexId, bool missing_ok)
bool CompareIndexInfo(const IndexInfo *info1, const IndexInfo *info2, const Oid *collations1, const Oid *collations2, const Oid *opfamilies1, const Oid *opfamilies2, const AttrMap *attmap)
bool reindex_relation(const ReindexStmt *stmt, Oid relid, int flags, const ReindexParams *params)
void index_check_primary_key(Relation heapRel, const IndexInfo *indexInfo, bool is_alter_table, const IndexStmt *stmt)
ObjectAddress index_constraint_create(Relation heapRelation, Oid indexRelationId, Oid parentConstraintId, const IndexInfo *indexInfo, const char *constraintName, char constraintType, bits16 constr_flags, bool allow_system_table_mods, bool is_internal)
IndexInfo * BuildIndexInfo(Relation index)
#define REINDEX_REL_PROCESS_TOAST
#define INDEX_CONSTR_CREATE_UPDATE_INDEX
#define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS
#define INDEX_CONSTR_CREATE_DEFERRABLE
#define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY
#define INDEX_CONSTR_CREATE_INIT_DEFERRED
void index_close(Relation relation, LOCKMODE lockmode)
Relation index_open(Oid relationId, LOCKMODE lockmode)
ObjectAddress DefineIndex(Oid tableId, IndexStmt *stmt, Oid indexRelationId, Oid parentIndexId, Oid parentConstraintId, int total_parts, bool is_alter_table, bool check_rights, bool check_not_in_use, bool skip_build, bool quiet)
void IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
bool CheckIndexCompatible(Oid oldId, const char *accessMethodName, const List *attributeList, const List *exclusionOpNames, bool isWithoutOverlaps)
void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
Oid ResolveOpClass(const List *opclass, Oid attrType, const char *accessMethodName, Oid accessMethodId)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
void AcceptInvalidationMessages(void)
void CacheInvalidateRelcache(Relation relation)
void CacheInvalidateRelcacheByRelid(Oid relid)
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
if(TABLE==NULL||TABLE_index==NULL)
List * list_difference_ptr(const List *list1, const List *list2)
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
List * list_copy(const List *oldlist)
List * list_delete_nth_cell(List *list, int n)
void list_free(List *list)
bool list_member_oid(const List *list, Oid datum)
List * list_concat(List *list1, const List *list2)
List * lcons(void *datum, List *list)
List * list_append_unique_oid(List *list, Oid datum)
void list_free_deep(List *list)
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
#define AccessExclusiveLock
#define ShareRowExclusiveLock
#define ShareUpdateExclusiveLock
AttrNumber get_attnum(Oid relid, const char *attname)
Oid get_constraint_index(Oid conoid)
char * get_namespace_name(Oid nspid)
char get_typstorage(Oid typid)
bool get_index_isreplident(Oid index_oid)
char get_rel_relkind(Oid relid)
Oid get_typcollation(Oid typid)
char * get_rel_name(Oid relid)
bool get_index_isclustered(Oid index_oid)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
char * get_collation_name(Oid colloid)
char * get_constraint_name(Oid conoid)
Oid get_rel_relam(Oid relid)
bool type_is_collatable(Oid typid)
Oid get_rel_tablespace(Oid relid)
Oid get_typ_typrelid(Oid typid)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Oid getBaseType(Oid typid)
char get_constraint_type(Oid conoid)
Oid get_relname_relid(const char *relname, Oid relnamespace)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
#define TypeIsToastable(typid)
List * make_ands_implicit(Expr *clause)
TypeName * makeTypeNameFromNameList(List *names)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
ColumnDef * makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Expr * make_ands_explicit(List *andclauses)
void MemoryContextReset(MemoryContext context)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
char * MemoryContextStrdup(MemoryContext context, const char *string)
MemoryContext CacheMemoryContext
void MemoryContextDelete(MemoryContext context)
MemoryContext PortalContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define ALLOCSET_SMALL_SIZES
#define CHECK_FOR_INTERRUPTS()
bool InSecurityRestrictedOperation(void)
MultiXactId ReadNextMultiXactId(void)
void namestrcpy(Name name, const char *str)
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
bool isAnyTempNamespace(Oid namespaceId)
Oid get_collation_oid(List *collname, bool missing_ok)
void CheckSetNamespace(Oid oldNspOid, Oid nspOid)
RangeVar * makeRangeVarFromNameList(const List *names)
Oid LookupNamespaceNoError(const char *nspname)
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Oid exprType(const Node *expr)
Oid exprCollation(const Node *expr)
Node * strip_implicit_coercions(Node *node)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectTruncateHook(objectId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
#define InvokeObjectPostAlterHookArg(classId, objectId, subId, auxiliaryId, is_internal)
ObjectType get_relkind_objtype(char relkind)
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
char * nodeToString(const void *obj)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
CoercionPathType find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
@ COERCION_PATH_RELABELTYPE
void assign_expr_collations(ParseState *pstate, Node *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
int parser_errposition(ParseState *pstate, int location)
ParseState * make_parsestate(ParseState *parentParseState)
@ EXPR_KIND_PARTITION_EXPRESSION
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
const NameData * attnumAttName(Relation rd, int attid)
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
Oid attnumTypeId(Relation rd, int attid)
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
Type typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
Oid GetColumnDefCollation(ParseState *pstate, const ColumnDef *coldef, Oid typeOid)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
IndexStmt * generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx, const AttrMap *attmap, Oid *constraintOid)
CreateStatsStmt * transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
AlterTableStmt * transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, const char *queryString, List **beforeStmts, List **afterStmts)
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
PartitionBoundSpec * transformPartitionBound(ParseState *pstate, Relation parent, PartitionBoundSpec *spec)
#define FKCONSTR_ACTION_RESTRICT
#define FKCONSTR_ACTION_SETDEFAULT
@ PARTITION_STRATEGY_HASH
@ PARTITION_STRATEGY_LIST
@ AT_DetachPartitionFinalize
@ AT_ReAddDomainConstraint
@ AT_AlterColumnGenericOptions
#define FKCONSTR_ACTION_CASCADE
#define FKCONSTR_ACTION_SETNULL
@ CREATE_TABLE_LIKE_IDENTITY
@ CREATE_TABLE_LIKE_INDEXES
#define FKCONSTR_ACTION_NOACTION
List * SystemFuncName(char *name)
void check_new_partition_bound(char *relname, Relation parent, PartitionBoundSpec *spec, ParseState *pstate)
List * get_qual_from_partbound(Relation parent, PartitionBoundSpec *spec)
void check_default_partition_contents(Relation parent, Relation default_rel, PartitionBoundSpec *new_spec)
List * RelationGetPartitionQual(Relation rel)
PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached)
Oid get_default_oid_from_partdesc(PartitionDesc partdesc)
bool has_partition_attrs(Relation rel, Bitmapset *attnums, bool *used_in_expr)
List * map_partition_varattnos(List *expr, int fromrel_varno, Relation to_rel, Relation from_rel)
List * get_proposed_default_constraint(List *new_part_constraints)
void update_default_partition_oid(Oid parentId, Oid defaultPartId)
Oid index_get_partition(Relation partition, Oid indexId)
Oid get_partition_parent(Oid relid, bool even_if_detached)
Oid GetAttrDefaultOid(Oid relid, AttrNumber attnum)
Oid StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr, bool is_internal, bool add_column_mode)
ObjectAddress GetAttrDefaultColumnAddress(Oid attrdefoid)
void RemoveAttrDefault(Oid relid, AttrNumber attnum, DropBehavior behavior, bool complain, bool internal)
FormData_pg_attribute * Form_pg_attribute
int errdetail_relkind_not_supported(char relkind)
FormData_pg_class * Form_pg_class
#define PARTITION_MAX_KEYS
char * ChooseConstraintName(const char *name1, const char *name2, const char *label, Oid namespaceid, List *others)
HeapTuple findNotNullConstraint(Oid relid, const char *colname)
bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)
Oid CreateConstraintEntry(const char *constraintName, Oid constraintNamespace, char constraintType, bool isDeferrable, bool isDeferred, bool isValidated, Oid parentConstrId, Oid relId, const int16 *constraintKey, int constraintNKeys, int constraintNTotalKeys, Oid domainId, Oid indexRelId, Oid foreignRelId, const int16 *foreignKey, const Oid *pfEqOp, const Oid *ppEqOp, const Oid *ffEqOp, int foreignNKeys, char foreignUpdateType, char foreignDeleteType, const int16 *fkDeleteSetCols, int numFkDeleteSetCols, char foreignMatchType, const Oid *exclOp, Node *conExpr, const char *conBin, bool conIsLocal, int conInhCount, bool conNoInherit, bool conPeriod, bool is_internal)
void RenameConstraintById(Oid conId, const char *newname)
Oid get_relation_idx_constraint_oid(Oid relationId, Oid indexId)
void ConstraintSetParentConstraint(Oid childConstrId, Oid parentConstrId, Oid childTableId)
List * RelationGetNotNullConstraints(Oid relid, bool cooked)
void DeconstructFkConstraintRow(HeapTuple tuple, int *numfks, AttrNumber *conkey, AttrNumber *confkey, Oid *pf_eq_oprs, Oid *pp_eq_oprs, Oid *ff_eq_oprs, int *num_fk_del_set_cols, AttrNumber *fk_del_set_cols)
void AdjustNotNullInheritance(Oid relid, Bitmapset *columns, int count)
HeapTuple findNotNullConstraintAttnum(Oid relid, AttrNumber attnum)
void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, Oid newNspId, bool isType, ObjectAddresses *objsMoved)
void FindFKPeriodOpers(Oid opclass, Oid *containedbyoperoid, Oid *aggedcontainedbyoperoid)
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
AttrNumber extractNotNullColumn(HeapTuple constrTup)
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
FormData_pg_constraint * Form_pg_constraint
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
Oid get_index_constraint(Oid indexId)
Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
List * getOwnedSequences(Oid relid)
bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId)
FormData_pg_depend * Form_pg_depend
FormData_pg_foreign_table * Form_pg_foreign_table
FormData_pg_index * Form_pg_index
bool DeleteInheritsTuple(Oid inhrelid, Oid inhparent, bool expect_detach_pending, const char *childname)
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
void StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)
List * find_inheritance_children(Oid parentrelId, LOCKMODE lockmode)
bool has_superclass(Oid relationId)
bool PartitionHasPendingDetach(Oid partoid)
FormData_pg_inherits * Form_pg_inherits
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
#define foreach_current_index(var_or_cell)
#define foreach_delete_current(lst, var_or_cell)
#define list_make1_oid(x1)
#define foreach_ptr(type, var, lst)
static ListCell * list_head(const List *l)
#define for_each_from(cell, lst, N)
#define list_make3(x1, x2, x3)
#define foreach_node(type, var, lst)
static void * list_nth(const List *list, int n)
#define foreach_oid(var, lst)
#define list_nth_node(type, list, n)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make1_int(x1)
#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)
FormData_pg_trigger * Form_pg_trigger
void RenameTypeInternal(Oid typeOid, const char *newTypeName, Oid typeNamespace)
FormData_pg_type * Form_pg_type
#define ERRCODE_UNDEFINED_TABLE
void pgstat_count_truncate(Relation rel)
Expr * expression_planner(Expr *expr)
int pg_strcasecmp(const char *s1, const char *s2)
size_t strlcpy(char *dst, const char *src, size_t siz)
void check_stack_depth(void)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static Datum CharGetDatum(char X)
void CheckTableForSerializableConflictIn(Relation relation)
void TransferPredicateLocksToHeapRelation(Relation relation)
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Expr * canonicalize_qual(Expr *qual, bool is_check)
MemoryContextSwitchTo(old_ctx)
void * stringToNode(const char *str)
#define RelationGetForm(relation)
#define RelationGetRelid(relation)
#define RelationIsLogicallyLogged(relation)
#define RelationIsUsedAsCatalogTable(relation)
static SMgrRelation RelationGetSmgr(Relation rel)
#define RelationGetDescr(relation)
#define RelationIsMapped(relation)
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
#define RELATION_IS_OTHER_TEMP(relation)
#define RelationGetNamespace(relation)
#define IndexRelationGetNumberOfKeyAttributes(relation)
#define RelationIsPermanent(relation)
List * RelationGetIndexList(Relation relation)
int errtableconstraint(Relation rel, const char *conname)
int errtablecol(Relation rel, int attnum)
List * RelationGetIndexPredicate(Relation relation)
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
List * RelationGetFKeyList(Relation relation)
void RelationSetNewRelfilenumber(Relation relation, char persistence)
void RelationAssumeNewRelfilelocator(Relation relation)
int errtable(Relation rel)
List * RelationGetIndexExpressions(Relation relation)
struct RelationData * Relation
@ INDEX_ATTR_BITMAP_PRIMARY_KEY
@ INDEX_ATTR_BITMAP_IDENTITY_KEY
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
List * untransformRelOptions(Datum options)
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
bytea * view_reloptions(Datum reloptions, bool validate)
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
LOCKMODE AlterTableGetRelOptionsLockLevel(List *defList)
bytea * attribute_reloptions(Datum reloptions, bool validate)
#define HEAP_RELOPT_NAMESPACES
#define RelFileNumberIsValid(relnumber)
void EnableDisableRule(Relation rel, const char *rulename, char fires_when)
#define RULE_FIRES_ON_ORIGIN
#define RULE_FIRES_ON_REPLICA
#define RULE_FIRES_ALWAYS
const char * view_query_is_auto_updatable(Query *viewquery, bool check_cols)
Query * get_view_query(Relation view)
Node * build_column_default(Relation rel, int attrno)
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
Datum RI_FKey_check_ins(PG_FUNCTION_ARGS)
bool RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
void RI_PartitionRemove_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
int RI_FKey_trigger_type(Oid tgfoid)
char * pg_get_constraintdef_command(Oid constraintId)
const char * quote_identifier(const char *ident)
char * pg_get_statisticsobjdef_string(Oid statextid)
Datum pg_get_expr(PG_FUNCTION_ARGS)
char * pg_get_indexdef_string(Oid indexrelid)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
void smgrclose(SMgrRelation reln)
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Snapshot GetTransactionSnapshot(void)
Snapshot GetLatestSnapshot(void)
void UnregisterSnapshot(Snapshot snapshot)
void PushActiveSnapshot(Snapshot snapshot)
Snapshot RegisterSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
Snapshot GetActiveSnapshot(void)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation try_relation_open(Oid relationId, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
ObjectAddress CreateStatistics(CreateStatsStmt *stmt)
Oid StatisticsGetRelation(Oid statId, bool missing_ok)
void RelationPreserveStorage(RelFileLocator rlocator, bool atCommit)
void RelationCopyStorage(SMgrRelation src, SMgrRelation dst, ForkNumber forkNum, char relpersistence)
SMgrRelation RelationCreateStorage(RelFileLocator rlocator, char relpersistence, bool register_delete)
void log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum)
void RelationDropStorage(Relation rel)
#define RTOverlapStrategyNumber
#define RTEqualStrategyNumber
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
List * changedConstraintDefs
Expr * partition_constraint
List * changedStatisticsDefs
char * replicaIdentityIndex
List * changedStatisticsOids
List * changedConstraintOids
List * subcmds[AT_NUM_PASSES]
RangeVar * identitySequence
bool reset_default_tblspc
char actual_relpersistence
List * es_opened_result_relations
TupleTableSlot * ecxt_scantuple
ExecForeignTruncate_function ExecForeignTruncate
amoptions_function amoptions
AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS]
bool reset_default_tblspc
NullTestType nulltesttype
SubTransactionId creating_subid
SubTransactionId deleting_subid
const char * p_sourcetext
PartitionBoundSpec * bound
PartitionStrategy strategy
struct IndexAmRoutine * rd_indam
SubTransactionId rd_firstRelfilelocatorSubid
SubTransactionId rd_newRelfilelocatorSubid
SubTransactionId rd_createSubid
RelFileLocator rd_locator
PartitionBoundSpec * bound
ExprState * partqualstate
TupleTableSlot * tg_trigslot
bool has_generated_stored
struct AttrMissing * missing
const char * skipping_msg
const char * nonexistent_msg
const char * drophint_msg
Oid values[FLEXIBLE_ARRAY_MEMBER]
#define FirstLowInvalidHeapAttributeNumber
HeapTuple SearchSysCacheCopyAttName(Oid relid, const char *attname)
HeapTuple SearchSysCacheCopyAttNum(Oid relid, int16 attnum)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
HeapTuple SearchSysCacheAttNum(Oid relid, int16 attnum)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
bool SearchSysCacheExistsAttName(Oid relid, const char *attname)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
#define SearchSysCacheCopy1(cacheId, key1)
#define SearchSysCacheExists2(cacheId, key1, key2)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
char * default_table_access_method
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
static void table_endscan(TableScanDesc scan)
#define TABLE_INSERT_SKIP_FSM
static void table_finish_bulk_insert(Relation rel, int options)
static void table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
static void table_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
static AttrNumber renameatt_internal(Oid myrelid, const char *oldattname, const char *newattname, bool recurse, bool recursing, int expected_parents, DropBehavior behavior)
void ResetRelRewrite(Oid myrelid)
static void MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel, bool ispartition)
static void MarkInheritDetached(Relation child_rel, Relation parent_rel)
static ObjectAddress ATExecAlterColumnGenericOptions(Relation rel, const char *colName, List *options, LOCKMODE lockmode)
static void ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode, AlterTableUtilityContext *context)
static ObjectAddress ATExecAddInherit(Relation child_rel, RangeVar *parent, LOCKMODE lockmode)
ObjectAddress RenameRelation(RenameStmt *stmt)
static AlteredTableInfo * ATGetQueueEntry(List **wqueue, Relation rel)
static void ATExecDropOf(Relation rel, LOCKMODE lockmode)
static ColumnDef * MergeInheritedAttribute(List *inh_columns, int exist_attno, const ColumnDef *newdef)
static 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 drop_parent_dependency(Oid relid, Oid refclassid, Oid refobjid, DependencyType deptype)
static void RemoveInheritance(Relation child_rel, Relation parent_rel, bool expect_detached)
void PreCommit_on_commit_actions(void)
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 int transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, List **attnamelist, int16 *attnums, Oid *atttypids, Oid *opclasses, bool *pk_has_without_overlaps)
static void createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName, AlterTableUtilityContext *context)
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 ObjectAddress ATExecSetNotNull(List **wqueue, Relation rel, char *constrname, char *colName, bool recurse, bool recursing, List **readyRels, LOCKMODE lockmode)
static List * GetParentedForeignKeyRefs(Relation partition)
void AlterRelationNamespaceInternal(Relation classRel, Oid relOid, Oid oldNspOid, Oid newNspOid, bool hasDependEntry, ObjectAddresses *objsMoved)
static ObjectAddress ATExecAddConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *newConstraint, bool recurse, bool is_readd, LOCKMODE lockmode)
ObjectAddress renameatt(RenameStmt *stmt)
void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lockmode)
static void RangeVarCallbackForAlterRelation(const RangeVar *rv, Oid relid, Oid oldrelid, void *arg)
static ObjectAddress ATExecSetAttNotNull(List **wqueue, Relation rel, const char *colName, LOCKMODE lockmode)
static void DropErrorMsgWrongType(const char *relname, char wrongkind, char rightkind)
LOCKMODE AlterTableGetLockLevel(List *cmds)
static int transformColumnNameList(Oid relId, List *colList, int16 *attnums, Oid *atttypids)
static void verifyPartitionIndexNotNull(IndexInfo *iinfo, Relation partIdx)
struct ForeignTruncateInfo ForeignTruncateInfo
static ObjectAddress ATExecDetachPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, RangeVar *name, bool concurrent)
static bool ATExecAlterConstrRecurse(Constraint *cmdcon, Relation conrel, Relation tgrel, Relation rel, HeapTuple contuple, List **otherrelids, LOCKMODE lockmode)
static void AlterSeqNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved, LOCKMODE lockmode)
static void RangeVarCallbackForRenameAttribute(const RangeVar *rv, Oid relid, Oid oldrelid, void *arg)
TupleDesc BuildDescForRelation(const List *columns)
static void attachPartitionTable(List **wqueue, Relation rel, Relation attachrel, PartitionBoundSpec *bound)
static void ATExecForceNoForceRowSecurity(Relation rel, bool force_rls)
void AtEOXact_on_commit_actions(bool isCommit)
static void checkFkeyPermissions(Relation rel, int16 *attnums, int natts)
struct OnCommitItem OnCommitItem
void CheckTableNotInUse(Relation rel, const char *stmt)
static ObjectAddress addFkRecurseReferenced(List **wqueue, Constraint *fkconstraint, Relation rel, Relation pkrel, Oid indexOid, Oid parentConstr, int numfks, int16 *pkattnum, int16 *fkattnum, Oid *pfeqoperators, Oid *ppeqoperators, Oid *ffeqoperators, int numfkdelsetcols, int16 *fkdelsetcols, bool old_check_ok, Oid parentDelTrigger, Oid parentUpdTrigger, bool with_period)
static void moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPartRels, Oid defaultPartOid)
static void ATExecEnableDisableTrigger(Relation rel, const char *trigname, char fires_when, bool skip_system, bool recurse, LOCKMODE lockmode)
static void createForeignKeyActionTriggers(Relation rel, Oid refRelOid, Constraint *fkconstraint, Oid constraintOid, Oid indexOid, Oid parentDelTrigger, Oid parentUpdTrigger, Oid *deleteTrigOid, Oid *updateTrigOid)
static void renameatt_check(Oid myrelid, Form_pg_class classform, bool recursing)
static void RangeVarCallbackForAttachIndex(const RangeVar *rv, Oid relOid, Oid oldRelOid, void *arg)
static void ATCheckPartitionsNotInUse(Relation rel, LOCKMODE lockmode)
static void truncate_check_activity(Relation rel)
static void validatePartitionedIndex(Relation partedIdx, Relation partedTbl)
static ObjectAddress ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *fkconstraint, bool recurse, bool recursing, LOCKMODE lockmode)
static void ATExecSetAccessMethodNoStorage(Relation rel, Oid newAccessMethod)
static void TryReuseIndex(Oid oldId, IndexStmt *stmt)
static void GetForeignKeyCheckTriggers(Relation trigrel, Oid conoid, Oid confrelid, Oid conrelid, Oid *insertTriggerOid, Oid *updateTriggerOid)
static void RememberClusterOnForRebuilding(Oid indoid, AlteredTableInfo *tab)
static ObjectAddress ATExecSetOptions(Relation rel, const char *colName, Node *options, bool isReset, LOCKMODE lockmode)
static ObjectAddress ATExecDropColumn(List **wqueue, Relation rel, const char *colName, DropBehavior behavior, bool recurse, bool recursing, bool missing_ok, LOCKMODE lockmode, ObjectAddresses *addrs)
static void CloneFkReferencing(List **wqueue, Relation parentRel, Relation partRel)
static void SetIndexStorageProperties(Relation rel, Relation attrelation, AttrNumber attnum, bool setstorage, char newstorage, bool setcompression, char newcompression, LOCKMODE lockmode)
static void ATController(AlterTableStmt *parsetree, Relation rel, List *cmds, bool recurse, LOCKMODE lockmode, AlterTableUtilityContext *context)
bool CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId)
static void ATExecSetRowSecurity(Relation rel, bool rls)
void find_composite_type_dependencies(Oid typeOid, Relation origRelation, const char *origTypeName)
static void truncate_check_perms(Oid relid, Form_pg_class reltuple)
static void truncate_check_rel(Oid relid, Form_pg_class reltuple)
static void change_owner_recurse_to_sequences(Oid relationOid, Oid newOwnerId, LOCKMODE lockmode)
static void StoreCatalogInheritance1(Oid relationId, Oid parentOid, int32 seqNumber, Relation inhRelation, bool child_is_partition)
static void RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, Relation rel, AttrNumber attnum, const char *colName)
static void ATPrepDropExpression(Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode)
static ObjectAddress ATExecCookedColumnDefault(Relation rel, AttrNumber attnum, Node *newDefault)
static void moveMergedTablesRows(Relation rel, List *mergingPartitionsList, Relation newPartRel)
static ObjectAddress rename_constraint_internal(Oid myrelid, Oid mytypid, const char *oldconname, const char *newconname, bool recurse, bool recursing, int expected_parents)
static void DropErrorMsgNonExistent(RangeVar *rel, char rightkind, bool missing_ok)
static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab, LOCKMODE lockmode)
static bool tryAttachPartitionForeignKey(ForeignKeyCacheInfo *fk, Oid partRelid, Oid parentConstrOid, int numfks, AttrNumber *mapped_conkey, AttrNumber *confkey, Oid *conpfeqop, Oid parentInsTrigger, Oid parentUpdTrigger, Relation trigrel)
static void ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel, PartitionCmd *cmd, AlterTableUtilityContext *context)
static AlterTableCmd * ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses *objsMoved)
static ObjectAddress ATAddCheckNNConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *constr, bool recurse, bool recursing, bool is_readd, LOCKMODE lockmode)
static void CloneFkReferenced(Relation parentRel, Relation partitionRel)
static void MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel)
static void ATPrepDropColumn(List **wqueue, Relation rel, bool recurse, bool recursing, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
void SetRelationHasSubclass(Oid relationId, bool relhassubclass)
static void MergeChildAttribute(List *inh_columns, int exist_attno, int newcol_attno, const ColumnDef *newdef)
static void ATSimplePermissions(AlterTableType cmdtype, Relation rel, int allowed_targets)
static List * MergeCheckConstraint(List *constraints, const char *name, Node *expr)
static void ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation, LOCKMODE lockmode)
static ObjectAddress ATExecSetIdentity(Relation rel, const char *colName, Node *def, LOCKMODE lockmode, bool recurse, bool recursing)
ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
static void RememberConstraintForRebuilding(Oid conoid, AlteredTableInfo *tab)
void ExecuteTruncate(TruncateStmt *stmt)
static ObjectAddress dropconstraint_internal(Relation rel, HeapTuple constraintTup, DropBehavior behavior, bool recurse, bool recursing, bool missing_ok, List **readyRels, LOCKMODE lockmode)
static bool ATPrepChangePersistence(Relation rel, bool toLogged)
static void relation_mark_replica_identity(Relation rel, char ri_type, Oid indexOid, bool is_internal)
#define ATT_FOREIGN_TABLE
static ObjectAddress ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode)
static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing, bool is_view, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNumber *partattrs, List **partexprs, Oid *partopclass, Oid *partcollation, PartitionStrategy strategy)
static void CloneRowTriggersToPartition(Relation parent, Relation partition)
static void ATInheritAdjustNotNulls(Relation parent_rel, Relation child_rel, int inhcount)
static void AttachPartitionEnsureIndexes(List **wqueue, Relation rel, Relation attachrel)
static void StoreCatalogInheritance(Oid relationId, List *supers, bool child_is_partition)
static void ATExecGenericOptions(Relation rel, List *options)
static void TryReuseForeignKey(Oid oldId, Constraint *con)
struct AlteredTableInfo AlteredTableInfo
static void validateFkOnDeleteSetColumns(int numfks, const int16 *fkattnums, int numfksetcols, const int16 *fksetcolsattnums, List *fksetcols)
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
static void ATPrepAddPrimaryKey(List **wqueue, Relation rel, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
struct NewConstraint NewConstraint
static ObjectAddress ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newValue, LOCKMODE lockmode)
static void ATSimpleRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void DetachPartitionFinalize(Relation rel, Relation partRel, bool concurrent, Oid defaultPartOid)
static void RebuildConstraintComment(AlteredTableInfo *tab, AlterTablePass pass, Oid objid, Relation rel, List *domname, const char *conname)
static void CloneForeignKeyConstraints(List **wqueue, Relation parentRel, Relation partitionRel)
static bool check_for_column_name_collision(Relation rel, const char *colname, bool if_not_exists)
static ObjectAddress ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, AlterTableCmd **cmd, bool recurse, bool recursing, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
@ AT_PASS_ADD_OTHERCONSTR
@ AT_PASS_ADD_INDEXCONSTR
static ObjectAddress ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd, LOCKMODE lockmode)
static void validateForeignKeyConstraint(char *conname, Relation rel, Relation pkrel, Oid pkindOid, Oid constraintOid, bool hasperiod)
void SetRelationTableSpace(Relation rel, Oid newTableSpaceId, RelFileNumber newRelFilenumber)
void remove_on_commit_action(Oid relid)
static void DetachAddConstraintIfNeeded(List **wqueue, Relation partRel)
static void ATExecDropCluster(Relation rel, LOCKMODE lockmode)
static bool set_attnotnull(List **wqueue, Relation rel, AttrNumber attnum, bool recurse, LOCKMODE lockmode)
#define ATT_PARTITIONED_INDEX
static void CreateInheritance(Relation child_rel, Relation parent_rel, bool ispartition)
static const struct dropmsgstrings dropmsgstringarray[]
static ObjectAddress ATExecSetExpression(AlteredTableInfo *tab, Relation rel, const char *colName, Node *newExpr, LOCKMODE lockmode)
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
static Oid CreateFKCheckTrigger(Oid myRelOid, Oid refRelOid, Constraint *fkconstraint, Oid constraintOid, Oid indexOid, Oid parentTrigOid, bool on_insert)
static SplitPartitionContext * createSplitPartitionContext(Relation partRel)
static void DropClonedTriggersFromPartition(Oid partitionId)
static void QueuePartitionConstraintValidation(List **wqueue, Relation scanrel, List *partConstraint, bool validate_default)
static ObjectAddress ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode)
static void RangeVarCallbackForDropRelation(const RangeVar *rel, Oid relOid, Oid oldRelOid, void *arg)
void AlterTableInternal(Oid relid, List *cmds, bool recurse)
static void GetForeignKeyActionTriggers(Relation trigrel, Oid conoid, Oid confrelid, Oid conrelid, Oid *deleteTriggerOid, Oid *updateTriggerOid)
void check_of_type(HeapTuple typetuple)
static ObjectAddress ATExecDropInherit(Relation rel, RangeVar *parent, LOCKMODE lockmode)
static void ATDetachCheckNoForeignKeyRefs(Relation partition)
static ObjectAddress ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel, IndexStmt *stmt, LOCKMODE lockmode)
static void AlterIndexNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved)
static char * decompile_conbin(HeapTuple contup, TupleDesc tupdesc)
static void ATExecCmd(List **wqueue, AlteredTableInfo *tab, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
static void ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode)
static void createForeignKeyCheckTriggers(Oid myRelOid, Oid refRelOid, Constraint *fkconstraint, Oid constraintOid, Oid indexOid, Oid parentInsTrigger, Oid parentUpdTrigger, Oid *insertTrigOid, Oid *updateTrigOid)
static void ATPrepAddInherit(Relation child_rel)
static ObjectAddress ATExecDetachPartitionFinalize(Relation rel, RangeVar *name)
static ObjectAddress ATExecSetStorage(Relation rel, const char *colName, Node *newValue, LOCKMODE lockmode)
static ObjectAddress ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd, AlterTableUtilityContext *context)
static List * find_typed_table_dependencies(Oid typeOid, const char *typeName, DropBehavior behavior)
Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
static ObjectAddress ATExecAddIdentity(Relation rel, const char *colName, Node *def, LOCKMODE lockmode, bool recurse, bool recursing)
static void ATExecDropConstraint(Relation rel, const char *constrName, DropBehavior behavior, bool recurse, bool missing_ok, LOCKMODE lockmode)
static ObjectAddress ATExecAddIndex(AlteredTableInfo *tab, Relation rel, IndexStmt *stmt, bool is_rebuild, LOCKMODE lockmode)
static ObjectAddress ATExecSetCompression(Relation rel, const char *column, Node *newValue, LOCKMODE lockmode)
static PartitionSpec * transformPartitionSpec(Relation rel, PartitionSpec *partspec)
static void ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
static void index_copy_data(Relation rel, RelFileLocator newrlocator)
void RenameRelationInternal(Oid myrelid, const char *newrelname, bool is_internal, bool is_index)
static void ATExecSetTableSpaceNoStorage(Relation rel, Oid newTableSpace)
static void ATPrepAlterColumnType(List **wqueue, AlteredTableInfo *tab, Relation rel, bool recurse, bool recursing, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
static void change_owner_fix_column_acls(Oid relationOid, Oid oldOwnerId, Oid newOwnerId)
#define ATT_COMPOSITE_TYPE
static ObjectAddress ATExecAttachPartitionIdx(List **wqueue, Relation parentIdx, RangeVar *name)
bool PartConstraintImpliedByRelConstraint(Relation scanrel, List *partConstraint)
void RangeVarCallbackMaintainsTable(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
static void ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, PartitionCmd *cmd, AlterTableUtilityContext *context)
static const char * alter_table_type_to_string(AlterTableType cmdtype)
static bool constraints_equivalent(HeapTuple a, HeapTuple b, TupleDesc tupleDesc)
static ObjectAddress ATExecAddStatistics(AlteredTableInfo *tab, Relation rel, CreateStatsStmt *stmt, bool is_rebuild, LOCKMODE lockmode)
ObjectAddress RenameConstraint(RenameStmt *stmt)
static void ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode, AlterTableUtilityContext *context)
void register_on_commit_action(Oid relid, OnCommitAction action)
static void RangeVarCallbackForTruncate(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
static ObjectAddress ATExecClusterOn(Relation rel, const char *indexName, LOCKMODE lockmode)
static char GetAttributeStorage(Oid atttypid, const char *storagemode)
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
#define child_dependency_type(child_is_partition)
static void refuseDupeIndexAttach(Relation parentIdx, Relation partIdx, Relation partitionTbl)
void ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged, DropBehavior behavior, bool restart_seqs, bool run_as_table_owner)
static List * MergeAttributes(List *columns, const List *supers, char relpersistence, bool is_partition, List **supconstr, List **supnotnulls)
static void ATExecEnableDisableRule(Relation rel, const char *rulename, char fires_when, LOCKMODE lockmode)
struct NewColumnValue NewColumnValue
static void ATPrepSetAccessMethod(AlteredTableInfo *tab, Relation rel, const char *amname)
static bool NotNullImpliedByRelConstraints(Relation rel, Form_pg_attribute attr)
const char * GetCompressionMethodName(char method)
char CompressionNameToMethod(const char *compression)
#define CompressionMethodIsValid(cm)
#define InvalidCompressionMethod
void AlterTableCreateToastTable(Oid relOid, Datum reloptions, LOCKMODE lockmode)
void ExecBSTruncateTriggers(EState *estate, ResultRelInfo *relinfo)
void EnableDisableTrigger(Relation rel, const char *tgname, Oid tgparent, char fires_when, bool skip_system, bool recurse, LOCKMODE lockmode)
void ExecASTruncateTriggers(EState *estate, ResultRelInfo *relinfo)
const char * FindTriggerIncompatibleWithInheritance(TriggerDesc *trigdesc)
ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition)
void TriggerSetParentTrigger(Relation trigRel, Oid childTrigId, Oid parentTrigId, Oid childTableId)
ObjectAddress CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition, char trigger_fires_when)
bool AfterTriggerPendingOnRel(Oid relid)
void AfterTriggerEndQuery(EState *estate)
void AfterTriggerBeginQuery(void)
#define TRIGGER_FIRES_ON_ORIGIN
#define TRIGGER_FIRES_ON_REPLICA
#define TRIGGER_EVENT_ROW
#define TRIGGER_FIRES_ALWAYS
#define TRIGGER_EVENT_INSERT
TupleTableSlot * execute_attr_map_slot(AttrMap *attrMap, TupleTableSlot *in_slot, TupleTableSlot *out_slot)
void free_conversion_map(TupleConversionMap *map)
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc)
TupleDesc CreateTemplateTupleDesc(int natts)
Node * TupleDescGetDefault(TupleDesc tupdesc, AttrNumber attnum)
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
#define ReleaseTupleDesc(tupdesc)
#define TupleDescAttr(tupdesc, i)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
static void slot_getallattrs(TupleTableSlot *slot)
static bool slot_attisnull(TupleTableSlot *slot, int attnum)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
bool DomainHasConstraints(Oid type_id)
void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId)
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid, bool isImplicitArray, bool errorOnTableType, ObjectAddresses *objsMoved)
void checkDomainOwner(HeapTuple tup)
void SwitchToUntrustedUser(Oid userid, UserContext *context)
void RestoreUserContext(UserContext *context)
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
void ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
@ PROCESS_UTILITY_SUBCOMMAND
#define MAX_STATISTICS_TARGET
String * makeString(char *str)
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
SubTransactionId GetCurrentSubTransactionId(void)
void CommandCounterIncrement(void)
void StartTransactionCommand(void)
void CommitTransactionCommand(void)
CommandId GetCurrentCommandId(bool used)
#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE
#define XLogLogicalInfoActive()
#define XLOG_INCLUDE_ORIGIN
void XLogRegisterData(char *data, uint32 len)
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void XLogSetRecordFlags(uint8 flags)
void XLogBeginInsert(void)