34#include "utils/fmgroids.h"
518 char *conname =
NULL;
529 if (
label[0] !=
'\0')
606 true,
NULL, 1, &key);
672 true,
NULL, 1, &key);
683 if (!con->convalidated)
717 elog(
ERROR,
"conkey is not a 1-D smallint array");
742 bool is_local,
bool is_no_inherit,
bool is_notvalid)
760 if (is_no_inherit !=
conform->connoinherit)
763 errmsg(
"cannot change NO INHERIT status of NOT NULL constraint \"%s\" on relation \"%s\"",
765 errhint(
"You might need to make the existing constraint inheritable using %s.",
766 "ALTER TABLE ... ALTER CONSTRAINT ... INHERIT"));
775 errmsg(
"incompatible NOT VALID constraint \"%s\" on relation \"%s\"",
777 errhint(
"You might need to validate it using %s.",
778 "ALTER TABLE ... VALIDATE CONSTRAINT"));
786 errmsg(
"too many inheritance parents"));
856 cooked->is_enforced =
true;
880 notnulls =
lappend(notnulls, constr);
936 elog(
ERROR,
"cache lookup failed for relation %u",
944 elog(
WARNING,
"relation \"%s\" has relchecks = %d",
1010 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
1018 errmsg(
"constraint \"%s\" for domain %s already exists",
1131 elog(
ERROR,
"constraint %u already has a parent constraint",
1139 errmsg(
"too many inheritance parents"));
1219 errmsg(
"constraint \"%s\" for table \"%s\" does not exist",
1294 elog(
ERROR,
"conkey is not a 1-D smallint array");
1312 errmsg(
"constraint \"%s\" for table \"%s\" does not exist",
1345 true,
NULL, 1, &key);
1412 errmsg(
"constraint \"%s\" for domain %s does not exist",
1483 elog(
ERROR,
"null conkey for constraint %u",
1491 elog(
ERROR,
"conkey is not a 1-D smallint array");
1495 for (
i = 0;
i < numkeys;
i++)
1523 Oid *pf_eq_oprs,
Oid *pp_eq_oprs,
Oid *ff_eq_oprs,
1542 elog(
ERROR,
"conkey is not a 1-D smallint array");
1545 elog(
ERROR,
"foreign key constraint cannot have %d columns", numkeys);
1557 elog(
ERROR,
"confkey is not a 1-D smallint array");
1572 elog(
ERROR,
"conpfeqop is not a 1-D Oid array");
1587 elog(
ERROR,
"conppeqop is not a 1-D Oid array");
1602 elog(
ERROR,
"conffeqop is not a 1-D Oid array");
1608 if (fk_del_set_cols)
1624 elog(
ERROR,
"confdelsetcols is not a 1-D smallint array");
1666 errmsg(
"invalid type for PERIOD part of foreign key"),
1667 errdetail(
"Only range and multirange are supported."));
1671 elog(
ERROR,
"cache lookup failed for opclass %u", opclass);
1705 elog(
ERROR,
"unexpected opcintype: %u", opcintype);
1747 gvar->varno == varno &&
1748 gvar->varlevelsup == varlevelsup)
#define DatumGetArrayTypeP(X)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
#define InvalidAttrNumber
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_add_member(Bitmapset *a, int x)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define Assert(condition)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
void free_object_addresses(ObjectAddresses *addrs)
@ DEPENDENCY_PARTITION_PRI
@ DEPENDENCY_PARTITION_SEC
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define palloc_object(type)
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)
HeapTuple heap_copytuple(HeapTuple tuple)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static void * GETSTRUCT(const HeapTupleData *tuple)
char * makeObjectName(const char *name1, const char *name2, const char *label)
void GetOperatorFromCompareType(Oid opclass, Oid rhstype, CompareType cmptype, Oid *opid, StrategyNumber *strat)
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
static bool pg_add_s16_overflow(int16 a, int16 b, int16 *result)
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
#define AccessExclusiveLock
char * get_rel_name(Oid relid)
AttrNumber get_attnum(Oid relid, const char *attname)
bool get_opclass_opfamily_and_input_type(Oid opclass, Oid *opfamily, Oid *opcintype)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
char * pstrdup(const char *in)
void pfree(void *pointer)
void namestrcpy(Name name, const char *str)
#define IsA(nodeptr, _type_)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
#define InvokeObjectPostCreateHookArg(classId, objectId, subId, is_internal)
#define ObjectAddressSet(addr, class_id, object_id)
#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
FormData_pg_class * Form_pg_class
Oid CreateConstraintEntry(const char *constraintName, Oid constraintNamespace, char constraintType, bool isDeferrable, bool isDeferred, bool isEnforced, bool isValidated, Oid parentConstrId, Oid relId, const int16 *constraintKey, int constraintNKeys, int constraintNTotalKeys, Oid domainId, Oid indexRelId, Oid foreignRelId, const int16 *foreignKey, const Oid *pfEqOp, const Oid *ppEqOp, const Oid *ffEqOp, int foreignNKeys, char foreignUpdateType, char foreignDeleteType, const int16 *fkDeleteSetCols, int numFkDeleteSetCols, char foreignMatchType, const Oid *exclOp, Node *conExpr, const char *conBin, bool conIsLocal, int16 conInhCount, bool conNoInherit, bool conPeriod, bool is_internal)
HeapTuple findNotNullConstraint(Oid relid, const char *colname)
bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)
void RemoveConstraintById(Oid conId)
void FindFKPeriodOpers(Oid opclass, Oid *containedbyoperoid, Oid *aggedcontainedbyoperoid, Oid *intersectoperoid)
void RenameConstraintById(Oid conId, const char *newname)
Oid get_relation_idx_constraint_oid(Oid relationId, Oid indexId)
void ConstraintSetParentConstraint(Oid childConstrId, Oid parentConstrId, Oid childTableId)
Bitmapset * get_primary_key_attnos(Oid relid, bool deferrableOk, Oid *constraintOid)
HeapTuple findDomainNotNullConstraint(Oid typid)
void DeconstructFkConstraintRow(HeapTuple tuple, int *numfks, AttrNumber *conkey, AttrNumber *confkey, Oid *pf_eq_oprs, Oid *pp_eq_oprs, Oid *ff_eq_oprs, int *num_fk_del_set_cols, AttrNumber *fk_del_set_cols)
HeapTuple findNotNullConstraintAttnum(Oid relid, AttrNumber attnum)
void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, Oid newNspId, bool isType, ObjectAddresses *objsMoved)
List * RelationGetNotNullConstraints(Oid relid, bool cooked, bool include_noinh)
bool ConstraintNameExists(const char *conname, Oid namespaceid)
char * ChooseConstraintName(const char *name1, const char *name2, const char *label, Oid namespaceid, List *others)
bool check_functional_grouping(Oid relid, Index varno, Index varlevelsup, List *grouping_columns, List **constraintDeps)
Bitmapset * get_relation_constraint_attnos(Oid relid, const char *conname, bool missing_ok, Oid *constraintOid)
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
AttrNumber extractNotNullColumn(HeapTuple constrTup)
bool AdjustNotNullInheritance(Oid relid, AttrNumber attnum, bool is_local, bool is_no_inherit, bool is_notvalid)
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
FormData_pg_constraint * Form_pg_constraint
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
size_t strlcpy(char *dst, const char *src, size_t siz)
static Datum PointerGetDatum(const void *X)
static Datum Int16GetDatum(int16 X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum NameGetDatum(const NameData *X)
static Pointer DatumGetPointer(Datum X)
static Datum CStringGetDatum(const char *X)
static Datum CharGetDatum(char X)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
#define FirstLowInvalidHeapAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
#define SearchSysCacheCopy1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
String * makeString(char *str)