99 #include "utils/fmgroids.h"
166 #define AT_NUM_PASSES (AT_PASS_MISC + 1)
265 gettext_noop(
"sequence \"%s\" does not exist, skipping"),
267 gettext_noop(
"Use DROP SEQUENCE to remove a sequence.")},
276 gettext_noop(
"materialized view \"%s\" does not exist"),
277 gettext_noop(
"materialized view \"%s\" does not exist, skipping"),
279 gettext_noop(
"Use DROP MATERIALIZED VIEW to remove a materialized view.")},
281 ERRCODE_UNDEFINED_OBJECT,
286 {RELKIND_COMPOSITE_TYPE,
287 ERRCODE_UNDEFINED_OBJECT,
292 {RELKIND_FOREIGN_TABLE,
293 ERRCODE_UNDEFINED_OBJECT,
295 gettext_noop(
"foreign table \"%s\" does not exist, skipping"),
297 gettext_noop(
"Use DROP FOREIGN TABLE to remove a foreign table.")},
298 {RELKIND_PARTITIONED_TABLE,
304 {RELKIND_PARTITIONED_INDEX,
305 ERRCODE_UNDEFINED_OBJECT,
310 {
'\0', 0, NULL, NULL, NULL, NULL}
328 #define ATT_TABLE 0x0001
329 #define ATT_VIEW 0x0002
330 #define ATT_MATVIEW 0x0004
331 #define ATT_INDEX 0x0008
332 #define ATT_COMPOSITE_TYPE 0x0010
333 #define ATT_FOREIGN_TABLE 0x0020
334 #define ATT_PARTITIONED_INDEX 0x0040
335 #define ATT_SEQUENCE 0x0080
336 #define ATT_PARTITIONED_TABLE 0x0100
365 #define child_dependency_type(child_is_partition) \
366 ((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
374 bool is_partition,
List **supconstr);
381 bool child_is_partition);
384 bool child_is_partition);
392 bool recurse,
bool recursing,
LOCKMODE lockmode);
398 bool recurse,
bool recursing,
LOCKMODE lockmode);
404 Oid *opclasses,
bool *pk_has_without_overlaps);
406 int numattrs,
int16 *attnums,
407 bool with_period,
Oid *opclasses,
408 bool *pk_has_without_overlaps);
414 Oid pkindOid,
Oid constraintOid,
bool hasperiod);
420 bool recurse,
bool recursing,
LOCKMODE lockmode,
452 bool recurse,
bool recursing,
465 const char *colName,
LOCKMODE lockmode);
467 const char *colName,
LOCKMODE lockmode);
470 List *testConstraint,
List *provenConstraint);
476 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
478 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing);
480 bool recurse,
bool recursing);
496 bool recurse,
bool recursing,
505 Constraint *newConstraint,
bool recurse,
bool is_readd,
513 bool recurse,
bool recursing,
bool is_readd,
517 bool recurse,
bool recursing,
520 int numfksetcols,
const int16 *fksetcolsattnums,
523 char *constraintname,
528 Oid *pfeqoperators,
Oid *ppeqoperators,
529 Oid *ffeqoperators,
int numfkdelsetcols,
530 int16 *fkdelsetcols,
bool is_internal,
535 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
536 int numfkdelsetcols,
int16 *fkdelsetcols,
538 Oid parentDelTrigger,
Oid parentUpdTrigger,
543 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
544 int numfkdelsetcols,
int16 *fkdelsetcols,
545 bool old_check_ok,
LOCKMODE lockmode,
546 Oid parentInsTrigger,
Oid parentUpdTrigger,
556 Oid parentInsTrigger,
Oid parentUpdTrigger,
557 Oid *insertTrigOid,
Oid *updateTrigOid);
561 Oid parentDelTrigger,
Oid parentUpdTrigger,
562 Oid *deleteTrigOid,
Oid *updateTrigOid);
565 Oid parentConstrOid,
int numfks,
568 Oid parentInsTrigger,
569 Oid parentUpdTrigger,
573 Oid *deleteTriggerOid,
574 Oid *updateTriggerOid);
577 Oid *insertTriggerOid,
578 Oid *updateTriggerOid);
581 bool recurse,
bool recursing,
582 bool missing_ok,
LOCKMODE lockmode);
585 bool recurse,
bool recursing,
603 const char *conname);
609 Oid oldOwnerId,
Oid newOwnerId);
620 const char *tablespacename,
LOCKMODE lockmode);
627 char fires_when,
bool skip_system,
bool recurse,
630 char fires_when,
LOCKMODE lockmode);
649 Oid oldRelOid,
void *
arg);
654 List **partexprs,
Oid *partopclass,
Oid *partcollation,
658 bool expect_detached);
664 List *partConstraint,
665 bool validate_default);
673 bool concurrent,
Oid defaultPartOid);
716 List *old_constraints;
718 List *cookedDefaults;
739 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
741 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
742 errmsg(
"ON COMMIT can only be used on temporary tables")));
744 if (
stmt->partspec != NULL)
746 if (relkind != RELKIND_RELATION)
747 elog(
ERROR,
"unexpected relkind: %d", (
int) relkind);
749 relkind = RELKIND_PARTITIONED_TABLE;
755 if (relkind == RELKIND_PARTITIONED_TABLE &&
756 stmt->relation->relpersistence == RELPERSISTENCE_UNLOGGED)
758 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
759 errmsg(
"partitioned tables cannot be unlogged")));
775 if (
stmt->relation->relpersistence == RELPERSISTENCE_TEMP
778 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
779 errmsg(
"cannot create temporary table within security-restricted operation")));
802 foreach(listptr,
stmt->inhRelations)
814 (
errcode(ERRCODE_DUPLICATE_TABLE),
815 errmsg(
"relation \"%s\" would be inherited from more than once",
825 if (
stmt->tablespacename)
831 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
832 errmsg(
"cannot specify default tablespace for partitioned relations")));
834 else if (
stmt->partbound)
860 if (tablespaceId == GLOBALTABLESPACE_OID)
862 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
863 errmsg(
"only shared relations can be placed in pg_global tablespace")));
880 case RELKIND_PARTITIONED_TABLE:
887 if (
stmt->ofTypename)
907 stmt->relation->relpersistence,
908 stmt->partbound != NULL,
931 cookedDefaults =
NIL;
934 foreach(listptr,
stmt->tableElts)
953 rawDefaults =
lappend(rawDefaults, rawEnt);
954 attr->atthasdef =
true;
970 cookedDefaults =
lappend(cookedDefaults, cooked);
971 attr->atthasdef =
true;
980 if (
stmt->accessMethod != NULL)
982 Assert(RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE);
985 else if (RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE)
993 if (RELKIND_HAS_TABLE_AM(relkind) && !
OidIsValid(accessMethodId))
1014 stmt->relation->relpersistence,
1053 true,
true,
false, queryString);
1061 if (
stmt->partbound)
1078 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1080 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1081 errmsg(
"\"%s\" is not partitioned",
1119 NULL,
false,
false);
1174 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1175 errmsg(
"cannot partition using more than %d columns",
1187 partattrs, &partexprs, partopclass,
1188 partcollation,
stmt->partspec->strategy);
1192 partopclass, partcollation);
1205 if (
stmt->partbound)
1219 foreach(cell, idxlist)
1226 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1230 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1231 errmsg(
"cannot create foreign partition of partitioned table \"%s\"",
1233 errdetail(
"Table \"%s\" contains indexes that are unique.",
1247 attmap, &constraintOid);
1254 false,
false,
false,
false,
false);
1282 if (
stmt->constraints)
1284 true,
true,
false, queryString);
1351 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1352 errmsg(
"too many array dimensions"));
1356 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1357 errmsg(
"column \"%s\" cannot be declared SETOF",
1361 atttypid, atttypmod, attdim);
1370 att->attinhcount = entry->
inhcount;
1371 att->attidentity = entry->
identity;
1375 att->attstorage = entry->
storage;
1398 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
1404 (
errmsg(
"schema \"%s\" does not exist, skipping",
1412 if (rentry->
kind == rightkind)
1442 if (rentry->
kind == rightkind)
1447 if (wentry->
kind == wrongkind)
1452 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1483 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1484 errmsg(
"DROP INDEX CONCURRENTLY does not support dropping multiple objects")));
1487 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1488 errmsg(
"DROP INDEX CONCURRENTLY does not support CASCADE")));
1501 relkind = RELKIND_RELATION;
1505 relkind = RELKIND_INDEX;
1509 relkind = RELKIND_SEQUENCE;
1513 relkind = RELKIND_VIEW;
1517 relkind = RELKIND_MATVIEW;
1521 relkind = RELKIND_FOREIGN_TABLE;
1525 elog(
ERROR,
"unrecognized drop object type: %d",
1554 state.expected_relkind = relkind;
1577 state.actual_relpersistence != RELPERSISTENCE_TEMP)
1589 state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1591 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1592 errmsg(
"cannot drop partitioned index \"%s\" concurrently",
1602 if (
state.actual_relkind == RELKIND_PARTITIONED_INDEX)
1604 state.heap_lockmode,
1608 obj.
classId = RelationRelationId;
1636 bool invalid_system_index =
false;
1671 is_partition = classform->relispartition;
1674 state->actual_relkind = classform->relkind;
1675 state->actual_relpersistence = classform->relpersistence;
1685 if (classform->relkind == RELKIND_PARTITIONED_TABLE)
1687 else if (classform->relkind == RELKIND_PARTITIONED_INDEX)
1694 state->expected_relkind);
1709 if (
IsSystemClass(relOid, classform) && classform->relkind == RELKIND_INDEX)
1723 indisvalid = indexform->indisvalid;
1728 invalid_system_index =
true;
1734 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1735 errmsg(
"permission denied: \"%s\" is a system catalog",
1749 relOid != oldRelOid)
1762 if (is_partition && relOid != oldRelOid)
1796 foreach(cell,
stmt->relations)
1800 bool recurse = rv->
inh;
1826 relids_logged =
lappend_oid(relids_logged, myrelid);
1835 foreach(child, children)
1874 relids_logged =
lappend_oid(relids_logged, childrelid);
1877 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1879 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1880 errmsg(
"cannot truncate only a partitioned table"),
1881 errhint(
"Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly.")));
1885 stmt->behavior,
stmt->restart_seqs,
false);
1912 List *relids_logged,
1914 bool run_as_table_owner)
1918 HTAB *ft_htab = NULL;
1944 if (newrelids ==
NIL)
1947 foreach(cell, newrelids)
1954 (
errmsg(
"truncate cascades to table \"%s\"",
1964 relids_logged =
lappend_oid(relids_logged, relid);
1974 #ifdef USE_ASSERT_CHECKING
1995 foreach(seqcell, seqlist)
2029 resultRelInfo = resultRelInfos;
2050 resultRelInfo = resultRelInfos;
2055 if (run_as_table_owner)
2059 if (run_as_table_owner)
2074 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2084 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2095 memset(&hctl, 0,
sizeof(
HASHCTL));
2100 ft_htab =
hash_create(
"TRUNCATE for Foreign Tables",
2160 toast_relid = rel->
rd_rel->reltoastrelid;
2167 toastrel->
rd_rel->relpersistence);
2213 foreach(cell, seq_relids)
2227 if (relids_logged !=
NIL)
2236 foreach(cell, relids_logged)
2259 resultRelInfo = resultRelInfos;
2264 if (run_as_table_owner)
2268 if (run_as_table_owner)
2307 if (reltuple->relkind == RELKIND_FOREIGN_TABLE)
2314 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2315 errmsg(
"cannot truncate foreign table \"%s\"",
2318 else if (reltuple->relkind != RELKIND_RELATION &&
2319 reltuple->relkind != RELKIND_PARTITIONED_TABLE)
2321 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2334 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2335 errmsg(
"permission denied: \"%s\" is a system catalog",
2371 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2372 errmsg(
"cannot truncate temporary tables of other sessions")));
2390 case TYPSTORAGE_PLAIN:
2392 case TYPSTORAGE_EXTERNAL:
2394 case TYPSTORAGE_EXTENDED:
2396 case TYPSTORAGE_MAIN:
2466 bool is_partition,
List **supconstr)
2470 bool have_bogus_defaults =
false;
2472 static Node bogus_marker = {0};
2489 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2490 errmsg(
"tables can have at most %d columns",
2507 for (
int coldefpos = 0; coldefpos <
list_length(columns); coldefpos++)
2511 if (!is_partition && coldef->
typeName == NULL)
2520 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2521 errmsg(
"column \"%s\" does not exist",
2526 for (
int restpos = coldefpos + 1; restpos <
list_length(columns);)
2546 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2547 errmsg(
"column \"%s\" specified more than once",
2562 saved_columns = columns;
2578 List *inherited_defaults;
2579 List *cols_with_defaults;
2598 if (relation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !is_partition)
2600 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2601 errmsg(
"cannot inherit from partitioned table \"%s\"",
2603 if (relation->
rd_rel->relispartition && !is_partition)
2605 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2606 errmsg(
"cannot inherit from partition \"%s\"",
2609 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2610 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2611 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2613 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2614 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2622 relation->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
2623 relpersistence == RELPERSISTENCE_TEMP)
2625 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2626 errmsg(
"cannot create a temporary relation as partition of permanent relation \"%s\"",
2630 if (relpersistence != RELPERSISTENCE_TEMP &&
2631 relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
2633 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2635 ?
"cannot inherit from temporary relation \"%s\""
2636 :
"cannot create a permanent relation as partition of temporary relation \"%s\"",
2640 if (relation->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
2643 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2645 ?
"cannot inherit from temporary relation of another session"
2646 :
"cannot create as partition of temporary relation of another session")));
2657 constr = tupleDesc->
constr;
2667 inherited_defaults = cols_with_defaults =
NIL;
2674 char *attributeName =
NameStr(attribute->attname);
2682 if (attribute->attisdropped)
2689 attribute->atttypmod, attribute->attcollation);
2691 newdef->
storage = attribute->attstorage;
2692 newdef->
generated = attribute->attgenerated;
2703 newdef->
identity = attribute->attidentity;
2710 if (exist_attno > 0)
2717 newattmap->
attnums[parent_attno - 1] = exist_attno;
2732 inh_columns =
lappend(inh_columns, newdef);
2734 newattmap->
attnums[parent_attno - 1] = ++child_attno;
2741 if (attribute->atthasdef)
2746 if (this_default == NULL)
2747 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
2756 inherited_defaults =
lappend(inherited_defaults, this_default);
2757 cols_with_defaults =
lappend(cols_with_defaults, mergeddef);
2765 forboth(lc1, inherited_defaults, lc2, cols_with_defaults)
2769 bool found_whole_row;
2783 if (found_whole_row)
2785 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2786 errmsg(
"cannot convert whole-row table reference"),
2787 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
2803 have_bogus_defaults =
true;
2820 bool found_whole_row;
2823 if (check[
i].ccnoinherit)
2837 if (found_whole_row)
2839 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2840 errmsg(
"cannot convert whole-row table reference"),
2841 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
2865 if (inh_columns !=
NIL)
2867 int newcol_attno = 0;
2869 foreach(lc, columns)
2872 char *attributeName = newdef->
colname;
2887 if (exist_attno > 0)
2899 inh_columns =
lappend(inh_columns, newdef);
2903 columns = inh_columns;
2911 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2912 errmsg(
"tables can have at most %d columns",
2924 foreach(lc, saved_columns)
2950 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2951 errmsg(
"column \"%s\" inherits from generated column but specifies default",
2955 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2956 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
2963 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
2964 errmsg(
"child column \"%s\" specifies generation expression",
2966 errhint(
"A child table column cannot be generated unless its parent column is.")));
2991 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2992 errmsg(
"column \"%s\" does not exist",
3001 if (have_bogus_defaults)
3003 foreach(lc, columns)
3011 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3012 errmsg(
"column \"%s\" inherits conflicting generation expressions",
3014 errhint(
"To resolve the conflict, specify a generation expression explicitly.")));
3017 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3018 errmsg(
"column \"%s\" inherits conflicting default values",
3020 errhint(
"To resolve the conflict, specify a default explicitly.")));
3025 *supconstr = constraints;
3052 foreach(lc, constraints)
3068 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3069 errmsg(
"too many inheritance parents"));
3075 errmsg(
"check constraint name \"%s\" appears multiple times but with different expressions",
3086 newcon->
expr = expr;
3088 return lappend(constraints, newcon);
3115 char *attributeName = newdef->
colname;
3124 if (exist_attno == newcol_attno)
3126 (
errmsg(
"merging column \"%s\" with inherited definition",
3130 (
errmsg(
"moving and merging column \"%s\" with inherited definition", attributeName),
3131 errdetail(
"User-specified column moved to the position of the inherited column.")));
3140 if (inhtypeid != newtypeid || inhtypmod != newtypmod)
3142 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3143 errmsg(
"column \"%s\" has a type conflict",
3154 if (inhcollid != newcollid)
3156 (
errcode(ERRCODE_COLLATION_MISMATCH),
3157 errmsg(
"column \"%s\" has a collation conflict",
3176 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3177 errmsg(
"column \"%s\" has a storage parameter conflict",
3192 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3193 errmsg(
"column \"%s\" has a compression method conflict",
3221 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3222 errmsg(
"column \"%s\" inherits from generated column but specifies default",
3226 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3227 errmsg(
"column \"%s\" inherits from generated column but specifies identity",
3234 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
3235 errmsg(
"child column \"%s\" specifies generation expression",
3237 errhint(
"A child table column cannot be generated unless its parent column is.")));
3278 char *attributeName = newdef->
colname;
3288 (
errmsg(
"merging multiple inherited definitions of column \"%s\"",
3297 if (prevtypeid != newtypeid || prevtypmod != newtypmod)
3299 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3300 errmsg(
"inherited column \"%s\" has a type conflict",
3316 if (prevcollid != newcollid)
3318 (
errcode(ERRCODE_COLLATION_MISMATCH),
3319 errmsg(
"inherited column \"%s\" has a collation conflict",
3332 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3333 errmsg(
"inherited column \"%s\" has a storage parameter conflict",
3348 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3349 errmsg(
"column \"%s\" has a compression method conflict",
3360 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3361 errmsg(
"inherited column \"%s\" has a generation conflict",
3371 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3372 errmsg(
"too many inheritance parents"));
3385 bool child_is_partition)
3411 foreach(entry, supers)
3416 child_is_partition);
3430 bool child_is_partition)
3441 parentobject.
classId = RelationRelationId;
3444 childobject.
classId = RelationRelationId;
3478 foreach(lc, columns)
3527 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
3530 if (classtuple->relhassubclass != relhassubclass)
3532 classtuple->relhassubclass = relhassubclass;
3558 Oid oldTableSpaceId;
3564 oldTableSpaceId = rel->
rd_rel->reltablespace;
3565 if (newTableSpaceId == oldTableSpaceId ||
3575 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3576 errmsg(
"cannot move system relation \"%s\"",
3580 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3582 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3583 errmsg(
"only shared relations can be placed in pg_global tablespace")));
3591 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3592 errmsg(
"cannot move temporary tables of other sessions")));
3614 Oid newTableSpaceId,
3630 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
3638 rd_rel->relfilenode = newRelFilenumber;
3646 if (!RELKIND_HAS_STORAGE(rel->
rd_rel->relkind))
3648 rd_rel->reltablespace);
3660 char relkind = classform->relkind;
3662 if (classform->reloftype && !recursing)
3664 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3665 errmsg(
"cannot rename column of typed table")));
3674 if (relkind != RELKIND_RELATION &&
3675 relkind != RELKIND_VIEW &&
3676 relkind != RELKIND_MATVIEW &&
3677 relkind != RELKIND_COMPOSITE_TYPE &&
3678 relkind != RELKIND_INDEX &&
3679 relkind != RELKIND_PARTITIONED_INDEX &&
3680 relkind != RELKIND_FOREIGN_TABLE &&
3681 relkind != RELKIND_PARTITIONED_TABLE)
3683 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3684 errmsg(
"cannot rename columns of relation \"%s\"",
3696 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3697 errmsg(
"permission denied: \"%s\" is a system catalog",
3698 NameStr(classform->relname))));
3708 const char *oldattname,
3709 const char *newattname,
3712 int expected_parents,
3756 forboth(lo, child_oids, li, child_numparents)
3761 if (childrelid == myrelid)
3764 renameatt_internal(childrelid, oldattname, newattname,
false,
true, numparents, behavior);
3775 if (expected_parents == 0 &&
3778 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3779 errmsg(
"inherited column \"%s\" must be renamed in child tables too",
3784 if (targetrelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
3793 foreach(lo, child_oids)
3802 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3803 errmsg(
"column \"%s\" does not exist",
3807 attnum = attform->attnum;
3810 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3811 errmsg(
"cannot rename system column \"%s\"",
3823 if (attform->attinhcount > expected_parents)
3825 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3826 errmsg(
"cannot rename inherited column \"%s\"",
3887 (
errmsg(
"relation \"%s\" does not exist, skipping",
3888 stmt->relation->relname)));
3896 stmt->relation->inh,
3912 const char *oldconname,
3913 const char *newconname,
3916 int expected_parents)
3924 Assert(!myrelid || !mytypid);
3945 elog(
ERROR,
"cache lookup failed for constraint %u",
3949 if (myrelid && con->contype == CONSTRAINT_CHECK && !con->connoinherit)
3961 forboth(lo, child_oids, li, child_numparents)
3966 if (childrelid == myrelid)
3974 if (expected_parents == 0 &&
3977 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3978 errmsg(
"inherited constraint \"%s\" must be renamed in child tables too",
3982 if (con->coninhcount > expected_parents)
3984 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3985 errmsg(
"cannot rename inherited constraint \"%s\"",
3990 && (con->contype == CONSTRAINT_PRIMARY
3991 || con->contype == CONSTRAINT_UNIQUE
3992 || con->contype == CONSTRAINT_EXCLUSION))
4030 elog(
ERROR,
"cache lookup failed for type %u", typid);
4045 (
errmsg(
"relation \"%s\" does not exist, skipping",
4046 stmt->relation->relname)));
4056 stmt->relation->inh),
4097 (
errmsg(
"relation \"%s\" does not exist, skipping",
4098 stmt->relation->relname)));
4109 obj_is_index = (relkind == RELKIND_INDEX ||
4110 relkind == RELKIND_PARTITIONED_INDEX);
4111 if (obj_is_index || is_index_stmt == obj_is_index)
4115 is_index_stmt = obj_is_index;
4159 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4165 (
errcode(ERRCODE_DUPLICATE_TABLE),
4166 errmsg(
"relation \"%s\" already exists",
4176 is_index == (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4177 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX));
4199 newrelname, namespaceId);
4204 if (targetrelation->
rd_rel->relkind == RELKIND_INDEX ||
4205 targetrelation->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
4236 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
4278 int expected_refcnt;
4283 (
errcode(ERRCODE_OBJECT_IN_USE),
4285 errmsg(
"cannot %s \"%s\" because it is being used by active queries in this session",
4288 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
4289 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
4292 (
errcode(ERRCODE_OBJECT_IN_USE),
4294 errmsg(
"cannot %s \"%s\" because it has pending trigger events",
4319 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4320 errmsg(
"cannot alter temporary tables of other sessions")));
4432 ATController(NULL, rel, cmds, recurse, lockmode, NULL);
4717 elog(
ERROR,
"unrecognized alter table type: %d",
4725 if (cmd_lockmode > lockmode)
4726 lockmode = cmd_lockmode;
4775 bool recurse,
bool recursing,
LOCKMODE lockmode,
4788 if (rel->
rd_rel->relispartition &&
4792 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4793 errmsg(
"cannot alter partition \"%s\" with an incomplete detach",
4795 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
5023 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5024 errmsg(
"cannot change persistence setting twice")));
5040 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5041 errmsg(
"cannot have multiple SET ACCESS METHOD subcommands")));
5152 elog(
ERROR,
"unrecognized alter table type: %d",
5186 foreach(ltab, *wqueue)
5202 foreach(lcmd, subcmds)
5224 foreach(ltab, *wqueue)
5233 if (((tab->
relkind == RELKIND_RELATION ||
5234 tab->
relkind == RELKIND_PARTITIONED_TABLE) &&
5236 tab->
relkind == RELKIND_MATVIEW)
5341 cmd->
recurse,
false, lockmode);
5346 true,
true, lockmode);
5406 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
5417 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
5418 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
5527 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
5539 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
5548 elog(
ERROR,
"unrecognized alter table type: %d",
5608 foreach(lc, beforeStmts)
5617 foreach(lc, atstmt->
cmds)
5677 if (pass < cur_pass)
5680 elog(
ERROR,
"ALTER TABLE scheduling failure: too late for pass %d",
5683 else if (pass > cur_pass)
5700 elog(
ERROR,
"ALTER TABLE scheduling failure: bogus item for pass %d",
5721 foreach(ltab, *wqueue)
5726 if (!RELKIND_HAS_STORAGE(tab->
relkind))
5767 Oid NewAccessMethod;
5780 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5781 errmsg(
"cannot rewrite system relation \"%s\"",
5786 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5787 errmsg(
"cannot rewrite table \"%s\" used as a catalog table",
5798 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5799 errmsg(
"cannot rewrite temporary tables of other sessions")));
5808 NewTableSpace = OldHeap->
rd_rel->reltablespace;
5817 NewAccessMethod = OldHeap->
rd_rel->relam;
5860 persistence, lockmode);
5919 foreach(lc, seqlist)
5935 foreach(ltab, *wqueue)
5942 if (!RELKIND_HAS_STORAGE(tab->
relkind))
5981 foreach(ltab, *wqueue)
6008 bool needscan =
false;
6009 List *notnull_attrs;
6070 elog(
ERROR,
"unrecognized constraint type: %d",
6090 notnull_attrs =
NIL;
6099 for (
i = 0;
i < newTupDesc->
natts;
i++)
6103 if (attr->attnotnull && !attr->attisdropped)
6110 if (newrel || needscan)
6180 for (
i = 0;
i < newTupDesc->
natts;
i++)
6216 foreach(lc, dropped_attrs)
6270 insertslot = newslot;
6279 insertslot = oldslot;
6285 foreach(l, notnull_attrs)
6294 (
errcode(ERRCODE_NOT_NULL_VIOLATION),
6295 errmsg(
"column \"%s\" of relation \"%s\" contains null values",
6311 (
errcode(ERRCODE_CHECK_VIOLATION),
6312 errmsg(
"check constraint \"%s\" of relation \"%s\" is violated by some row",
6321 elog(
ERROR,
"unrecognized constraint type: %d",
6326 if (partqualstate && !
ExecCheck(partqualstate, econtext))
6330 (
errcode(ERRCODE_CHECK_VIOLATION),
6331 errmsg(
"updated partition constraint for default partition \"%s\" would be violated by some row",
6336 (
errcode(ERRCODE_CHECK_VIOLATION),
6337 errmsg(
"partition constraint of relation \"%s\" is violated by some row",
6345 ti_options, bistate);
6384 foreach(ltab, *wqueue)
6387 if (tab->
relid == relid)
6406 *wqueue =
lappend(*wqueue, tab);
6418 return "ADD COLUMN";
6421 return "ALTER COLUMN ... SET DEFAULT";
6423 return "ALTER COLUMN ... DROP NOT NULL";
6425 return "ALTER COLUMN ... SET NOT NULL";
6427 return "ALTER COLUMN ... SET EXPRESSION";
6429 return "ALTER COLUMN ... DROP EXPRESSION";
6433 return "ALTER COLUMN ... SET STATISTICS";
6435 return "ALTER COLUMN ... SET";
6437 return "ALTER COLUMN ... RESET";
6439 return "ALTER COLUMN ... SET STORAGE";
6441 return "ALTER COLUMN ... SET COMPRESSION";
6443 return "DROP COLUMN";
6451 return "ADD CONSTRAINT";
6453 return "ALTER CONSTRAINT";
6455 return "VALIDATE CONSTRAINT";
6457 return "DROP CONSTRAINT";
6461 return "ALTER COLUMN ... SET DATA TYPE";
6463 return "ALTER COLUMN ... OPTIONS";
6467 return "CLUSTER ON";
6469 return "SET WITHOUT CLUSTER";
6471 return "SET ACCESS METHOD";
6473 return "SET LOGGED";
6475 return "SET UNLOGGED";
6477 return "SET WITHOUT OIDS";
6479 return "SET TABLESPACE";
6487 return "ENABLE TRIGGER";
6489 return "ENABLE ALWAYS TRIGGER";
6491 return "ENABLE REPLICA TRIGGER";
6493 return "DISABLE TRIGGER";
6495 return "ENABLE TRIGGER ALL";
6497 return "DISABLE TRIGGER ALL";
6499 return "ENABLE TRIGGER USER";
6501 return "DISABLE TRIGGER USER";
6503 return "ENABLE RULE";
6505 return "ENABLE ALWAYS RULE";
6507 return "ENABLE REPLICA RULE";
6509 return "DISABLE RULE";
6513 return "NO INHERIT";
6519 return "REPLICA IDENTITY";
6521 return "ENABLE ROW SECURITY";
6523 return "DISABLE ROW SECURITY";
6525 return "FORCE ROW SECURITY";
6527 return "NO FORCE ROW SECURITY";
6531 return "ATTACH PARTITION";
6533 return "DETACH PARTITION";
6535 return "DETACH PARTITION ... FINALIZE";
6537 return "ALTER COLUMN ... ADD IDENTITY";
6539 return "ALTER COLUMN ... SET";
6541 return "ALTER COLUMN ... DROP IDENTITY";
6561 switch (rel->
rd_rel->relkind)
6563 case RELKIND_RELATION:
6566 case RELKIND_PARTITIONED_TABLE:
6572 case RELKIND_MATVIEW:
6578 case RELKIND_PARTITIONED_INDEX:
6581 case RELKIND_COMPOSITE_TYPE:
6584 case RELKIND_FOREIGN_TABLE:
6587 case RELKIND_SEQUENCE:
6596 if ((actual_target & allowed_targets) == 0)
6602 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6604 errmsg(
"ALTER action %s cannot be performed on relation \"%s\"",
6609 elog(
ERROR,
"invalid ALTER action attempted on relation \"%s\"",
6620 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6621 errmsg(
"permission denied: \"%s\" is a system catalog",
6642 if (recurse && rel->
rd_rel->relhassubclass)
6655 foreach(child, children)
6660 if (childrelid == relid)
6681 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
6715 Assert(rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
6721 foreach(child, children)
6755 const char *origTypeName)
6772 Anum_pg_depend_refclassid,
6776 Anum_pg_depend_refobjid,
6791 if (pg_depend->classid == TypeRelationId)
6800 origRelation, origTypeName);
6805 if (pg_depend->classid != RelationRelationId)
6824 if (pg_depend->objsubid > 0 && pg_depend->objsubid <= tupleDesc->
natts)
6829 for (
int attno = 1; attno <= tupleDesc->
natts; attno++)
6832 if (att->atttypid == typeOid && !att->attisdropped)
6853 if (RELKIND_HAS_STORAGE(rel->
rd_rel->relkind) ||
6854 RELKIND_HAS_PARTITIONS(rel->
rd_rel->relkind))
6858 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6859 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
6863 else if (origRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
6865 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6866 errmsg(
"cannot alter type \"%s\" because column \"%s.%s\" uses it",
6870 else if (origRelation->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
6872 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6873 errmsg(
"cannot alter foreign table \"%s\" because column \"%s.%s\" uses its row type",
6879 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6880 errmsg(
"cannot alter table \"%s\" because column \"%s.%s\" uses its row type",
6892 origRelation, origTypeName);
6923 Anum_pg_class_reloftype,
6935 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
6936 errmsg(
"cannot alter type \"%s\" because it is the type of a typed table",
6938 errhint(
"Use ALTER ... CASCADE to alter the typed tables too.")));
6964 bool typeOk =
false;
6966 if (typ->typtype == TYPTYPE_COMPOSITE)
6972 typeOk = (typeRelation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE);
6983 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6984 errmsg(
"type %s is the row type of another table",
6986 errdetail(
"A typed table must use a stand-alone composite type created with CREATE TYPE.")));
6990 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6991 errmsg(
"type %s is not a composite type",
7015 if (rel->
rd_rel->reloftype && !recursing)
7017 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7018 errmsg(
"cannot add column to typed table")));
7020 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
7023 if (recurse && !is_view)
7042 bool if_not_exists = (*cmd)->missing_ok;
7065 if (rel->
rd_rel->relispartition && !recursing)
7067 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7068 errmsg(
"cannot add column to a partition")));
7093 if (ctypeId != childatt->atttypid ||
7094 ctypmod != childatt->atttypmod)
7096 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7097 errmsg(
"child table \"%s\" has different type for column \"%s\"",
7100 if (ccollid != childatt->attcollation)
7102 (
errcode(ERRCODE_COLLATION_MISMATCH),
7103 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
7111 &childatt->attinhcount))
7113 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
7114 errmsg(
"too many inheritance parents"));
7121 (
errmsg(
"merging definition of column \"%s\" for child \"%s\"",
7151 if (
context != NULL && !recursing)
7170 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE &&
7173 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7174 errmsg(
"cannot recursively add identity column to table that has child tables")));
7180 elog(
ERROR,
"cache lookup failed for relation %u", myrelid);
7182 relkind = relform->relkind;
7185 newattnum = relform->relnatts + 1;
7188 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
7189 errmsg(
"tables can have at most %d columns",
7200 attribute->attnum = newattnum;
7214 relform->relnatts = newattnum;
7236 rawEnt->
attnum = attribute->attnum;
7253 false,
true,
false, NULL);
7299 if (RELKIND_HAS_STORAGE(relkind))
7310 nve->
typeId = attribute->atttypid;
7312 defval = (
Expr *) nve;
7326 baseTypeMod = attribute->atttypmod;
7333 attribute->atttypid,
7334 attribute->atttypmod,
7339 elog(
ERROR,
"failed to coerce base type to domain");
7347 newval->attnum = attribute->attnum;
7385 if (children && !recurse)
7387 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7388 errmsg(
"column must be added to child tables too")));
7401 foreach(child, children)
7416 &childcmd, recurse,
true,
7457 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7458 errmsg(
"column name \"%s\" conflicts with a system column name",
7465 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7466 errmsg(
"column \"%s\" of relation \"%s\" already exists, skipping",
7472 (
errcode(ERRCODE_DUPLICATE_COLUMN),
7473 errmsg(
"column \"%s\" of relation \"%s\" already exists",
7489 myself.
classId = RelationRelationId;
7492 referenced.
classId = TypeRelationId;
7510 myself.
classId = RelationRelationId;
7513 referenced.
classId = CollationRelationId;
7544 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7545 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7553 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7554 errmsg(
"cannot alter system column \"%s\"",
7557 if (attTup->attidentity)
7559 (
errcode(ERRCODE_SYNTAX_ERROR),
7560 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
7580 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
7587 if (indexStruct->indisprimary || indexStruct->indisreplident)
7594 for (
int i = 0;
i < indexStruct->indnkeyatts;
i++)
7596 if (indexStruct->indkey.values[
i] ==
attnum)
7598 if (indexStruct->indisprimary)
7600 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7601 errmsg(
"column \"%s\" is in a primary key",
7605 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7606 errmsg(
"column \"%s\" is in index used as replica identity",
7618 if (rel->
rd_rel->relispartition)
7625 parent_attnum =
get_attnum(parentId, colName);
7628 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7629 errmsg(
"column \"%s\" is marked NOT NULL in parent table",
7637 if (attTup->attnotnull)
7639 attTup->attnotnull =
false;
7687 if (rel->
rd_rel->relhassubclass &&
7688 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
7698 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7699 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7713 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
7732 const char *colName,
LOCKMODE lockmode)
7749 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7750 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7759 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7760 errmsg(
"cannot alter system column \"%s\"",
7766 if (!attTup->attnotnull)
7768 attTup->attnotnull =
true;
7815 const char *colName,
LOCKMODE lockmode)
7823 errcode(ERRCODE_UNDEFINED_COLUMN),
7824 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7829 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7830 errmsg(
"constraint must be added to child tables too"),
7831 errdetail(
"Column \"%s\" of relation \"%s\" is not already NOT NULL.",
7833 errhint(
"Do not specify the ONLY keyword.")));
7860 nnulltest->argisrow =
false;
7866 (
errmsg_internal(
"existing constraints on column \"%s.%s\" are sufficient to prove that it does not contain nulls",
7893 (
errcode(ERRCODE_UNDEFINED_COLUMN),
7894 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
7900 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7901 errmsg(
"cannot alter system column \"%s\"",
7906 (
errcode(ERRCODE_SYNTAX_ERROR),
7907 errmsg(
"column \"%s\" of relation \"%s\" is an identity column",
7910 newDefault ? 0 :
errhint(
"Use %s instead.",
7911 "ALTER TABLE ... ALTER COLUMN ... DROP IDENTITY")));
7915 (
errcode(ERRCODE_SYNTAX_ERROR),
7916 errmsg(
"column \"%s\" of relation \"%s\" is a generated column",
7920 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... SET EXPRESSION") :
7922 errhint(
"Use %s instead.",
"ALTER TABLE ... ALTER COLUMN ... DROP EXPRESSION") : 0)));
7934 newDefault != NULL);
7952 false,
true,
false, NULL);
7996 Node *def,
LOCKMODE lockmode,
bool recurse,
bool recursing)
8006 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8007 if (ispartitioned && !recurse)
8009 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8010 errmsg(
"cannot add identity to a column of only the partitioned table"),
8011 errhint(
"Do not specify the ONLY keyword.")));
8013 if (rel->
rd_rel->relispartition && !recursing)
8015 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8016 errmsg(
"cannot add identity to a column of a partition"));
8023 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8024 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8032 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8033 errmsg(
"cannot alter system column \"%s\"",
8041 if (!attTup->attnotnull)
8043 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8044 errmsg(
"column \"%s\" of relation \"%s\" must be declared NOT NULL before identity can be added",
8047 if (attTup->attidentity)
8049 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8050 errmsg(
"column \"%s\" of relation \"%s\" is already an identity column",
8053 if (attTup->atthasdef)
8055 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8056 errmsg(
"column \"%s\" of relation \"%s\" already has a default value",
8059 attTup->attidentity = cdef->
identity;
8075 if (recurse && ispartitioned)
8082 foreach(lc, children)
8102 LOCKMODE lockmode,
bool recurse,
bool recursing)
8113 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8114 if (ispartitioned && !recurse)
8116 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8117 errmsg(
"cannot change identity column of only the partitioned table"),
8118 errhint(
"Do not specify the ONLY keyword.")));
8120 if (rel->
rd_rel->relispartition && !recursing)
8122 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8123 errmsg(
"cannot change identity column of a partition"));
8129 if (strcmp(defel->
defname,
"generated") == 0)
8133 (
errcode(ERRCODE_SYNTAX_ERROR),
8134 errmsg(
"conflicting or redundant options")));
8135 generatedEl = defel;
8138 elog(
ERROR,
"option \"%s\" not recognized",
8152 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8153 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8161 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8162 errmsg(
"cannot alter system column \"%s\"",
8165 if (!attTup->attidentity)
8167 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8168 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8192 if (generatedEl && recurse && ispartitioned)
8199 foreach(lc, children)
8219 bool recurse,
bool recursing)
8230 ispartitioned = (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
8231 if (ispartitioned && !recurse)
8233 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8234 errmsg(
"cannot drop identity from a column of only the partitioned table"),
8235 errhint(
"Do not specify the ONLY keyword.")));
8237 if (rel->
rd_rel->relispartition && !recursing)
8239 errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8240 errmsg(
"cannot drop identity from a column of a partition"));
8246 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8247 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8255 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8256 errmsg(
"cannot alter system column \"%s\"",
8259 if (!attTup->attidentity)
8263 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8264 errmsg(
"column \"%s\" of relation \"%s\" is not an identity column",
8269 (
errmsg(
"column \"%s\" of relation \"%s\" is not an identity column, skipping",
8277 attTup->attidentity =
'\0';
8293 if (recurse && ispartitioned)
8300 foreach(lc, children)
8317 seqaddress.
classId = RelationRelationId;
8347 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8348 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8356 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8357 errmsg(
"cannot alter system column \"%s\"",
8360 if (attTup->attgenerated != ATTRIBUTE_GENERATED_STORED)
8362 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8363 errmsg(
"column \"%s\" of relation \"%s\" is not a generated column",
8390 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8410 rawEnt->
generated = ATTRIBUTE_GENERATED_STORED;
8414 false,
true,
false, NULL);
8425 newval->is_generated =
true;
8460 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8461 errmsg(
"ALTER TABLE / DROP EXPRESSION must be applied to child tables too")));
8474 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8475 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8480 if (attTup->attinhcount > 0)
8482 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
8483 errmsg(
"cannot drop generation expression from inherited column")));
8504 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8505 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8513 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8514 errmsg(
"cannot alter system column \"%s\"",
8517 if (attTup->attgenerated != ATTRIBUTE_GENERATED_STORED)
8521 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8522 errmsg(
"column \"%s\" of relation \"%s\" is not a stored generated column",
8527 (
errmsg(
"column \"%s\" of relation \"%s\" is not a stored generated column, skipping",
8539 attTup->attgenerated =
'\0';
8556 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
8585 bool newtarget_default;
8592 Datum repl_val[Natts_pg_attribute];
8593 bool repl_null[Natts_pg_attribute];
8594 bool repl_repl[Natts_pg_attribute];
8600 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
8601 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
8604 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8605 errmsg(
"cannot refer to non-index column by number")));
8608 if (newValue &&
intVal(newValue) != -1)
8610 newtarget =
intVal(newValue);
8611 newtarget_default =
false;
8614 newtarget_default =
true;
8616 if (!newtarget_default)
8624 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8625 errmsg(
"statistics target %d is too low",
8632 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8633 errmsg(
"lowering statistics target to %d",
8646 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8647 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8656 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8657 errmsg(
"column number %d of relation \"%s\" does not exist",
8663 attnum = attrtuple->attnum;
8666 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8667 errmsg(
"cannot alter system column \"%s\"",
8670 if (rel->
rd_rel->relkind == RELKIND_INDEX ||
8671 rel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
8675 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8676 errmsg(
"cannot alter statistics on included column \"%s\" of index \"%s\"",
8680 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8681 errmsg(
"cannot alter statistics on non-expression column \"%s\" of index \"%s\"",
8683 errhint(
"Alter statistics on table column instead.")));
8687 memset(repl_null,
false,
sizeof(repl_null));
8688 memset(repl_repl,
false,
sizeof(repl_repl));
8689 if (!newtarget_default)
8690 repl_val[Anum_pg_attribute_attstattarget - 1] = newtarget;
8692 repl_null[Anum_pg_attribute_attstattarget - 1] =
true;
8693 repl_repl[Anum_pg_attribute_attstattarget - 1] =
true;
8695 repl_val, repl_null, repl_repl);
8729 Datum repl_val[Natts_pg_attribute];
8730 bool repl_null[Natts_pg_attribute];
8731 bool repl_repl[Natts_pg_attribute];
8739 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8740 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8744 attnum = attrtuple->attnum;
8747 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8748 errmsg(
"cannot alter system column \"%s\"",
8761 memset(repl_null,
false,
sizeof(repl_null));
8762 memset(repl_repl,
false,
sizeof(repl_repl));
8763 if (newOptions != (
Datum) 0)
8764 repl_val[Anum_pg_attribute_attoptions - 1] = newOptions;
8766 repl_null[Anum_pg_attribute_attoptions - 1] =
true;
8767 repl_repl[Anum_pg_attribute_attoptions - 1] =
true;
8769 repl_val, repl_null, repl_repl);
8798 bool setstorage,
char newstorage,
8799 bool setcompression,
char newcompression,
8813 for (
int i = 0;
i < indrel->
rd_index->indnatts;
i++)
8835 attrtuple->attstorage = newstorage;
8838 attrtuple->attcompression = newcompression;
8873 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8874 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8878 attnum = attrtuple->attnum;
8881 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8882 errmsg(
"cannot alter system column \"%s\"",
8898 true, attrtuple->attstorage,
8926 if (rel->
rd_rel->reloftype && !recursing)
8928 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
8929 errmsg(
"cannot drop column from typed table")));
8931 if (rel->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
8952 bool recurse,
bool recursing,
8953 bool missing_ok,
LOCKMODE lockmode,
8969 Assert(!recursing || addrs != NULL);
8986 (
errcode(ERRCODE_UNDEFINED_COLUMN),
8987 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
8993 (
errmsg(
"column \"%s\" of relation \"%s\" does not exist, skipping",
9000 attnum = targetatt->attnum;
9005 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9006 errmsg(
"cannot drop system column \"%s\"",
9013 if (targetatt->attinhcount > 0 && !recursing)
9015 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9016 errmsg(
"cannot drop inherited column \"%s\"",
9028 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9029 errmsg(
"cannot drop column \"%s\" because it is part of the partition key of relation \"%s\"",
9051 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE && !recurse)
9053 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9054 errmsg(
"cannot drop column from only the partitioned table when partitions exist"),
9055 errhint(
"Do not specify the ONLY keyword.")));
9058 foreach(child, children)
9070 elog(
ERROR,
"cache lookup failed for attribute \"%s\" of relation %u",
9071 colName, childrelid);
9074 if (childatt->attinhcount <= 0)
9075 elog(
ERROR,
"relation %u has non-inherited attribute \"%s\"",
9076 childrelid, colName);
9085 if (childatt->attinhcount == 1 && !childatt->attislocal)
9089 behavior,
true,
true,
9090 false, lockmode, addrs);
9095 childatt->attinhcount--;
9110 childatt->attinhcount--;
9111 childatt->attislocal =
true;
9127 object.classId = RelationRelationId;
9129 object.objectSubId =
attnum;
9167 check_rights = !is_rebuild;
9239 Oid index_oid =
stmt->indexOid;
9243 char *constraintName;
9244 char constraintType;
9256 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
9258 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9259 errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables")));
9269 elog(
ERROR,
"index \"%s\" is not unique", indexName);
9278 constraintName =
stmt->idxname;
9279 if (constraintName == NULL)
9280 constraintName = indexName;
9281 else if (strcmp(constraintName, indexName) != 0)
9284 (
errmsg(
"ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index \"%s\" to \"%s\"",
9285 indexName, constraintName)));
9295 constraintType = CONSTRAINT_PRIMARY;
9297 constraintType = CONSTRAINT_UNIQUE;
9329 Constraint *newConstraint,
bool recurse,
bool is_readd,
9341 switch (newConstraint->
contype)
9346 newConstraint, recurse,
false, is_readd,
9362 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
9381 elog(
ERROR,
"unrecognized constraint type: %d",
9382 (
int) newConstraint->
contype);
9408 foreach(lc, colnames)
9413 buf[buflen++] =
'_';
9420 buflen += strlen(
buf + buflen);
9444 Constraint *constr,
bool recurse,
bool recursing,
9470 recursing || is_readd,
9480 foreach(lcon, newcons)
9537 if (!recurse && children !=
NIL)
9539 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9540 errmsg(
"constraint must be added to child tables too")));
9542 foreach(child, children)
9557 constr, recurse,
true, is_readd, lockmode);
9583 bool recurse,
bool recursing,
LOCKMODE lockmode)
9596 bool pk_has_without_overlaps;
9619 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
9623 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9624 errmsg(
"cannot use ONLY for foreign key on partitioned table \"%s\" referencing relation \"%s\"",
9629 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9630 errmsg(
"cannot add NOT VALID foreign key on partitioned table \"%s\" referencing relation \"%s\"",
9633 errdetail(
"This feature is not yet supported on partitioned tables.")));
9636 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
9637 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
9639 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
9640 errmsg(
"referenced relation \"%s\" is not a table",
9645 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9646 errmsg(
"permission denied: \"%s\" is a system catalog",
9657 switch (rel->
rd_rel->relpersistence)
9659 case RELPERSISTENCE_PERMANENT:
9662 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9663 errmsg(
"constraints on permanent tables may reference only permanent tables")));
9665 case RELPERSISTENCE_UNLOGGED:
9667 && pkrel->
rd_rel->relpersistence != RELPERSISTENCE_UNLOGGED)
9669 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9670 errmsg(
"constraints on unlogged tables may reference only permanent or unlogged tables")));
9672 case RELPERSISTENCE_TEMP:
9673 if (pkrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
9675 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9676 errmsg(
"constraints on temporary tables may reference only temporary tables")));
9679 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
9680 errmsg(
"constraints on temporary tables must involve temporary tables of this session")));
9690 fkattnum, fktypoid);
9694 errcode(ERRCODE_INVALID_FOREIGN_KEY),
9695 errmsg(
"foreign key uses PERIOD on the referenced table but not the referencing table"));
9699 fkdelsetcols, NULL);
9701 numfkdelsetcols, fkdelsetcols,
9715 opclasses, &pk_has_without_overlaps);
9720 errcode(ERRCODE_INVALID_FOREIGN_KEY),
9721 errmsg(
"foreign key uses PERIOD on the referenced table but not the referencing table"));
9727 pkattnum, pktypoid);
9732 errcode(ERRCODE_INVALID_FOREIGN_KEY),
9733 errmsg(
"foreign key uses PERIOD on the referencing table but not the referenced table"));
9737 with_period, opclasses, &pk_has_without_overlaps);
9744 if (pk_has_without_overlaps && !with_period)
9746 errcode(ERRCODE_INVALID_FOREIGN_KEY),
9747 errmsg(
"foreign key must use PERIOD when referencing a primary using WITHOUT OVERLAPS"));
9757 for (
i = 0;
i < numfks;
i++)
9770 (
errcode(ERRCODE_SYNTAX_ERROR),
9771 errmsg(
"invalid %s action for foreign key constraint containing generated column",
9776 (
errcode(ERRCODE_SYNTAX_ERROR),
9777 errmsg(
"invalid %s action for foreign key constraint containing generated column",
9791 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9792 errmsg(
"unsupported %s action for foreign key constraint using PERIOD",
9799 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9800 errmsg(
"unsupported %s action for foreign key constraint using PERIOD",
9812 if (numfks != numpks)
9814 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
9815 errmsg(
"number of referencing and referenced columns for foreign key disagree")));
9824 for (
i = 0;
i < numpks;
i++)
9826 Oid pktype = pktypoid[
i];
9827 Oid fktype = fktypoid[
i];
9843 elog(
ERROR,
"cache lookup failed for opclass %u", opclasses[
i]);
9845 amid = cla_tup->opcmethod;
9846 opfamily = cla_tup->opcfamily;
9847 opcintype = cla_tup->opcintype;
9853 bool for_overlaps = with_period &&
i == numpks - 1;
9859 if (amid != GIST_AM_OID)
9860 elog(
ERROR,
"only GiST indexes are supported for temporal foreign keys");
9876 elog(
ERROR,
"cache lookup failed for operator class %u", opclasses[
i]);
9879 errcode(ERRCODE_UNDEFINED_OBJECT),
9881 ?
errmsg(
"could not identify an overlaps operator for foreign key")
9882 :
errmsg(
"could not identify an equality operator for foreign key"),
9883 errdetail(
"Could not translate strategy number %d for operator class \"%s\" for access method \"%s\".",
9896 if (amid != BTREE_AM_OID)
9897 elog(
ERROR,
"only b-tree indexes are supported for foreign keys");
9909 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
9910 eqstrategy, opcintype, opcintype, opfamily);
9922 pfeqop_right = fktyped;
9944 Oid input_typeids[2];
9945 Oid target_typeids[2];
9947 input_typeids[0] = pktype;
9948 input_typeids[1] = fktype;
9949 target_typeids[0] = opcintype;
9950 target_typeids[1] = opcintype;
9954 pfeqop = ffeqop = ppeqop;
9955 pfeqop_right = opcintype;
9961 (
errcode(ERRCODE_DATATYPE_MISMATCH),
9962 errmsg(
"foreign key constraint \"%s\" cannot be implemented",
9964 errdetail(
"Key columns \"%s\" and \"%s\" "
9965 "are of incompatible types: %s and %s.",
9979 old_check_ok = (pfeqop ==
lfirst_oid(old_pfeqop_item));
9999 old_fktype = attr->atttypid;
10000 new_fktype = fktype;
10038 old_check_ok = (new_pathtype == old_pathtype &&
10039 new_castfunc == old_castfunc &&
10040 (!IsPolymorphicType(pfeqop_right) ||
10041 new_fktype == old_fktype));
10044 pfeqoperators[
i] = pfeqop;
10045 ppeqoperators[
i] = ppeqop;
10046 ffeqoperators[
i] = ffeqop;
10060 Oid aggedperiodoperoid;
10067 fkconstraint->
conname, fkconstraint, rel, pkrel,
10129 int numfksetcols,
const int16 *fksetcolsattnums,
10132 for (
int i = 0;
i < numfksetcols;
i++)
10134 int16 setcol_attnum = fksetcolsattnums[
i];
10137 for (
int j = 0;
j < numfks;
j++)
10139 if (fkattnums[
j] == setcol_attnum)
10151 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
10152 errmsg(
"column \"%s\" referenced in ON DELETE SET action must be part of foreign key", col)));
10188 char *constraintname,
Constraint *fkconstraint,
10190 int numfks,
int16 *pkattnum,
10191 int16 *fkattnum,
Oid *pfeqoperators,
Oid *ppeqoperators,
10192 Oid *ffeqoperators,
int numfkdelsetcols,
int16 *fkdelsetcols,
10193 bool is_internal,
bool with_period)
10206 if (pkrel->
rd_rel->relkind != RELKIND_RELATION &&
10207 pkrel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
10209 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10210 errmsg(
"referenced relation \"%s\" is not a table",
10225 conname = constraintname;
10227 if (fkconstraint->
conname == NULL)
10232 conislocal =
false;
10234 connoinherit =
false;
10244 connoinherit = rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE;
10252 CONSTRAINT_FOREIGN,
10366 Oid *ppeqoperators,
Oid *ffeqoperators,
10367 int numfkdelsetcols,
int16 *fkdelsetcols,
10369 Oid parentDelTrigger,
Oid parentUpdTrigger,
10372 Oid deleteTriggerOid,
10380 parentConstr, indexOid,
10381 parentDelTrigger, parentUpdTrigger,
10382 &deleteTriggerOid, &updateTriggerOid);
10389 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10413 for (
int j = 0;
j < numfks;
j++)
10414 mapped_pkattnum[
j] = map->
attnums[pkattnum[
j] - 1];
10417 mapped_pkattnum = pkattnum;
10422 elog(
ERROR,
"index for %u not found in partition %s",
10427 fkconstraint->
conname, fkconstraint, rel,
10428 partRel, partIndexId, parentConstr,
10429 numfks, mapped_pkattnum,
10430 fkattnum, pfeqoperators, ppeqoperators,
10431 ffeqoperators, numfkdelsetcols,
10432 fkdelsetcols,
true, with_period);
10435 partIndexId, address.
objectId, numfks,
10436 mapped_pkattnum, fkattnum,
10437 pfeqoperators, ppeqoperators, ffeqoperators,
10438 numfkdelsetcols, fkdelsetcols,
10440 deleteTriggerOid, updateTriggerOid,
10447 pfree(mapped_pkattnum);
10495 int numfks,
int16 *pkattnum,
int16 *fkattnum,
10496 Oid *pfeqoperators,
Oid *ppeqoperators,
Oid *ffeqoperators,
10497 int numfkdelsetcols,
int16 *fkdelsetcols,
10498 bool old_check_ok,
LOCKMODE lockmode,
10499 Oid parentInsTrigger,
Oid parentUpdTrigger,
10502 Oid insertTriggerOid,
10507 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
10509 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10510 errmsg(
"foreign key constraints are not supported on foreign tables")));
10523 parentInsTrigger, parentUpdTrigger,
10524 &insertTriggerOid, &updateTriggerOid);
10526 if (rel->
rd_rel->relkind == RELKIND_RELATION)
10547 newcon->
conid = parentConstr;
10549 newcon->
qual = (
Node *) fkconstraint;
10554 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
10588 for (
int j = 0;
j < numfks;
j++)
10589 mapped_fkattnum[
j] = attmap->
attnums[fkattnum[
j] - 1];
10594 foreach(cell, partFKs)
10624 fkconstraint->
conname, fkconstraint,
10625 partition, pkrel, indexOid, parentConstr,
10627 mapped_fkattnum, pfeqoperators,
10628 ppeqoperators, ffeqoperators,
10629 numfkdelsetcols, fkdelsetcols,
true,
10675 Assert(parentRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
10752 foreach(cell, clone)
10766 int numfkdelsetcols;
10770 Oid deleteTriggerOid,
10775 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
10807 indexOid = constrForm->conindid;
10818 for (
int i = 0;
i < numfks;
i++)
10819 mapped_confkey[
i] = attmap->
attnums[confkey[
i] - 1];
10822 fkconstraint->
contype = CONSTRAINT_FOREIGN;
10824 fkconstraint->
deferrable = constrForm->condeferrable;
10827 fkconstraint->
pktable = NULL;
10830 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
10840 for (
int i = 0;
i < numfks;
i++)
10857 elog(
ERROR,
"index for %u not found in partition %s",
10866 constrForm->confrelid, constrForm->conrelid,
10867 &deleteTriggerOid, &updateTriggerOid);
10871 fkconstraint->
conname, fkconstraint, fkRel,
10872 partitionRel, partIndexId, constrOid,
10873 numfks, mapped_confkey,
10874 conkey, conpfeqop, conppeqop, conffeqop,
10875 numfkdelsetcols, confdelsetcols,
false,
10876 constrForm->conperiod);
10894 constrForm->conperiod);
10942 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10943 errmsg(
"cannot attach table \"%s\" as a partition because it is referenced by foreign key \"%s\"",
10957 if (partRel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
10959 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
10960 errmsg(
"foreign key constraints are not supported on foreign tables")));
10980 foreach(cell, clone)
10993 int numfkdelsetcols;
11000 Oid insertTriggerOid,
11006 elog(
ERROR,
"cache lookup failed for constraint %u",
11022 if (pkrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11027 conpfeqop, conppeqop, conffeqop,
11028 &numfkdelsetcols, confdelsetcols);
11029 for (
int i = 0;
i < numfks;
i++)
11030 mapped_conkey[
i] = attmap->
attnums[conkey[
i] - 1];
11042 constrForm->confrelid, constrForm->conrelid,
11043 &insertTriggerOid, &updateTriggerOid);
11053 foreach(lc, partFKs)
11081 fkconstraint->
contype = CONSTRAINT_FOREIGN;
11083 fkconstraint->
deferrable = constrForm->condeferrable;
11086 fkconstraint->
pktable = NULL;
11089 fkconstraint->
fk_matchtype = constrForm->confmatchtype;
11097 for (
int i = 0;
i < numfks;
i++)
11102 mapped_conkey[
i] - 1);
11107 indexOid = constrForm->conindid;
11108 with_period = constrForm->conperiod;
11112 NameStr(constrForm->conname), fkconstraint,
11113 partRel, pkrel, indexOid, parentConstrOid,
11115 mapped_conkey, conpfeqop,
11116 conppeqop, conffeqop,
11117 numfkdelsetcols, confdelsetcols,
11118 false, with_period);
11163 Oid parentConstrOid,
11168 Oid parentInsTrigger,
11169 Oid parentUpdTrigger,
11179 Oid insertTriggerOid,
11185 elog(
ERROR,
"cache lookup failed for constraint %u", parentConstrOid);
11192 if (fk->
confrelid != parentConstr->confrelid || fk->
nkeys != numfks)
11197 for (
int i = 0;
i < numfks;
i++)
11199 if (fk->conkey[
i] != mapped_conkey[
i] ||
11200 fk->confkey[
i] != confkey[
i] ||
11201 fk->conpfeqop[
i] != conpfeqop[
i])
11219 !partConstr->convalidated ||
11220 partConstr->condeferrable != parentConstr->condeferrable ||
11221 partConstr->condeferred != parentConstr->condeferred ||
11222 partConstr->confupdtype != parentConstr->confupdtype ||
11223 partConstr->confdeltype != parentConstr->confdeltype ||
11224 partConstr->confmatchtype != parentConstr->confmatchtype)
11242 Anum_pg_trigger_tgconstraint,
11252 if (trgform->tgconstrrelid != fk->
conrelid)
11286 &insertTriggerOid, &updateTriggerOid);
11306 Anum_pg_constraint_conrelid,
11311 ConstraintRelidTypidNameIndexId,
11312 true, NULL, 1, &
key);
11318 if (conform->conparentid != fk->
conoid)
11337 ConstraintRelationId,
11346 Anum_pg_trigger_tgconstraint,
11350 true, NULL, 1, &key2);
11380 Oid conoid,
Oid confrelid,
Oid conrelid,
11381 Oid *deleteTriggerOid,
11382 Oid *updateTriggerOid)
11388 *deleteTriggerOid = *updateTriggerOid =
InvalidOid;
11390 Anum_pg_trigger_tgconstraint,
11400 if (trgform->tgconstrrelid != conrelid)
11402 if (trgform->tgrelid != confrelid)
11407 if (TRIGGER_FOR_DELETE(trgform->tgtype))
11410 *deleteTriggerOid = trgform->oid;
11412 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
11415 *updateTriggerOid = trgform->oid;
11417 #ifndef USE_ASSERT_CHECKING
11425 elog(
ERROR,
"could not find ON DELETE action trigger of foreign key constraint %u",
11428 elog(
ERROR,
"could not find ON UPDATE action trigger of foreign key constraint %u",
11441 Oid conoid,
Oid confrelid,
Oid conrelid,
11442 Oid *insertTriggerOid,
11443 Oid *updateTriggerOid)
11449 *insertTriggerOid = *updateTriggerOid =
InvalidOid;
11451 Anum_pg_trigger_tgconstraint,
11461 if (trgform->tgconstrrelid != confrelid)
11463 if (trgform->tgrelid != conrelid)
11468 if (TRIGGER_FOR_INSERT(trgform->tgtype))
11471 *insertTriggerOid = trgform->oid;
11473 else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
11476 *updateTriggerOid = trgform->oid;
11478 #ifndef USE_ASSERT_CHECKING
11486 elog(
ERROR,
"could not find ON INSERT check triggers of foreign key constraint %u",
11489 elog(
ERROR,
"could not find ON UPDATE check triggers of foreign key constraint %u",
11507 bool recursing,
LOCKMODE lockmode)
11529 Anum_pg_constraint_conrelid,
11533 Anum_pg_constraint_contypid,
11537 Anum_pg_constraint_conname,
11541 true, NULL, 3, skey);
11546 (
errcode(ERRCODE_UNDEFINED_OBJECT),
11547 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
11551 if (currcon->contype != CONSTRAINT_FOREIGN)
11553 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11554 errmsg(
"constraint \"%s\" of relation \"%s\" is not a foreign key constraint",
11569 Oid parent = currcon->conparentid;
11570 char *ancestorname = NULL;
11571 char *ancestortable = NULL;
11587 parent = contup->conparentid;
11592 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
11593 errmsg(
"cannot alter constraint \"%s\" on relation \"%s\"",
11595 ancestorname && ancestortable ?
11596 errdetail(
"Constraint \"%s\" is derived from constraint \"%s\" of relation \"%s\".",
11597 cmdcon->
conname, ancestorname, ancestortable) : 0,
11598 errhint(
"You may alter the constraint it derives from instead.")));
11607 if (currcon->condeferrable != cmdcon->
deferrable ||
11609 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
11612 &otherrelids, lockmode))
11621 foreach(lc, otherrelids)
11651 bool changed =
false;
11657 conoid = currcon->oid;
11658 refrelid = currcon->confrelid;
11666 if (currcon->condeferrable != cmdcon->
deferrable ||
11677 copy_con->condeferrable = cmdcon->
deferrable;
11695 Anum_pg_trigger_tgconstraint,
11722 if (tgform->tgfoid != F_RI_FKEY_NOACTION_DEL &&
11723 tgform->tgfoid != F_RI_FKEY_NOACTION_UPD &&
11724 tgform->tgfoid != F_RI_FKEY_CHECK_INS &&
11725 tgform->tgfoid != F_RI_FKEY_CHECK_UPD)
11751 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE ||
11759 Anum_pg_constraint_conparentid,
11764 true, NULL, 1, &pkey);
11771 childrel =
table_open(childcon->conrelid, lockmode);
11773 otherrelids, lockmode);
11796 bool recurse,
bool recursing,
LOCKMODE lockmode)
11811 Anum_pg_constraint_conrelid,
11815 Anum_pg_constraint_contypid,
11819 Anum_pg_constraint_conname,
11823 true, NULL, 3, skey);
11828 (
errcode(ERRCODE_UNDEFINED_OBJECT),
11829 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
11833 if (con->contype != CONSTRAINT_FOREIGN &&
11834 con->contype != CONSTRAINT_CHECK)
11836 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
11837 errmsg(
"constraint \"%s\" of relation \"%s\" is not a foreign key or check constraint",
11840 if (!con->convalidated)
11846 if (con->contype == CONSTRAINT_FOREIGN)
11854 fkconstraint->
conname = constrName;
11857 newcon->
name = constrName;
11859 newcon->
refrelid = con->confrelid;
11861 newcon->
conid = con->oid;
11862 newcon->
qual = (
Node *) fkconstraint;
11873 else if (con->contype == CONSTRAINT_CHECK)
11886 if (!recursing && !con->connoinherit)
11898 foreach(child, children)
11913 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
11914 errmsg(
"constraint must be validated on child tables too")));
11926 newcon->
name = constrName;
11930 newcon->
conid = con->oid;
11933 Anum_pg_constraint_conbin);
11953 copy_con->convalidated =
true;
11991 foreach(l, colList)
12000 (
errcode(ERRCODE_UNDEFINED_COLUMN),
12001 errmsg(
"column \"%s\" referenced in foreign key constraint does not exist",
12004 if (attform->attnum < 0)
12006 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12007 errmsg(
"system columns cannot be used in foreign keys")));
12010 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
12011 errmsg(
"cannot have more than %d keys in a foreign key",
12013 attnums[
attnum] = attform->attnum;
12014 if (atttypids != NULL)
12015 atttypids[
attnum] = attform->atttypid;
12038 List **attnamelist,
12040 Oid *opclasses,
bool *pk_has_without_overlaps)
12042 List *indexoidlist;
12046 Datum indclassDatum;
12059 foreach(indexoidscan, indexoidlist)
12065 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
12067 if (indexStruct->indisprimary && indexStruct->indisvalid)
12074 if (!indexStruct->indimmediate)
12076 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12077 errmsg(
"cannot use a deferrable primary key for referenced table \"%s\"",
12080 *indexOid = indexoid;
12093 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12094 errmsg(
"there is no primary key for referenced table \"%s\"",
12099 Anum_pg_index_indclass);
12106 *attnamelist =
NIL;
12107 for (
i = 0;
i < indexStruct->indnkeyatts;
i++)
12109 int pkattno = indexStruct->indkey.values[
i];
12111 attnums[
i] = pkattno;
12113 opclasses[
i] = indclass->
values[
i];
12114 *attnamelist =
lappend(*attnamelist,
12118 *pk_has_without_overlaps = indexStruct->indisexclusion;
12140 int numattrs,
int16 *attnums,
12141 bool with_period,
Oid *opclasses,
12142 bool *pk_has_without_overlaps)
12145 bool found =
false;
12146 bool found_deferrable =
false;
12147 List *indexoidlist;
12159 for (
i = 0;
i < numattrs;
i++)
12161 for (
j =
i + 1;
j < numattrs;
j++)
12163 if (attnums[
i] == attnums[
j])
12165 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
12166 errmsg(
"foreign key referenced-columns list must not contain duplicates")));
12177 foreach(indexoidscan, indexoidlist)
12185 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
12193 if (indexStruct->indnkeyatts == numattrs &&
12194 (with_period ? indexStruct->indisexclusion : indexStruct->indisunique) &&
12195 indexStruct->indisvalid &&
12199 Datum indclassDatum;
12204 Anum_pg_index_indclass);
12217 for (
i = 0;
i < numattrs;
i++)
12220 for (
j = 0;
j < numattrs;
j++)
12222 if (attnums[
i] == indexStruct->indkey.values[
j])
12224 opclasses[
i] = indclass->
values[
j];
12233 if (found && with_period)
12235 int16 periodattnum = attnums[numattrs - 1];
12237 found = (periodattnum == indexStruct->indkey.values[numattrs - 1]);
12245 if (found && !indexStruct->indimmediate)
12251 found_deferrable =
true;
12257 *pk_has_without_overlaps = indexStruct->indisexclusion;
12266 if (found_deferrable)
12268 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12269 errmsg(
"cannot use a deferrable unique constraint for referenced table \"%s\"",
12273 (
errcode(ERRCODE_INVALID_FOREIGN_KEY),
12274 errmsg(
"there is no unique constraint matching given keys for referenced table \"%s\"",
12294 if (targetTypeId == sourceTypeId)
12305 elog(
ERROR,
"could not find cast from %u to %u",
12306 sourceTypeId, targetTypeId);
12331 for (
i = 0;
i < natts;
i++)
12363 (
errmsg_internal(
"validating foreign key constraint \"%s\"", conname)));
12398 "validateForeignKeyConstraint",
12419 trigdata.
type = T_TriggerData;
12426 fcinfo->context = (
Node *) &trigdata;
12449 Oid constraintOid,
Oid indexOid,
Oid parentTrigOid,
12467 fk_trigger->
trigname =
"RI_ConstraintTrigger_c";
12474 fk_trigger->
events = TRIGGER_TYPE_INSERT;
12479 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
12483 fk_trigger->
row =
true;
12484 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12492 trigAddress =
CreateTrigger(fk_trigger, NULL, myRelOid, refRelOid,
12494 parentTrigOid, NULL,
true,
false);
12512 Oid constraintOid,
Oid indexOid,
12513 Oid parentDelTrigger,
Oid parentUpdTrigger,
12514 Oid *deleteTrigOid,
Oid *updateTrigOid)
12526 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
12529 fk_trigger->
row =
true;
12530 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12531 fk_trigger->
events = TRIGGER_TYPE_DELETE;
12565 elog(
ERROR,
"unrecognized FK action type: %d",
12573 parentDelTrigger, NULL,
true,
false);
12575 *deleteTrigOid = trigAddress.
objectId;
12587 fk_trigger->
trigname =
"RI_ConstraintTrigger_a";
12590 fk_trigger->
row =
true;
12591 fk_trigger->
timing = TRIGGER_TYPE_AFTER;
12592 fk_trigger->
events = TRIGGER_TYPE_UPDATE;
12626 elog(
ERROR,
"unrecognized FK action type: %d",
12634 parentUpdTrigger, NULL,
true,
false);
12636 *updateTrigOid = trigAddress.
objectId;
12651 Oid parentInsTrigger,
Oid parentUpdTrigger,
12652 Oid *insertTrigOid,
Oid *updateTrigOid)
12655 constraintOid, indexOid,
12656 parentInsTrigger,
true);
12658 constraintOid, indexOid,
12659 parentUpdTrigger,
false);
12670 bool recurse,
bool recursing,
12671 bool missing_ok,
LOCKMODE lockmode)
12679 bool found =
false;
12680 bool is_no_inherit_constraint =
false;
12694 Anum_pg_constraint_conrelid,
12698 Anum_pg_constraint_contypid,
12702 Anum_pg_constraint_conname,
12706 true, NULL, 3, skey);
12716 if (con->coninhcount > 0 && !recursing)
12718 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12719 errmsg(
"cannot drop inherited constraint \"%s\" of relation \"%s\"",
12722 is_no_inherit_constraint = con->connoinherit;
12723 contype = con->contype;
12732 if (contype == CONSTRAINT_FOREIGN &&
12746 conobj.
classId = ConstraintRelationId;
12762 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12763 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12769 (
errmsg(
"constraint \"%s\" of relation \"%s\" does not exist, skipping",
12780 if (contype != CONSTRAINT_CHECK &&
12781 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
12792 if (!is_no_inherit_constraint)
12807 Anum_pg_constraint_conrelid,
12811 Anum_pg_constraint_contypid,
12815 Anum_pg_constraint_conname,
12819 true, NULL, 3, skey);
12824 (
errcode(ERRCODE_UNDEFINED_OBJECT),
12825 errmsg(
"constraint \"%s\" of relation \"%s\" does not exist",
12836 if (con->contype != CONSTRAINT_CHECK)
12837 elog(
ERROR,
"inherited constraint is not a CHECK constraint");
12839 if (con->coninhcount <= 0)
12840 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
12841 childrelid, constrName);
12849 if (con->coninhcount == 1 && !con->conislocal)
12859 con->coninhcount--;
12873 con->coninhcount--;
12874 con->conislocal =
true;
12910 bool recurse,
bool recursing,
12914 char *colName = cmd->
name;
12922 int32 targettypmod;
12929 if (rel->
rd_rel->reloftype && !recursing)
12931 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
12932 errmsg(
"cannot alter column type of typed table")));
12938 (
errcode(ERRCODE_UNDEFINED_COLUMN),
12939 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
12942 attnum = attTup->attnum;
12947 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12948 errmsg(
"cannot alter system column \"%s\"",
12957 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
12958 errmsg(
"cannot specify USING when altering type of generated column"),
12959 errdetail(
"Column \"%s\" is a generated column.", colName)));
12966 if (attTup->attinhcount > 0 && !recursing)
12968 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12969 errmsg(
"cannot alter inherited column \"%s\"",
12977 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
12978 errmsg(
"cannot alter column \"%s\" because it is part of the partition key of relation \"%s\"",
12996 if (tab->
relkind == RELKIND_RELATION ||
12997 tab->
relkind == RELKIND_PARTITIONED_TABLE)
13011 attTup->atttypid, attTup->atttypmod,
13012 attTup->attcollation,
13018 targettype, targettypmod,
13022 if (transform == NULL)
13027 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13028 errmsg(
"result of USING clause for column \"%s\""
13029 " cannot be cast automatically to type %s",
13031 errhint(
"You might need to add an explicit cast.")));
13034 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13035 errmsg(
"column \"%s\" cannot be cast automatically to type %s",
13037 !attTup->attgenerated ?
13039 errhint(
"You might need to specify \"USING %s::%s\".",
13042 targettypmod)) : 0));
13058 newval->is_generated =
false;
13064 else if (transform)
13066 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
13067 errmsg(
"\"%s\" is not a table",
13070 if (!RELKIND_HAS_STORAGE(tab->
relkind))
13098 &child_numparents);
13105 forboth(lo, child_oids, li, child_numparents)
13113 if (childrelid == relid)
13130 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13131 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
13135 if (childattTup->attinhcount > numparents)
13137 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13138 errmsg(
"cannot alter inherited column \"%s\" of relation \"%s\"",
13150 bool found_whole_row;
13163 if (found_whole_row)
13165 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13166 errmsg(
"cannot convert whole-row table reference"),
13167 errdetail(
"USING expression contains a whole-row table reference.")));
13174 else if (!recursing &&
13177 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13178 errmsg(
"type of inherited column \"%s\" must be changed in child tables too",
13181 if (tab->
relkind == RELKIND_COMPOSITE_TYPE)
13207 if (
IsA(expr,
Var) && ((
Var *) expr)->varattno == varattno)
13225 case F_TIMESTAMPTZ_TIMESTAMP:
13226 case F_TIMESTAMP_TIMESTAMPTZ:
13250 char *colName = cmd->
name;
13260 int32 targettypmod;
13291 (
errcode(ERRCODE_UNDEFINED_COLUMN),
13292 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
13295 attnum = attTup->attnum;
13299 if (attTup->atttypid != attOldTup->atttypid ||
13300 attTup->atttypmod != attOldTup->atttypmod)
13302 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13303 errmsg(
"cannot alter type of column \"%s\" twice",
13307 typeTuple =
typenameType(NULL, typeName, &targettypmod);
13309 targettype = tform->oid;
13325 if (attTup->atthasdef)
13331 defaultexpr,
exprType(defaultexpr),
13332 targettype, targettypmod,
13336 if (defaultexpr == NULL)
13338 if (attTup->attgenerated)
13340 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13341 errmsg(
"generation expression for column \"%s\" cannot be cast automatically to type %s",
13345 (
errcode(ERRCODE_DATATYPE_MISMATCH),
13346 errmsg(
"default for column \"%s\" cannot be cast automatically to type %s",
13351 defaultexpr = NULL;
13372 Anum_pg_depend_classid,
13376 Anum_pg_depend_objid,
13380 Anum_pg_depend_objsubid,
13392 foundObject.
classId = foundDep->refclassid;
13393 foundObject.
objectId = foundDep->refobjid;
13397 elog(
ERROR,
"found unexpected dependency type '%c'",
13398 foundDep->deptype);
13399 if (!(foundDep->refclassid == TypeRelationId &&
13400 foundDep->refobjid == attTup->atttypid) &&
13401 !(foundDep->refclassid == CollationRelationId &&
13402 foundDep->refobjid == attTup->attcollation))
13403 elog(
ERROR,
"found unexpected dependency for column: %s",
13418 if (attTup->atthasmissing)
13428 Anum_pg_attribute_attmissingval,
13429 attrelation->rd_att,
13445 Datum valuesAtt[Natts_pg_attribute] = {0};
13446 bool nullsAtt[Natts_pg_attribute] = {0};
13447 bool replacesAtt[Natts_pg_attribute] = {0};
13465 valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
13466 replacesAtt[Anum_pg_attribute_attmissingval - 1] =
true;
13467 nullsAtt[Anum_pg_attribute_attmissingval - 1] =
false;
13470 valuesAtt, nullsAtt, replacesAtt);
13477 attTup->atttypid = targettype;
13478 attTup->atttypmod = targettypmod;
13479 attTup->attcollation = targetcollid;
13482 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
13483 errmsg(
"too many array dimensions"));
13484 attTup->attndims =
list_length(typeName->arrayBounds);
13485 attTup->attlen = tform->typlen;
13486 attTup->attbyval = tform->typbyval;
13487 attTup->attalign = tform->typalign;
13488 attTup->attstorage = tform->typstorage;
13523 if (attTup->attgenerated)
13528 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
13577 Anum_pg_depend_refclassid,
13581 Anum_pg_depend_refobjid,
13585 Anum_pg_depend_refobjsubid,
13597 foundObject.
classId = foundDep->classid;
13598 foundObject.
objectId = foundDep->objid;
13603 case RelationRelationId:
13607 if (relKind == RELKIND_INDEX ||
13608 relKind == RELKIND_PARTITIONED_INDEX)
13613 else if (relKind == RELKIND_SEQUENCE)
13624 elog(
ERROR,
"unexpected object depending on column: %s",
13630 case ConstraintRelationId:
13635 case ProcedureRelationId:
13649 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13650 errmsg(
"cannot alter type of a column used by a function or procedure"),
13651 errdetail(
"%s depends on column \"%s\"",
13656 case RewriteRelationId:
13664 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13665 errmsg(
"cannot alter type of a column used by a view or rule"),
13666 errdetail(
"%s depends on column \"%s\"",
13671 case TriggerRelationId:
13684 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13685 errmsg(
"cannot alter type of a column used in a trigger definition"),
13686 errdetail(
"%s depends on column \"%s\"",
13691 case PolicyRelationId:
13703 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13704 errmsg(
"cannot alter type of a column used in a policy definition"),
13705 errdetail(
"%s depends on column \"%s\"",
13710 case AttrDefaultRelationId:
13734 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13735 errmsg(
"cannot alter type of a column used by a generated column"),
13736 errdetail(
"Column \"%s\" is used by generated column \"%s\".",
13745 case StatisticExtRelationId:
13754 case PublicationRelRelationId:
13762 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13763 errmsg(
"cannot alter type of a column used by a publication WHERE clause"),
13764 errdetail(
"%s depends on column \"%s\"",
13775 elog(
ERROR,
"unexpected object depending on column: %s",
13796 elog(
ERROR,
"relation %u has multiple indexes marked as replica identity", tab->
relid);
13811 elog(
ERROR,
"relation %u has multiple clustered indexes", tab->
relid);
13981 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
13984 relid = con->conrelid;
13990 elog(
ERROR,
"could not identify relation associated with constraint %u", oldId);
13992 confrelid = con->confrelid;
13993 contype = con->contype;
13994 conislocal = con->conislocal;
14015 if (relid != tab->
relid && contype == CONSTRAINT_FOREIGN)
14019 (
char *)
lfirst(def_item),
14020 wqueue, lockmode, tab->
rewrite);
14022 forboth(oid_item, tab->changedIndexOids,
14023 def_item, tab->changedIndexDefs)
14030 (
char *)
lfirst(def_item),
14031 wqueue, lockmode, tab->rewrite);
14038 forboth(oid_item, tab->changedStatisticsOids,
14039 def_item, tab->changedStatisticsDefs)
14046 (
char *)
lfirst(def_item),
14047 wqueue, lockmode, tab->rewrite);
14056 if (tab->replicaIdentityIndex)
14062 subcmd->
name = tab->replicaIdentityIndex;
14074 if (tab->clusterOnIndex)
14079 cmd->
name = tab->clusterOnIndex;
14112 List *raw_parsetree_list;
14113 List *querytree_list;
14124 querytree_list =
NIL;
14125 foreach(list_item, raw_parsetree_list)
14131 querytree_list =
lappend(querytree_list,
14145 querytree_list =
list_concat(querytree_list, beforeStmts);
14147 querytree_list =
list_concat(querytree_list, afterStmts);
14150 querytree_list =
lappend(querytree_list,
14169 foreach(list_item, querytree_list)
14183 stmt->reset_default_tblspc =
true;
14198 foreach(lcmd,
stmt->cmds)
14214 RelationRelationId, 0);
14236 !rewrite && tab->
rewrite == 0)
14262 elog(
ERROR,
"unexpected statement subtype: %d",
14270 if (
stmt->subtype ==
'C')
14289 elog(
ERROR,
"unexpected statement subtype: %d",
14290 (
int)
stmt->subtype);
14298 stmt->stxcomment =
GetComment(oldId, StatisticExtRelationId, 0);
14307 elog(
ERROR,
"unexpected statement type: %d",
14327 const char *conname)
14334 comment_str =
GetComment(objid, ConstraintRelationId, 0);
14335 if (comment_str == NULL)
14372 stmt->accessMethod,
14374 stmt->excludeOpNames,
14375 stmt->iswithoutoverlaps))
14380 if (irel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
14412 elog(
ERROR,
"cache lookup failed for constraint %u", oldId);
14415 Anum_pg_constraint_conpfeqop);
14422 elog(
ERROR,
"conpfeqop is not a 1-D Oid array");
14426 for (
i = 0;
i < numkeys;
i++)
14439 const char *colName,
14450 Datum repl_val[Natts_pg_attribute];
14451 bool repl_null[Natts_pg_attribute];
14452 bool repl_repl[Natts_pg_attribute];
14467 (
errcode(ERRCODE_UNDEFINED_OBJECT),
14468 errmsg(
"foreign table \"%s\" does not exist",
14481 (
errcode(ERRCODE_UNDEFINED_COLUMN),
14482 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
14487 attnum = atttableform->attnum;
14490 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14491 errmsg(
"cannot alter system column \"%s\"", colName)));
14495 memset(repl_val, 0,
sizeof(repl_val));
14496 memset(repl_null,
false,
sizeof(repl_null));
14497 memset(repl_repl,
false,
sizeof(repl_repl));
14502 Anum_pg_attribute_attfdwoptions,
14514 repl_val[Anum_pg_attribute_attfdwoptions - 1] = datum;
14516 repl_null[Anum_pg_attribute_attfdwoptions - 1] =
true;
14518 repl_repl[Anum_pg_attribute_attfdwoptions - 1] =
true;
14523 repl_val, repl_null, repl_repl);
14529 atttableform->attnum);
14573 elog(
ERROR,
"cache lookup failed for relation %u", relationOid);
14577 switch (tuple_class->relkind)
14579 case RELKIND_RELATION:
14581 case RELKIND_MATVIEW:
14582 case RELKIND_FOREIGN_TABLE:
14583 case RELKIND_PARTITIONED_TABLE:
14586 case RELKIND_INDEX:
14596 if (tuple_class->relowner != newOwnerId)
14598 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14599 errmsg(
"cannot change owner of index \"%s\"",
14600 NameStr(tuple_class->relname)),
14601 errhint(
"Change the ownership of the index's table instead.")));
14603 newOwnerId = tuple_class->relowner;
14606 case RELKIND_PARTITIONED_INDEX:
14610 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14611 errmsg(
"cannot change owner of index \"%s\"",
14612 NameStr(tuple_class->relname)),
14613 errhint(
"Change the ownership of the index's table instead.")));
14615 case RELKIND_SEQUENCE:
14617 tuple_class->relowner != newOwnerId)
14626 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
14627 errmsg(
"cannot change owner of sequence \"%s\"",
14628 NameStr(tuple_class->relname)),
14629 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
14630 NameStr(tuple_class->relname),
14634 case RELKIND_COMPOSITE_TYPE:
14638 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14639 errmsg(
"\"%s\" is a composite type",
14640 NameStr(tuple_class->relname)),
14645 case RELKIND_TOASTVALUE:
14651 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
14652 errmsg(
"cannot change owner of relation \"%s\"",
14653 NameStr(tuple_class->relname)),
14661 if (tuple_class->relowner != newOwnerId)
14663 Datum repl_val[Natts_pg_class];
14664 bool repl_null[Natts_pg_class];
14665 bool repl_repl[Natts_pg_class];
14677 Oid namespaceOid = tuple_class->relnamespace;
14689 aclresult =
object_aclcheck(NamespaceRelationId, namespaceOid, newOwnerId,
14697 memset(repl_null,
false,
sizeof(repl_null));
14698 memset(repl_repl,
false,
sizeof(repl_repl));
14700 repl_repl[Anum_pg_class_relowner - 1] =
true;
14708 Anum_pg_class_relacl,
14713 tuple_class->relowner, newOwnerId);
14714 repl_repl[Anum_pg_class_relacl - 1] =
true;
14729 tuple_class->relowner,
14737 if (tuple_class->relkind != RELKIND_COMPOSITE_TYPE &&
14738 tuple_class->relkind != RELKIND_INDEX &&
14739 tuple_class->relkind != RELKIND_PARTITIONED_INDEX &&
14740 tuple_class->relkind != RELKIND_TOASTVALUE)
14755 if (tuple_class->relkind == RELKIND_RELATION ||
14756 tuple_class->relkind == RELKIND_PARTITIONED_TABLE ||
14757 tuple_class->relkind == RELKIND_MATVIEW ||
14758 tuple_class->relkind == RELKIND_TOASTVALUE)
14760 List *index_oid_list;
14767 foreach(
i, index_oid_list)
14774 if (tuple_class->reltoastrelid !=
InvalidOid)
14805 Anum_pg_attribute_attrelid,
14809 true, NULL, 1,
key);
14813 Datum repl_val[Natts_pg_attribute];
14814 bool repl_null[Natts_pg_attribute];
14815 bool repl_repl[Natts_pg_attribute];
14822 if (att->attisdropped)
14826 Anum_pg_attribute_attacl,
14833 memset(repl_null,
false,
sizeof(repl_null));
14834 memset(repl_repl,
false,
sizeof(repl_repl));
14837 oldOwnerId, newOwnerId);
14838 repl_repl[Anum_pg_attribute_attacl - 1] =
true;
14843 repl_val, repl_null, repl_repl);
14875 Anum_pg_depend_refclassid,
14879 Anum_pg_depend_refobjid,
14893 if (depForm->refobjsubid == 0 ||
14894 depForm->classid != RelationRelationId ||
14895 depForm->objsubid != 0 ||
14939 (
errcode(ERRCODE_UNDEFINED_OBJECT),
14940 errmsg(
"index \"%s\" for table \"%s\" does not exist",
14950 RelationRelationId, indexOid);
14983 if (amname != NULL)
14985 else if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
14991 if (rel->
rd_rel->relam == amoid)
15011 Oid oldAccessMethodId;
15027 elog(
ERROR,
"cache lookup failed for relation %u", reloid);
15031 oldAccessMethodId = rd_rel->relam;
15032 rd_rel->relam = newAccessMethodId;
15035 if (rd_rel->relam == oldAccessMethodId)
15071 AccessMethodRelationId,
15081 AccessMethodRelationId,
15082 oldAccessMethodId, rd_rel->relam);
15118 (
errcode(ERRCODE_SYNTAX_ERROR),
15119 errmsg(
"cannot have multiple SET TABLESPACE subcommands")));
15138 Datum repl_val[Natts_pg_class];
15139 bool repl_null[Natts_pg_class];
15140 bool repl_repl[Natts_pg_class];
15152 elog(
ERROR,
"cache lookup failed for relation %u", relid);
15172 defList, NULL, validnsps,
false,
15176 switch (rel->
rd_rel->relkind)
15178 case RELKIND_RELATION:
15179 case RELKIND_TOASTVALUE:
15180 case RELKIND_MATVIEW:
15183 case RELKIND_PARTITIONED_TABLE:
15189 case RELKIND_INDEX:
15190 case RELKIND_PARTITIONED_INDEX:
15195 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15196 errmsg(
"cannot set options for relation \"%s\"",
15203 if (rel->
rd_rel->relkind == RELKIND_VIEW)
15208 bool check_option =
false;
15210 foreach(cell, view_options)
15214 if (strcmp(defel->
defname,
"check_option") == 0)
15215 check_option =
true;
15224 const char *view_updatable_error =
15227 if (view_updatable_error)
15229 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15230 errmsg(
"WITH CHECK OPTION is supported only on automatically updatable views"),
15231 errhint(
"%s",
_(view_updatable_error))));
15239 memset(repl_val, 0,
sizeof(repl_val));
15240 memset(repl_null,
false,
sizeof(repl_null));
15241 memset(repl_repl,
false,
sizeof(repl_repl));
15243 if (newOptions != (
Datum) 0)
15244 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
15246 repl_null[Anum_pg_class_reloptions - 1] =
true;
15248 repl_repl[Anum_pg_class_reloptions - 1] =
true;
15251 repl_val, repl_null, repl_repl);
15266 Oid toastid = rel->
rd_rel->reltoastrelid;
15273 elog(
ERROR,
"cache lookup failed for relation %u", toastid);
15292 defList,
"toast", validnsps,
false,
15297 memset(repl_val, 0,
sizeof(repl_val));
15298 memset(repl_null,
false,
sizeof(repl_null));
15299 memset(repl_repl,
false,
sizeof(repl_repl));
15301 if (newOptions != (
Datum) 0)
15302 repl_val[Anum_pg_class_reloptions - 1] = newOptions;
15304 repl_null[Anum_pg_class_reloptions - 1] =
true;
15306 repl_repl[Anum_pg_class_reloptions - 1] =
true;
15309 repl_val, repl_null, repl_repl);
15355 reltoastrelid = rel->
rd_rel->reltoastrelid;
15370 rel->
rd_rel->relpersistence);
15374 newrlocator.
relNumber = newrelfilenumber;
15375 newrlocator.
spcOid = newTableSpace;
15378 if (rel->
rd_rel->relkind == RELKIND_INDEX)
15410 foreach(lc, reltoastidxids)
15472 Oid orig_tablespaceoid;
15473 Oid new_tablespaceoid;
15480 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15481 errmsg(
"only tables, indexes, and materialized views exist in tablespaces")));
15489 if (orig_tablespaceoid == GLOBALTABLESPACE_OID ||
15490 new_tablespaceoid == GLOBALTABLESPACE_OID)
15492 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
15493 errmsg(
"cannot move relations in to or out of pg_global tablespace")));
15522 if (orig_tablespaceoid == new_tablespaceoid)
15523 return new_tablespaceoid;
15530 Anum_pg_class_reltablespace,
15539 Oid relOid = relForm->oid;
15550 relForm->relisshared ||
15557 relForm->relkind != RELKIND_RELATION &&
15558 relForm->relkind != RELKIND_PARTITIONED_TABLE) ||
15560 relForm->relkind != RELKIND_INDEX &&
15561 relForm->relkind != RELKIND_PARTITIONED_INDEX) ||
15563 relForm->relkind != RELKIND_MATVIEW))
15581 if (
stmt->nowait &&
15584 (
errcode(ERRCODE_OBJECT_IN_USE),
15585 errmsg(
"aborting because lock on relation \"%s.%s\" is not available",
15587 NameStr(relForm->relname))));
15598 if (relations ==
NIL)
15600 (
errcode(ERRCODE_NO_DATA_FOUND),
15601 errmsg(
"no matching relations in tablespace \"%s\" found",
15602 orig_tablespaceoid ==
InvalidOid ?
"(database default)" :
15606 foreach(l, relations)
15612 cmd->
name =
stmt->new_tablespacename;
15622 return new_tablespaceoid;
15649 rel->
rd_rel->relpersistence);
15664 (rel->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
15668 rel->
rd_rel->relpersistence);
15684 char fires_when,
bool skip_system,
bool recurse,
15688 fires_when, skip_system, recurse,
15702 char fires_when,
LOCKMODE lockmode)
15720 if (child_rel->
rd_rel->reloftype)
15722 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15723 errmsg(
"cannot change inheritance of typed table")));
15725 if (child_rel->
rd_rel->relispartition)
15727 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15728 errmsg(
"cannot change inheritance of a partition")));
15730 if (child_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
15732 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15733 errmsg(
"cannot change inheritance of partitioned table")));
15745 const char *trigger_name;
15761 if (parent_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
15762 child_rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
15764 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15765 errmsg(
"cannot inherit from temporary relation \"%s\"",
15769 if (parent_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
15772 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15773 errmsg(
"cannot inherit from temporary relation of another session")));
15776 if (child_rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
15779 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15780 errmsg(
"cannot inherit to temporary relation of another session")));
15783 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
15785 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15786 errmsg(
"cannot inherit from partitioned table \"%s\"",
15790 if (parent_rel->
rd_rel->relispartition)
15792 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
15793 errmsg(
"cannot inherit from a partition")));
15814 (
errcode(ERRCODE_DUPLICATE_TABLE),
15815 errmsg(
"circular inheritance not allowed"),
15816 errdetail(
"\"%s\" is already a child of \"%s\".",
15826 if (trigger_name != NULL)
15828 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
15829 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming an inheritance child",
15831 errdetail(
"ROW triggers with transition tables are not supported in inheritance hierarchies.")));
15874 Anum_pg_inherits_inhrelid,
15878 true, NULL, 1, &
key);
15888 (
errcode(ERRCODE_DUPLICATE_TABLE),
15889 errmsg(
"relation \"%s\" would be inherited from more than once",
15892 if (inh->inhseqno > inhseqno)
15893 inhseqno = inh->inhseqno;
15910 parent_rel->
rd_rel->relkind ==
15911 RELKIND_PARTITIONED_TABLE);
15930 attr =
heap_getattr(contup, Anum_pg_constraint_conbin, tupdesc, &isnull);
15932 elog(
ERROR,
"null conbin for constraint %u", con->oid);
15952 if (acon->condeferrable != bcon->condeferrable ||
15953 acon->condeferred != bcon->condeferred ||
15984 for (
AttrNumber parent_attno = 1; parent_attno <= parent_desc->
natts; parent_attno++)
15987 char *parent_attname =
NameStr(parent_att->attname);
15991 if (parent_att->attisdropped)
16000 if (parent_att->atttypid != child_att->atttypid ||
16001 parent_att->atttypmod != child_att->atttypmod)
16003 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16004 errmsg(
"child table \"%s\" has different type for column \"%s\"",
16007 if (parent_att->attcollation != child_att->attcollation)
16009 (
errcode(ERRCODE_COLLATION_MISMATCH),
16010 errmsg(
"child table \"%s\" has different collation for column \"%s\"",
16017 if (parent_att->attnotnull && !child_att->attnotnull)
16019 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16020 errmsg(
"column \"%s\" in child table must be marked NOT NULL",
16026 if (parent_att->attgenerated && !child_att->attgenerated)
16028 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16029 errmsg(
"column \"%s\" in child table must be a generated column", parent_attname)));
16030 if (child_att->attgenerated && !parent_att->attgenerated)
16032 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16033 errmsg(
"column \"%s\" in child table must not be a generated column", parent_attname)));
16041 child_att->attidentity = parent_att->attidentity;
16048 &child_att->attinhcount))
16050 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
16051 errmsg(
"too many inheritance parents"));
16058 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
16060 Assert(child_att->attinhcount == 1);
16061 child_att->attislocal =
false;
16070 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16071 errmsg(
"child table is missing column \"%s\"", parent_attname)));
16108 Anum_pg_constraint_conrelid,
16112 true, NULL, 1, &parent_key);
16120 bool found =
false;
16122 if (parent_con->contype != CONSTRAINT_CHECK)
16126 if (parent_con->connoinherit)
16131 Anum_pg_constraint_conrelid,
16135 true, NULL, 1, &child_key);
16142 if (child_con->contype != CONSTRAINT_CHECK)
16145 if (strcmp(
NameStr(parent_con->conname),
16146 NameStr(child_con->conname)) != 0)
16151 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16152 errmsg(
"child table \"%s\" has different definition for check constraint \"%s\"",
16156 if (child_con->connoinherit)
16158 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
16159 errmsg(
"constraint \"%s\" conflicts with non-inherited constraint on child table \"%s\"",
16166 if (parent_con->convalidated && !child_con->convalidated)
16168 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
16169 errmsg(
"constraint \"%s\" conflicts with NOT VALID constraint on child table \"%s\"",
16180 &child_con->coninhcount))
16182 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
16183 errmsg(
"too many inheritance parents"));
16190 if (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
16192 Assert(child_con->coninhcount == 1);
16193 child_con->conislocal =
false;
16207 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16208 errmsg(
"child table is missing constraint \"%s\"",
16209 NameStr(parent_con->conname))));
16227 if (rel->
rd_rel->relispartition)
16229 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16230 errmsg(
"cannot change inheritance of a partition")));
16270 bool found =
false;
16272 Assert(parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
16280 Anum_pg_inherits_inhparent,
16284 true, NULL, 1, &
key);
16291 if (inhForm->inhdetachpending)
16293 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
16294 errmsg(
"partition \"%s\" already pending detach in partitioned table \"%s.%s\"",
16298 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation."));
16323 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
16356 bool is_partitioning;
16358 is_partitioning = (parent_rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
16366 if (is_partitioning)
16369 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
16375 errmsg(
"relation \"%s\" is not a parent of relation \"%s\"",
16385 Anum_pg_attribute_attrelid,
16389 true, NULL, 1,
key);
16395 if (att->attisdropped)
16397 if (att->attinhcount <= 0)
16407 copy_att->attinhcount--;
16408 if (copy_att->attinhcount == 0)
16409 copy_att->attislocal =
true;
16426 Anum_pg_constraint_conrelid,
16430 true, NULL, 1,
key);
16438 if (con->contype == CONSTRAINT_CHECK)
16446 Anum_pg_constraint_conrelid,
16450 true, NULL, 1,
key);
16457 if (con->contype != CONSTRAINT_CHECK)
16463 if (strcmp(
NameStr(con->conname), chkname) == 0)
16476 if (copy_con->coninhcount <= 0)
16477 elog(
ERROR,
"relation %u has non-inherited constraint \"%s\"",
16480 copy_con->coninhcount--;
16481 if (copy_con->coninhcount == 0)
16482 copy_con->conislocal =
true;
16493 RelationRelationId,
16526 Anum_pg_depend_classid,
16530 Anum_pg_depend_objid,
16534 Anum_pg_depend_objsubid,
16545 if (dep->refclassid == refclassid &&
16546 dep->refobjid == refobjid &&
16547 dep->refobjsubid == 0 &&
16548 dep->deptype == deptype)
16589 typeid = typeform->oid;
16594 Anum_pg_inherits_inhrelid,
16598 true, NULL, 1, &
key);
16601 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16602 errmsg(
"typed tables cannot inherit")));
16613 for (type_attno = 1; type_attno <= typeTupleDesc->
natts; type_attno++)
16617 const char *type_attname,
16622 if (type_attr->attisdropped)
16624 type_attname =
NameStr(type_attr->attname);
16629 if (table_attno > tableTupleDesc->
natts)
16631 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16632 errmsg(
"table is missing column \"%s\"",
16634 table_attr =
TupleDescAttr(tableTupleDesc, table_attno - 1);
16636 }
while (table_attr->attisdropped);
16637 table_attname =
NameStr(table_attr->attname);
16640 if (strncmp(table_attname, type_attname,
NAMEDATALEN) != 0)
16642 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16643 errmsg(
"table has column \"%s\" where type requires \"%s\"",
16644 table_attname, type_attname)));
16647 if (table_attr->atttypid != type_attr->atttypid ||
16648 table_attr->atttypmod != type_attr->atttypmod ||
16649 table_attr->attcollation != type_attr->attcollation)
16651 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16652 errmsg(
"table \"%s\" has different type for column \"%s\"",
16658 for (; table_attno <= tableTupleDesc->
natts; table_attno++)
16663 if (!table_attr->attisdropped)
16665 (
errcode(ERRCODE_DATATYPE_MISMATCH),
16666 errmsg(
"table has extra column \"%s\"",
16667 NameStr(table_attr->attname))));
16671 if (rel->
rd_rel->reloftype)
16676 tableobj.
classId = RelationRelationId;
16679 typeobj.
classId = TypeRelationId;
16688 elog(
ERROR,
"cache lookup failed for relation %u", relid);
16717 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16718 errmsg(
"\"%s\" is not a typed table",
16733 elog(
ERROR,
"cache lookup failed for relation %u", relid);
16771 elog(
ERROR,
"cache lookup failed for relation \"%s\"",
16774 if (pg_class_form->relreplident != ri_type)
16776 pg_class_form->relreplident = ri_type;
16789 bool dirty =
false;
16794 elog(
ERROR,
"cache lookup failed for index %u", thisIndexOid);
16797 if (thisIndexOid == indexOid)
16800 if (!pg_index_form->indisreplident)
16803 pg_index_form->indisreplident =
true;
16809 if (pg_index_form->indisreplident)
16812 pg_index_form->indisreplident =
false;
16847 if (
stmt->identity_type == REPLICA_IDENTITY_DEFAULT)
16852 else if (
stmt->identity_type == REPLICA_IDENTITY_FULL)
16857 else if (
stmt->identity_type == REPLICA_IDENTITY_NOTHING)
16862 else if (
stmt->identity_type == REPLICA_IDENTITY_INDEX)
16867 elog(
ERROR,
"unexpected identity type %u",
stmt->identity_type);
16873 (
errcode(ERRCODE_UNDEFINED_OBJECT),
16874 errmsg(
"index \"%s\" for table \"%s\" does not exist",
16883 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16884 errmsg(
"\"%s\" is not an index for table \"%s\"",
16891 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16892 errmsg(
"cannot use non-unique index \"%s\" as replica identity",
16895 if (!indexRel->
rd_index->indimmediate)
16897 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16898 errmsg(
"cannot use non-immediate index \"%s\" as replica identity",
16903 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16904 errmsg(
"cannot use expression index \"%s\" as replica identity",
16909 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16910 errmsg(
"cannot use partial index \"%s\" as replica identity",
16926 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
16927 errmsg(
"index \"%s\" cannot be used as replica identity because column %d is a system column",
16931 if (!attr->attnotnull)
16933 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
16934 errmsg(
"index \"%s\" cannot be used as replica identity because column \"%s\" is nullable",
16963 elog(
ERROR,
"cache lookup failed for relation %u", relid);
16992 elog(
ERROR,
"cache lookup failed for relation %u", relid);
17015 Datum repl_val[Natts_pg_foreign_table];
17016 bool repl_null[Natts_pg_foreign_table];
17017 bool repl_repl[Natts_pg_foreign_table];
17030 (
errcode(ERRCODE_UNDEFINED_OBJECT),
17031 errmsg(
"foreign table \"%s\" does not exist",
17037 memset(repl_val, 0,
sizeof(repl_val));
17038 memset(repl_null,
false,
sizeof(repl_null));
17039 memset(repl_repl,
false,
sizeof(repl_repl));
17044 Anum_pg_foreign_table_ftoptions,
17056 repl_val[Anum_pg_foreign_table_ftoptions - 1] = datum;
17058 repl_null[Anum_pg_foreign_table_ftoptions - 1] =
true;
17060 repl_repl[Anum_pg_foreign_table_ftoptions - 1] =
true;
17065 repl_val, repl_null, repl_repl);
17090 const char *column,
17102 compression =
strVal(newValue);
17110 (
errcode(ERRCODE_UNDEFINED_COLUMN),
17111 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
17116 attnum = atttableform->attnum;
17119 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17120 errmsg(
"cannot alter system column \"%s\"", column)));
17129 atttableform->attcompression = cmethod;
17178 switch (rel->
rd_rel->relpersistence)
17180 case RELPERSISTENCE_TEMP:
17182 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17183 errmsg(
"cannot change logged status of table \"%s\" because it is temporary",
17187 case RELPERSISTENCE_PERMANENT:
17192 case RELPERSISTENCE_UNLOGGED:
17206 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
17207 errmsg(
"cannot change table \"%s\" to unlogged because it is part of a publication",
17209 errdetail(
"Unlogged relations cannot be replicated.")));
17223 toLogged ? Anum_pg_constraint_conrelid :
17224 Anum_pg_constraint_confrelid,
17228 toLogged ? ConstraintRelidTypidNameIndexId :
InvalidOid,
17229 true, NULL, 1, skey);
17235 if (con->contype == CONSTRAINT_FOREIGN)
17241 foreignrelid = toLogged ? con->confrelid : con->conrelid;
17253 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17254 errmsg(
"could not change table \"%s\" to logged because it references unlogged table \"%s\"",
17263 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
17264 errmsg(
"could not change table \"%s\" to unlogged because it references logged table \"%s\"",
17309 (
errmsg(
"relation \"%s\" does not exist, skipping",
17310 stmt->relation->relname)));
17319 if (rel->
rd_rel->relkind == RELKIND_SEQUENCE)
17327 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
17328 errmsg(
"cannot move an owned sequence into another schema"),
17329 errdetail(
"Sequence \"%s\" is linked to table \"%s\".",
17348 *oldschema = oldNspOid;
17367 Assert(objsMoved != NULL);
17373 nspOid,
true, objsMoved);
17400 Oid oldNspOid,
Oid newNspOid,
17401 bool hasDependEntry,
17407 bool already_done =
false;
17412 elog(
ERROR,
"cache lookup failed for relation %u", relOid);
17415 Assert(classForm->relnamespace == oldNspOid);
17417 thisobj.
classId = RelationRelationId;
17427 if (!already_done && oldNspOid != newNspOid)
17435 (
errcode(ERRCODE_DUPLICATE_TABLE),
17436 errmsg(
"relation \"%s\" already exists in schema \"%s\"",
17441 classForm->relnamespace = newNspOid;
17448 if (hasDependEntry &&
17451 NamespaceRelationId,
17454 elog(
ERROR,
"could not change schema dependency for relation \"%s\"",
17455 NameStr(classForm->relname));
17484 foreach(l, indexList)
17489 thisobj.
classId = RelationRelationId;
17504 oldNspOid, newNspOid,
17537 Anum_pg_depend_refclassid,
17541 Anum_pg_depend_refobjid,
17555 if (depForm->refobjsubid == 0 ||
17556 depForm->classid != RelationRelationId ||
17557 depForm->objsubid != 0 ||
17574 oldNspOid, newNspOid,
17650 if (oc->
relid == relid)
17668 List *oids_to_truncate =
NIL;
17709 if (oids_to_truncate !=
NIL)
17712 if (oids_to_drop !=
NIL)
17716 foreach(l, oids_to_drop)
17720 object.
classId = RelationRelationId;
17722 object.objectSubId = 0;
17744 #ifdef USE_ASSERT_CHECKING
17857 if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE &&
17858 relkind != RELKIND_MATVIEW && relkind != RELKIND_PARTITIONED_TABLE)
17860 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17861 errmsg(
"\"%s\" is not a table or materialized view", relation->
relname)));
17886 elog(
ERROR,
"cache lookup failed for relation %u", relId);
17910 elog(
ERROR,
"cache lookup failed for relation %u", relId);
17919 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
17920 errmsg(
"permission denied: \"%s\" is a system catalog",
17945 relkind = classform->relkind;
17954 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
17955 errmsg(
"permission denied: \"%s\" is a system catalog",
17966 aclresult =
object_aclcheck(NamespaceRelationId, classform->relnamespace,
17993 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
17996 if (reltype ==
OBJECT_VIEW && relkind != RELKIND_VIEW)
17998 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18003 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18004 errmsg(
"\"%s\" is not a materialized view", rv->
relname)));
18008 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18011 if (reltype ==
OBJECT_TYPE && relkind != RELKIND_COMPOSITE_TYPE)
18013 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18016 if (reltype ==
OBJECT_INDEX && relkind != RELKIND_INDEX &&
18017 relkind != RELKIND_PARTITIONED_INDEX
18020 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18027 if (reltype !=
OBJECT_TYPE && relkind == RELKIND_COMPOSITE_TYPE)
18029 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18041 if (relkind == RELKIND_INDEX || relkind == RELKIND_PARTITIONED_INDEX)
18043 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18044 errmsg(
"cannot change schema of index \"%s\"",
18046 errhint(
"Change the schema of the table instead.")));
18047 else if (relkind == RELKIND_COMPOSITE_TYPE)
18049 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18050 errmsg(
"cannot change schema of composite type \"%s\"",
18055 else if (relkind == RELKIND_TOASTVALUE)
18057 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18058 errmsg(
"cannot change schema of TOAST table \"%s\"",
18060 errhint(
"Change the schema of the table instead.")));
18089 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18090 errmsg(
"cannot use \"list\" partition strategy with more than one column")));
18098 NULL,
false,
true);
18131 List **partexprs,
Oid *partopclass,
Oid *partcollation,
18139 foreach(lc, partParams)
18145 if (pelem->
name != NULL)
18155 (
errcode(ERRCODE_UNDEFINED_COLUMN),
18156 errmsg(
"column \"%s\" named in partition key does not exist",
18161 if (attform->attnum <= 0)
18163 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18164 errmsg(
"cannot use system column \"%s\" in partition key",
18172 if (attform->attgenerated)
18174 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18175 errmsg(
"cannot use generated column in partition key"),
18176 errdetail(
"Column \"%s\" is a generated column.",
18180 partattrs[attn] = attform->attnum;
18181 atttype = attform->atttypid;
18182 attcollation = attform->attcollation;
18189 char partattname[16];
18201 snprintf(partattname,
sizeof(partattname),
"%d", attn + 1);
18203 atttype, attcollation,
18214 ((
Var *) expr)->varattno > 0)
18220 partattrs[attn] = ((
Var *) expr)->varattno;
18227 partattrs[attn] = 0;
18228 *partexprs =
lappend(*partexprs, expr);
18247 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18248 errmsg(
"partition key expressions cannot contain system column references")));
18264 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18265 errmsg(
"cannot use generated column in partition key"),
18266 errdetail(
"Column \"%s\" is a generated column.",
18294 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18295 errmsg(
"functions in partition key expression must be marked IMMUTABLE")));
18303 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
18304 errmsg(
"cannot use constant expression as partition key")));
18324 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
18325 errmsg(
"could not determine which collation to use for partition expression"),
18326 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
18332 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18333 errmsg(
"collations are not supported by type %s",
18337 partcollation[attn] = attcollation;
18345 am_oid = HASH_AM_OID;
18347 am_oid = BTREE_AM_OID;
18357 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18358 errmsg(
"data type %s has no default operator class for access method \"%s\"",
18360 errhint(
"You must specify a hash operator class or define a default hash operator class for the data type.")));
18363 (
errcode(ERRCODE_UNDEFINED_OBJECT),
18364 errmsg(
"data type %s has no default operator class for access method \"%s\"",
18366 errhint(
"You must specify a btree operator class or define a default btree operator class for the data type.")));
18372 am_oid == HASH_AM_OID ?
"hash" :
"btree",
18389 List *partConstraint)
18399 for (
i = 1;
i <= natts;
i++)
18403 if (att->attnotnull && !att->attisdropped)
18420 ntest->argisrow =
false;
18422 existConstraint =
lappend(existConstraint, ntest);
18448 num_check = (constr != NULL) ? constr->
num_check : 0;
18449 for (
i = 0;
i < num_check;
i++)
18499 List *partConstraint,
18500 bool validate_default)
18508 if (!validate_default)
18510 (
errmsg_internal(
"partition constraint for table \"%s\" is implied by existing constraints",
18514 (
errmsg_internal(
"updated partition constraint for default partition \"%s\" is implied by existing constraints",
18524 if (scanrel->
rd_rel->relkind == RELKIND_RELATION)
18534 else if (scanrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
18542 List *thisPartConstraint;
18553 thisPartConstraint =
18555 part_rel, scanrel);
18558 thisPartConstraint,
18576 List *attachrel_children;
18577 List *partConstraint;
18584 const char *trigger_name;
18585 Oid defaultPartOid;
18586 List *partBoundConstraint;
18615 if (attachrel->
rd_rel->relispartition)
18617 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18618 errmsg(
"\"%s\" is already a partition",
18623 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18624 errmsg(
"cannot attach a typed table as partition")));
18632 Anum_pg_inherits_inhrelid,
18639 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18640 errmsg(
"cannot attach inheritance child as partition")));
18645 Anum_pg_inherits_inhparent,
18651 attachrel->
rd_rel->relkind == RELKIND_RELATION)
18653 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18654 errmsg(
"cannot attach inheritance parent as partition")));
18677 (
errcode(ERRCODE_DUPLICATE_TABLE),
18678 errmsg(
"circular inheritance not allowed"),
18679 errdetail(
"\"%s\" is already a child of \"%s\".",
18684 if (rel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
18685 attachrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
18687 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18688 errmsg(
"cannot attach a temporary relation as partition of permanent relation \"%s\"",
18692 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
18693 attachrel->
rd_rel->relpersistence != RELPERSISTENCE_TEMP)
18695 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18696 errmsg(
"cannot attach a permanent relation as partition of temporary relation \"%s\"",
18700 if (rel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
18703 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18704 errmsg(
"cannot attach as partition of temporary relation of another session")));
18707 if (attachrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
18710 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18711 errmsg(
"cannot attach temporary relation of another session as partition")));
18718 natts = tupleDesc->
natts;
18719 for (attno = 1; attno <= natts; attno++)
18722 char *attributeName =
NameStr(attribute->attname);
18725 if (attribute->attisdropped)
18728 if (attribute->attidentity)
18730 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
18731 errmsg(
"table \"%s\" being attached contains an identity column \"%s\"",
18733 errdetail(
"The new partition may not contain an identity column."));
18740 (
errcode(ERRCODE_DATATYPE_MISMATCH),
18741 errmsg(
"table \"%s\" contains column \"%s\" not found in parent \"%s\"",
18744 errdetail(
"The new partition may contain only the columns present in parent.")));
18753 if (trigger_name != NULL)
18755 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18756 errmsg(
"trigger \"%s\" prevents table \"%s\" from becoming a partition",
18758 errdetail(
"ROW triggers with transition tables are not supported on partitions.")));
18766 cmd->
bound, pstate);
18802 if (partConstraint)
18811 (
Node *) partConstraint);
18838 List *defPartConstraint;
18844 defPartConstraint =
18851 defPartConstraint =
18853 1, defaultrel, rel);
18855 defPartConstraint,
true);
18869 if (attachrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
18873 foreach(l, attachrel_children)
18897 List *attachRelIdxs;
18905 "AttachPartitionEnsureIndexes",
18929 if (attachrel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
18931 foreach(cell, idxes)
18936 if (idxRel->
rd_index->indisunique ||
18939 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
18940 errmsg(
"cannot attach foreign table \"%s\" as partition of partitioned table \"%s\"",
18943 errdetail(
"Partitioned table \"%s\" contains unique indexes.",
18955 foreach(cell, idxes)
18961 bool found =
false;
18968 if (idxRel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
18992 if (attachrelIdxRels[
i]->rd_rel->relispartition)
18996 if (!attachrelIdxRels[
i]->rd_index->indisvalid)
19000 attachrelIdxRels[
i]->rd_indcollation,
19055 true,
false,
false,
false,
false);
19087 true, NULL, 1, &
key);
19106 if (!TRIGGER_FOR_ROW(trigForm->tgtype))
19113 if (trigForm->tgisinternal)
19119 if (!TRIGGER_FOR_BEFORE(trigForm->tgtype) &&
19120 !TRIGGER_FOR_AFTER(trigForm->tgtype))
19121 elog(
ERROR,
"unexpected trigger \"%s\" found",
19137 partition, parent);
19139 partition, parent);
19146 if (trigForm->tgattr.dim1 > 0)
19150 for (
i = 0;
i < trigForm->tgattr.dim1;
i++)
19155 trigForm->tgattr.values[
i] - 1);
19162 if (trigForm->tgnargs > 0)
19169 elog(
ERROR,
"tgargs is null for trigger \"%s\" in partition \"%s\"",
19174 for (
int i = 0;
i < trigForm->tgnargs;
i++)
19177 p += strlen(p) + 1;
19187 trigStmt->
args = trigargs;
19188 trigStmt->
row =
true;
19189 trigStmt->
timing = trigForm->tgtype & TRIGGER_TYPE_TIMING_MASK;
19190 trigStmt->
events = trigForm->tgtype & TRIGGER_TYPE_EVENT_MASK;
19194 trigStmt->
deferrable = trigForm->tgdeferrable;
19200 trigForm->tgfoid, trigForm->oid, qual,
19201 false,
true, trigForm->tgenabled);
19237 Oid defaultPartOid;
19264 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19265 errmsg(
"cannot detach partitions concurrently when a default partition exists")));
19307 char *parentrelname;
19369 if (partRel != NULL)
19370 elog(
WARNING,
"dangling partition \"%s\" remains, can't fix",
19373 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19374 errmsg(
"partitioned table \"%s\" was removed concurrently",
19377 if (partRel == NULL)
19379 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19380 errmsg(
"partition \"%s\" was removed concurrently", partrelname)));
19404 Oid defaultPartOid)
19410 Datum new_val[Natts_pg_class];
19411 bool new_null[Natts_pg_class],
19412 new_repl[Natts_pg_class];
19442 Oid insertTriggerOid,
19451 if (conform->contype != CONSTRAINT_FOREIGN ||
19462 elog(
ERROR,
"cache lookup failed for constraint %u",
19463 conform->conparentid);
19477 &insertTriggerOid, &updateTriggerOid);
19503 int numfkdelsetcols;
19520 fkconstraint->
contype = CONSTRAINT_FOREIGN;
19522 fkconstraint->
deferrable = conform->condeferrable;
19527 fkconstraint->
pktable = NULL;
19541 for (
int i = 0;
i < numfks;
i++)
19546 attmap->
attnums[conkey[
i] - 1] - 1);
19567 conform->conperiod);
19591 ConstraintRelationId,
19601 foreach(cell, indexes)
19607 Oid parentConstrOid;
19639 elog(
ERROR,
"cache lookup failed for relation %u",
19644 memset(new_val, 0,
sizeof(new_val));
19645 memset(new_null,
false,
sizeof(new_null));
19646 memset(new_repl,
false,
sizeof(new_repl));
19647 new_val[Anum_pg_class_relpartbound - 1] = (
Datum) 0;
19648 new_null[Anum_pg_class_relpartbound - 1] =
true;
19649 new_repl[Anum_pg_class_relpartbound - 1] =
true;
19651 new_val, new_null, new_repl);
19665 if (!attr->attisdropped && attr->attidentity)
19699 if (partRel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
19705 foreach(cell, children)
19756 List *constraintExpr;
19812 true, NULL, 1, &skey);
19838 RelationRelationId,
19877 if (!
state->lockedParentTbl)
19880 state->lockedParentTbl =
true;
19903 if (classform->relkind != RELKIND_PARTITIONED_INDEX &&
19904 classform->relkind != RELKIND_INDEX)
19906 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
19941 state.lockedParentTbl =
false;
19949 (
errcode(ERRCODE_UNDEFINED_OBJECT),
19950 errmsg(
"index \"%s\" does not exist",
name->relname)));
19962 currParent = partIdx->
rd_rel->relispartition ?
19983 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
19984 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
19987 errdetail(
"Index \"%s\" is already attached to another index.",
19995 if (partDesc->
oids[
i] ==
state.partitionOid)
20003 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20004 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20007 errdetail(
"Index \"%s\" is not an index on any partition of table \"%s\".",
20024 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
20025 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20028 errdetail(
"The index definitions do not match.")));
20043 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
20044 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20047 errdetail(
"The index \"%s\" belongs to a constraint in table \"%s\" but no constraint exists for index \"%s\".",
20085 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
20086 errmsg(
"cannot attach index \"%s\" as a partition of index \"%s\"",
20089 errdetail(
"Another index is already attached for partition \"%s\".",
20107 bool updated =
false;
20109 Assert(partedIdx->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX);
20131 elog(
ERROR,
"cache lookup failed for index %u", inhForm->inhrelid);
20133 if (indexForm->indisvalid)
20156 elog(
ERROR,
"cache lookup failed for index %u",
20160 indexForm->indisvalid =
true;
20173 if (updated && partedIdx->
rd_rel->relispartition)
20239 constraints =
lappend_oid(constraints, constrForm->oid);
20245 return constraints;
20261 foreach(cell, constraints)
20271 elog(
ERROR,
"cache lookup failed for constraint %u", constrOid);
20307 if (compression == NULL || strcmp(compression,
"default") == 0)
20324 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20325 errmsg(
"column data type %s does not support compression",
20331 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20332 errmsg(
"invalid compression method \"%s\"", compression)));
20346 cstorage = TYPSTORAGE_PLAIN;
20348 cstorage = TYPSTORAGE_EXTERNAL;
20350 cstorage = TYPSTORAGE_EXTENDED;
20352 cstorage = TYPSTORAGE_MAIN;
20357 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
20358 errmsg(
"invalid storage type \"%s\"",
20367 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
20368 errmsg(
"column data type %s can only have storage PLAIN",
Datum idx(PG_FUNCTION_ARGS)
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
void check_can_set_role(Oid member, Oid role)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Oid get_table_am_oid(const char *amname, bool missing_ok)
#define DatumGetArrayTypeP(X)
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
void free_attrmap(AttrMap *map)
AttrMap * make_attrmap(int maplen)
AttrMap * build_attrmap_by_name_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
#define InvalidAttrNumber
char * get_tablespace_name(Oid spc_oid)
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Oid GetDefaultTablespace(char relpersistence, bool partitioned)
List * raw_parser(const char *str, RawParseMode mode)
bool TimestampTimestampTzRequiresRewrite(void)
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_make_singleton(int x)
void FlushRelationBuffers(Relation rel)
#define TextDatumGetCString(d)
#define PG_USED_FOR_ASSERTS_ONLY
#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
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)
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)
static bool pg_add_s16_overflow(int16 a, int16 b, int16 *result)
void AcceptInvalidationMessages(void)
void CacheInvalidateRelcache(Relation relation)
void CacheInvalidateRelcacheByRelid(Oid relid)
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
if(TABLE==NULL||TABLE_index==NULL)
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_concat_copy(const List *list1, const List *list2)
List * list_append_unique_oid(List *list, Oid datum)
void list_free_deep(List *list)
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
bool CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode, bool orstronger)
void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
#define AccessExclusiveLock
#define ShareRowExclusiveLock
#define InplaceUpdateTupleLock
#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
#define FKCONSTR_ACTION_NOACTION
List * SystemFuncName(char *name)
void check_new_partition_bound(char *relname, Relation parent, PartitionBoundSpec *spec, ParseState *pstate)
List * get_qual_from_partbound(Relation parent, PartitionBoundSpec *spec)
void check_default_partition_contents(Relation parent, Relation default_rel, PartitionBoundSpec *new_spec)
List * RelationGetPartitionQual(Relation rel)
PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached)
Oid get_default_oid_from_partdesc(PartitionDesc partdesc)
bool has_partition_attrs(Relation rel, Bitmapset *attnums, bool *used_in_expr)
List * map_partition_varattnos(List *expr, int fromrel_varno, Relation to_rel, Relation from_rel)
List * get_proposed_default_constraint(List *new_part_constraints)
void update_default_partition_oid(Oid parentId, Oid defaultPartId)
Oid index_get_partition(Relation partition, Oid indexId)
Oid get_partition_parent(Oid relid, bool even_if_detached)
Oid GetAttrDefaultOid(Oid relid, AttrNumber attnum)
Oid StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr, bool is_internal, bool add_column_mode)
ObjectAddress GetAttrDefaultColumnAddress(Oid attrdefoid)
void RemoveAttrDefault(Oid relid, AttrNumber attnum, DropBehavior behavior, bool complain, bool internal)
FormData_pg_attribute * Form_pg_attribute
int errdetail_relkind_not_supported(char relkind)
FormData_pg_class * Form_pg_class
#define PARTITION_MAX_KEYS
char * ChooseConstraintName(const char *name1, const char *name2, const char *label, Oid namespaceid, List *others)
bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)
void RenameConstraintById(Oid conId, const char *newname)
Oid get_relation_idx_constraint_oid(Oid relationId, Oid indexId)
void ConstraintSetParentConstraint(Oid childConstrId, Oid parentConstrId, Oid childTableId)
void DeconstructFkConstraintRow(HeapTuple tuple, int *numfks, AttrNumber *conkey, AttrNumber *confkey, Oid *pf_eq_oprs, Oid *pp_eq_oprs, Oid *ff_eq_oprs, int *num_fk_del_set_cols, AttrNumber *fk_del_set_cols)
void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, Oid newNspId, bool isType, ObjectAddresses *objsMoved)
void FindFKPeriodOpers(Oid opclass, Oid *containedbyoperoid, Oid *aggedcontainedbyoperoid)
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
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, int16 conInhCount, bool conNoInherit, bool conPeriod, bool is_internal)
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)
long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId, char deptype, Oid refclassId, Oid refobjectId)
Oid getIdentitySequence(Relation rel, AttrNumber attnum, bool missing_ok)
Oid get_index_constraint(Oid indexId)
List * getOwnedSequences(Oid relid)
bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId)
FormData_pg_depend * Form_pg_depend
FormData_pg_foreign_table * Form_pg_foreign_table
FormData_pg_index * Form_pg_index
bool DeleteInheritsTuple(Oid inhrelid, Oid inhparent, bool expect_detach_pending, const char *childname)
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
void StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)
List * find_inheritance_children(Oid parentrelId, LOCKMODE lockmode)
bool has_superclass(Oid relationId)
bool PartitionHasPendingDetach(Oid partoid)
FormData_pg_inherits * Form_pg_inherits
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
#define foreach_current_index(var_or_cell)
#define foreach_delete_current(lst, var_or_cell)
#define list_make1_oid(x1)
#define foreach_ptr(type, var, lst)
static ListCell * list_head(const List *l)
#define for_each_from(cell, lst, N)
#define list_make3(x1, x2, x3)
static void * list_nth(const List *list, int n)
#define foreach_oid(var, lst)
#define list_nth_node(type, list, n)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make2(x1, x2)
FormData_pg_opclass * Form_pg_opclass
List * GetRelationPublications(Oid relid)
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
void changeDependencyOnTablespace(Oid classId, Oid objectId, Oid newTablespaceId)
FormData_pg_trigger * Form_pg_trigger
void RenameTypeInternal(Oid typeOid, const char *newTypeName, Oid typeNamespace)
FormData_pg_type * Form_pg_type
#define ERRCODE_UNDEFINED_TABLE
void pgstat_count_truncate(Relation rel)
Expr * expression_planner(Expr *expr)
int pg_strcasecmp(const char *s1, const char *s2)
size_t strlcpy(char *dst, const char *src, size_t siz)
void check_stack_depth(void)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static Datum CharGetDatum(char X)
void CheckTableForSerializableConflictIn(Relation relation)
void TransferPredicateLocksToHeapRelation(Relation relation)
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Expr * canonicalize_qual(Expr *qual, bool is_check)
MemoryContextSwitchTo(old_ctx)
void * stringToNode(const char *str)
#define RelationGetForm(relation)
#define RelationGetRelid(relation)
#define RelationIsLogicallyLogged(relation)
#define RelationIsUsedAsCatalogTable(relation)
static SMgrRelation RelationGetSmgr(Relation rel)
#define RelationGetDescr(relation)
#define RelationIsMapped(relation)
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
#define RELATION_IS_OTHER_TEMP(relation)
#define RelationGetNamespace(relation)
#define IndexRelationGetNumberOfKeyAttributes(relation)
#define RelationIsPermanent(relation)
List * RelationGetIndexList(Relation relation)
int errtableconstraint(Relation rel, const char *conname)
int errtablecol(Relation rel, int attnum)
List * RelationGetIndexPredicate(Relation relation)
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
List * RelationGetFKeyList(Relation relation)
void RelationSetNewRelfilenumber(Relation relation, char persistence)
void RelationAssumeNewRelfilelocator(Relation relation)
int errtable(Relation rel)
List * RelationGetIndexExpressions(Relation relation)
struct RelationData * Relation
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, const char *const validnsps[], bool acceptOidsOff, bool isReset)
List * untransformRelOptions(Datum options)
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
bool reset_default_tblspc
NullTestType nulltesttype
SubTransactionId creating_subid
SubTransactionId deleting_subid
const char * p_sourcetext
PartitionBoundSpec * bound
PartitionStrategy strategy
struct IndexAmRoutine * rd_indam
SubTransactionId rd_firstRelfilelocatorSubid
SubTransactionId rd_newRelfilelocatorSubid
SubTransactionId rd_createSubid
RelFileLocator rd_locator
TupleTableSlot * tg_trigslot
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 SearchSysCacheLocked1(int cacheId, Datum key1)
HeapTuple SearchSysCacheLockedCopy1(int cacheId, Datum key1)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
HeapTuple SearchSysCacheAttNum(Oid relid, int16 attnum)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
bool SearchSysCacheExistsAttName(Oid relid, const char *attname)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
#define SearchSysCacheCopy1(cacheId, key1)
#define SearchSysCacheExists2(cacheId, key1, key2)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
char * default_table_access_method
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
static void table_endscan(TableScanDesc scan)
#define TABLE_INSERT_SKIP_FSM
static void table_finish_bulk_insert(Relation rel, int options)
static void table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
static void table_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
static AttrNumber renameatt_internal(Oid myrelid, const char *oldattname, const char *newattname, bool recurse, bool recursing, int expected_parents, DropBehavior behavior)
void ResetRelRewrite(Oid myrelid)
static void MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel, bool ispartition)
static ObjectAddress ATExecSetNotNull(AlteredTableInfo *tab, Relation rel, const char *colName, LOCKMODE lockmode)
static void MarkInheritDetached(Relation child_rel, Relation parent_rel)
static ObjectAddress ATExecAlterColumnGenericOptions(Relation rel, const char *colName, List *options, LOCKMODE lockmode)
static void ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode, AlterTableUtilityContext *context)
static ObjectAddress ATExecAddInherit(Relation child_rel, RangeVar *parent, LOCKMODE lockmode)
ObjectAddress RenameRelation(RenameStmt *stmt)
static AlteredTableInfo * ATGetQueueEntry(List **wqueue, Relation rel)
static void ATExecDropOf(Relation rel, LOCKMODE lockmode)
static ColumnDef * MergeInheritedAttribute(List *inh_columns, int exist_attno, const ColumnDef *newdef)
static 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)
static void ATExecDropConstraint(Relation rel, const char *constrName, DropBehavior behavior, bool recurse, bool recursing, bool missing_ok, LOCKMODE lockmode)
static ObjectAddress ATExecDropIdentity(Relation rel, const char *colName, bool missing_ok, LOCKMODE lockmode, bool recurse, bool recursing)
static char GetAttributeCompression(Oid atttypid, const char *compression)
static ObjectAddress ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
static int findAttrByName(const char *attributeName, const List *columns)
static int transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, List **attnamelist, int16 *attnums, Oid *atttypids, Oid *opclasses, bool *pk_has_without_overlaps)
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 Oid transformFkeyCheckAttrs(Relation pkrel, int numattrs, int16 *attnums, bool with_period, Oid *opclasses, bool *pk_has_without_overlaps)
void RemoveRelations(DropStmt *drop)
static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacename, LOCKMODE lockmode)
static void ATTypedTableRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void RememberReplicaIdentityForRebuilding(Oid indoid, AlteredTableInfo *tab)
static List * MergeAttributes(List *columns, const List *supers, char relpersistence, bool is_partition, List **supconstr)
static List * GetParentedForeignKeyRefs(Relation partition)
void AlterRelationNamespaceInternal(Relation classRel, Oid relOid, Oid oldNspOid, Oid newNspOid, bool hasDependEntry, ObjectAddresses *objsMoved)
static ObjectAddress ATExecAddConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *newConstraint, bool recurse, bool is_readd, LOCKMODE lockmode)
ObjectAddress renameatt(RenameStmt *stmt)
void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lockmode)
static void RangeVarCallbackForAlterRelation(const RangeVar *rv, Oid relid, Oid oldrelid, void *arg)
static void CheckAlterTableIsSafe(Relation rel)
static void DropErrorMsgWrongType(const char *relname, char wrongkind, char rightkind)
LOCKMODE AlterTableGetLockLevel(List *cmds)
static int transformColumnNameList(Oid relId, List *colList, int16 *attnums, Oid *atttypids)
struct ForeignTruncateInfo ForeignTruncateInfo
static ObjectAddress ATExecDetachPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, RangeVar *name, bool concurrent)
static bool ATExecAlterConstrRecurse(Constraint *cmdcon, Relation conrel, Relation tgrel, Relation rel, HeapTuple contuple, List **otherrelids, LOCKMODE lockmode)
static void AlterSeqNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved, LOCKMODE lockmode)
static void RangeVarCallbackForRenameAttribute(const RangeVar *rv, Oid relid, Oid oldrelid, void *arg)
TupleDesc BuildDescForRelation(const List *columns)
static void ATExecForceNoForceRowSecurity(Relation rel, bool force_rls)
void AtEOXact_on_commit_actions(bool isCommit)
static void checkFkeyPermissions(Relation rel, int16 *attnums, int natts)
struct OnCommitItem OnCommitItem
void CheckTableNotInUse(Relation rel, const char *stmt)
static void ATExecEnableDisableTrigger(Relation rel, const char *trigname, char fires_when, bool skip_system, bool recurse, LOCKMODE lockmode)
static void createForeignKeyActionTriggers(Relation rel, Oid refRelOid, Constraint *fkconstraint, Oid constraintOid, Oid indexOid, Oid parentDelTrigger, Oid parentUpdTrigger, Oid *deleteTrigOid, Oid *updateTrigOid)
static void renameatt_check(Oid myrelid, Form_pg_class classform, bool recursing)
static void RangeVarCallbackForAttachIndex(const RangeVar *rv, Oid relOid, Oid oldRelOid, void *arg)
static void ATCheckPartitionsNotInUse(Relation rel, LOCKMODE lockmode)
static void truncate_check_activity(Relation rel)
static void validatePartitionedIndex(Relation partedIdx, Relation partedTbl)
static ObjectAddress ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *fkconstraint, bool recurse, bool recursing, LOCKMODE lockmode)
static void TryReuseIndex(Oid oldId, IndexStmt *stmt)
static void GetForeignKeyCheckTriggers(Relation trigrel, Oid conoid, Oid confrelid, Oid conrelid, Oid *insertTriggerOid, Oid *updateTriggerOid)
static ObjectAddress addFkConstraint(addFkConstraintSides fkside, char *constraintname, Constraint *fkconstraint, Relation rel, Relation pkrel, Oid indexOid, Oid parentConstr, int numfks, int16 *pkattnum, int16 *fkattnum, Oid *pfeqoperators, Oid *ppeqoperators, Oid *ffeqoperators, int numfkdelsetcols, int16 *fkdelsetcols, bool is_internal, bool with_period)
static void ATPrepSetNotNull(List **wqueue, Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void RememberClusterOnForRebuilding(Oid indoid, AlteredTableInfo *tab)
static ObjectAddress ATExecSetOptions(Relation rel, const char *colName, Node *options, bool isReset, LOCKMODE lockmode)
static ObjectAddress ATExecDropColumn(List **wqueue, Relation rel, const char *colName, DropBehavior behavior, bool recurse, bool recursing, bool missing_ok, LOCKMODE lockmode, ObjectAddresses *addrs)
static void CloneFkReferencing(List **wqueue, Relation parentRel, Relation partRel)
static void SetIndexStorageProperties(Relation rel, Relation attrelation, AttrNumber attnum, bool setstorage, char newstorage, bool setcompression, char newcompression, LOCKMODE lockmode)
static void ATController(AlterTableStmt *parsetree, Relation rel, List *cmds, bool recurse, LOCKMODE lockmode, AlterTableUtilityContext *context)
bool CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId)
static void ATExecSetRowSecurity(Relation rel, bool rls)
static void ATExecCheckNotNull(AlteredTableInfo *tab, Relation rel, const char *colName, LOCKMODE lockmode)
void find_composite_type_dependencies(Oid typeOid, Relation origRelation, const char *origTypeName)
static void truncate_check_perms(Oid relid, Form_pg_class reltuple)
static void truncate_check_rel(Oid relid, Form_pg_class reltuple)
static void change_owner_recurse_to_sequences(Oid relationOid, Oid newOwnerId, LOCKMODE lockmode)
static void StoreCatalogInheritance1(Oid relationId, Oid parentOid, int32 seqNumber, Relation inhRelation, bool child_is_partition)
static void RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, Relation rel, AttrNumber attnum, const char *colName)
static void ATPrepDropExpression(Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode)
static ObjectAddress ATExecCookedColumnDefault(Relation rel, AttrNumber attnum, Node *newDefault)
static ObjectAddress rename_constraint_internal(Oid myrelid, Oid mytypid, const char *oldconname, const char *newconname, bool recurse, bool recursing, int expected_parents)
static void DropErrorMsgNonExistent(RangeVar *rel, char rightkind, bool missing_ok)
static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab, LOCKMODE lockmode)
static bool tryAttachPartitionForeignKey(ForeignKeyCacheInfo *fk, Oid partRelid, Oid parentConstrOid, int numfks, AttrNumber *mapped_conkey, AttrNumber *confkey, Oid *conpfeqop, Oid parentInsTrigger, Oid parentUpdTrigger, Relation trigrel)
static AlterTableCmd * ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses *objsMoved)
static 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 void relation_mark_replica_identity(Relation rel, char ri_type, Oid indexOid, bool is_internal)
#define ATT_FOREIGN_TABLE
static ObjectAddress ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode)
static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing, bool is_view, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNumber *partattrs, List **partexprs, Oid *partopclass, Oid *partcollation, PartitionStrategy strategy)
static void CloneRowTriggersToPartition(Relation parent, Relation partition)
static void AttachPartitionEnsureIndexes(List **wqueue, Relation rel, Relation attachrel)
static void StoreCatalogInheritance(Oid relationId, List *supers, bool child_is_partition)
static ObjectAddress ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, Constraint *constr, bool recurse, bool recursing, bool is_readd, LOCKMODE lockmode)
static void ATExecGenericOptions(Relation rel, List *options)
static void TryReuseForeignKey(Oid oldId, Constraint *con)
struct AlteredTableInfo AlteredTableInfo
static void validateFkOnDeleteSetColumns(int numfks, const int16 *fkattnums, int numfksetcols, const int16 *fksetcolsattnums, List *fksetcols)
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
struct NewConstraint NewConstraint
static ObjectAddress ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newValue, LOCKMODE lockmode)
static void ATSimpleRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd, bool recurse, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void DetachPartitionFinalize(Relation rel, Relation partRel, bool concurrent, Oid defaultPartOid)
static void RebuildConstraintComment(AlteredTableInfo *tab, AlterTablePass pass, Oid objid, Relation rel, List *domname, const char *conname)
static void CloneForeignKeyConstraints(List **wqueue, Relation parentRel, Relation partitionRel)
static void addFkRecurseReferenced(Constraint *fkconstraint, Relation rel, Relation pkrel, Oid indexOid, Oid parentConstr, int numfks, int16 *pkattnum, int16 *fkattnum, Oid *pfeqoperators, Oid *ppeqoperators, Oid *ffeqoperators, int numfkdelsetcols, int16 *fkdelsetcols, bool old_check_ok, Oid parentDelTrigger, Oid parentUpdTrigger, bool with_period)
static bool check_for_column_name_collision(Relation rel, const char *colname, bool if_not_exists)
static ObjectAddress ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, AlterTableCmd **cmd, bool recurse, bool recursing, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
@ AT_PASS_ADD_OTHERCONSTR
@ AT_PASS_ADD_INDEXCONSTR
static ObjectAddress ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd, LOCKMODE lockmode)
static void validateForeignKeyConstraint(char *conname, Relation rel, Relation pkrel, Oid pkindOid, Oid constraintOid, bool hasperiod)
void SetRelationTableSpace(Relation rel, Oid newTableSpaceId, RelFileNumber newRelFilenumber)
void remove_on_commit_action(Oid relid)
static void DetachAddConstraintIfNeeded(List **wqueue, Relation partRel)
static void ATExecDropCluster(Relation rel, LOCKMODE lockmode)
#define ATT_PARTITIONED_INDEX
static void CreateInheritance(Relation child_rel, Relation parent_rel, bool ispartition)
static const struct dropmsgstrings dropmsgstringarray[]
static void ATPrepChangePersistence(AlteredTableInfo *tab, Relation rel, bool toLogged)
static ObjectAddress ATExecSetExpression(AlteredTableInfo *tab, Relation rel, const char *colName, Node *newExpr, LOCKMODE lockmode)
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
static Oid CreateFKCheckTrigger(Oid myRelOid, Oid refRelOid, Constraint *fkconstraint, Oid constraintOid, Oid indexOid, Oid parentTrigOid, bool on_insert)
static void 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)
#define ATT_PARTITIONED_TABLE
static char * decompile_conbin(HeapTuple contup, TupleDesc tupdesc)
static void ATExecCmd(List **wqueue, AlteredTableInfo *tab, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTablePass cur_pass, AlterTableUtilityContext *context)
static void ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode)
static void createForeignKeyCheckTriggers(Oid myRelOid, Oid refRelOid, Constraint *fkconstraint, Oid constraintOid, Oid indexOid, Oid parentInsTrigger, Oid parentUpdTrigger, Oid *insertTrigOid, Oid *updateTrigOid)
static void ATPrepAddInherit(Relation child_rel)
static ObjectAddress ATExecDetachPartitionFinalize(Relation rel, RangeVar *name)
static ObjectAddress ATExecSetStorage(Relation rel, const char *colName, Node *newValue, LOCKMODE lockmode)
static ObjectAddress ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd, AlterTableUtilityContext *context)
static List * find_typed_table_dependencies(Oid typeOid, const char *typeName, DropBehavior behavior)
Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
static ObjectAddress ATExecAddIdentity(Relation rel, const char *colName, Node *def, LOCKMODE lockmode, bool recurse, bool recursing)
static void ATExecSetAccessMethodNoStorage(Relation rel, Oid newAccessMethodId)
static ObjectAddress ATExecAddIndex(AlteredTableInfo *tab, Relation rel, IndexStmt *stmt, bool is_rebuild, LOCKMODE lockmode)
static ObjectAddress ATExecSetCompression(Relation rel, const char *column, Node *newValue, LOCKMODE lockmode)
static PartitionSpec * transformPartitionSpec(Relation rel, PartitionSpec *partspec)
static void ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd, bool recurse, bool recursing, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
static void index_copy_data(Relation rel, RelFileLocator newrlocator)
void RenameRelationInternal(Oid myrelid, const char *newrelname, bool is_internal, bool is_index)
static void ATExecSetTableSpaceNoStorage(Relation rel, Oid newTableSpace)
static void ATPrepAlterColumnType(List **wqueue, AlteredTableInfo *tab, Relation rel, bool recurse, bool recursing, AlterTableCmd *cmd, LOCKMODE lockmode, AlterTableUtilityContext *context)
static void change_owner_fix_column_acls(Oid relationOid, Oid oldOwnerId, Oid newOwnerId)
#define ATT_COMPOSITE_TYPE
static ObjectAddress ATExecAttachPartitionIdx(List **wqueue, Relation parentIdx, RangeVar *name)
bool PartConstraintImpliedByRelConstraint(Relation scanrel, List *partConstraint)
void RangeVarCallbackMaintainsTable(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
static const char * alter_table_type_to_string(AlterTableType cmdtype)
static bool constraints_equivalent(HeapTuple a, HeapTuple b, TupleDesc tupleDesc)
static ObjectAddress ATExecAddStatistics(AlteredTableInfo *tab, Relation rel, CreateStatsStmt *stmt, bool is_rebuild, LOCKMODE lockmode)
ObjectAddress RenameConstraint(RenameStmt *stmt)
static void ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode, AlterTableUtilityContext *context)
void register_on_commit_action(Oid relid, OnCommitAction action)
static void RangeVarCallbackForTruncate(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
static ObjectAddress ATExecClusterOn(Relation rel, const char *indexName, LOCKMODE lockmode)
static char GetAttributeStorage(Oid atttypid, const char *storagemode)
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
#define child_dependency_type(child_is_partition)
static void refuseDupeIndexAttach(Relation parentIdx, Relation partIdx, Relation partitionTbl)
void ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged, DropBehavior behavior, bool restart_seqs, bool run_as_table_owner)
static void ATExecEnableDisableRule(Relation rel, const char *rulename, char fires_when, LOCKMODE lockmode)
struct NewColumnValue NewColumnValue
static void ATPrepSetAccessMethod(AlteredTableInfo *tab, Relation rel, const char *amname)
static bool NotNullImpliedByRelConstraints(Relation rel, Form_pg_attribute attr)
const char * GetCompressionMethodName(char method)
char CompressionNameToMethod(const char *compression)
#define CompressionMethodIsValid(cm)
#define InvalidCompressionMethod
void AlterTableCreateToastTable(Oid relOid, Datum reloptions, LOCKMODE lockmode)
void ExecBSTruncateTriggers(EState *estate, ResultRelInfo *relinfo)
void EnableDisableTrigger(Relation rel, const char *tgname, Oid tgparent, char fires_when, bool skip_system, bool recurse, LOCKMODE lockmode)
void ExecASTruncateTriggers(EState *estate, ResultRelInfo *relinfo)
const char * FindTriggerIncompatibleWithInheritance(TriggerDesc *trigdesc)
ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition)
void TriggerSetParentTrigger(Relation trigRel, Oid childTrigId, Oid parentTrigId, Oid childTableId)
ObjectAddress CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition, char trigger_fires_when)
bool AfterTriggerPendingOnRel(Oid relid)
void AfterTriggerEndQuery(EState *estate)
void AfterTriggerBeginQuery(void)
#define TRIGGER_FIRES_ON_ORIGIN
#define TRIGGER_FIRES_ON_REPLICA
#define TRIGGER_EVENT_ROW
#define TRIGGER_FIRES_ALWAYS
#define TRIGGER_EVENT_INSERT
TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc)
TupleDesc CreateTemplateTupleDesc(int natts)
Node * TupleDescGetDefault(TupleDesc tupdesc, AttrNumber attnum)
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
#define ReleaseTupleDesc(tupdesc)
#define TupleDescAttr(tupdesc, i)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
static void slot_getallattrs(TupleTableSlot *slot)
static bool slot_attisnull(TupleTableSlot *slot, int attnum)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
bool DomainHasConstraints(Oid type_id)
void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId)
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
void checkDomainOwner(HeapTuple tup)
Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid, bool isImplicitArray, bool ignoreDependent, bool errorOnTableType, ObjectAddresses *objsMoved)
List * roleSpecsToIds(List *memberNames)
void SwitchToUntrustedUser(Oid userid, UserContext *context)
void RestoreUserContext(UserContext *context)
void ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
#define MAX_STATISTICS_TARGET
String * makeString(char *str)
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
SubTransactionId GetCurrentSubTransactionId(void)
void CommandCounterIncrement(void)
void StartTransactionCommand(void)
void CommitTransactionCommand(void)
CommandId GetCurrentCommandId(bool used)
#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE
#define XLogLogicalInfoActive()
#define XLOG_INCLUDE_ORIGIN
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void XLogSetRecordFlags(uint8 flags)
void XLogRegisterData(const char *data, uint32 len)
void XLogBeginInsert(void)