↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

支持中的版本: 当前版本 (18) / 17 / 16 / 15 / 14
开发中的版本: 19 / 20devel
已结束支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3
历史版本。 PostgreSQL 9.2 已结束支持。 2017-11-09. 请参阅 当前版本手册.

45.12. pg_constraint #

目录pg_constraint存储表上的检查约束、主键约束、唯一约束、外键约束和排他约束。(列约束不会被特殊对待。每一个列约束都等价于某种表约束。)非空约束在pg_attribute目录中表示,而不是在这里。

用户定义的约束触发器(使用CREATE CONSTRAINT TRIGGER创建)也会在这个表中产生一项。

域上的检查约束也存储在这里。

表 45.12. pg_constraint 列

NameTypeReferencesDescription
connamename Constraint name (not necessarily unique!)
connamespaceoidpg_namespace.oid The OID of the namespace that contains this constraint
contypechar  c = check constraint, f = foreign key constraint, p = primary key constraint, u = unique constraint, t = constraint trigger, x = exclusion constraint
condeferrablebool Is the constraint deferrable?
condeferredbool Is the constraint deferred by default?
convalidatedbool Has the constraint been validated? Currently, can only be false for foreign keys
conrelidoidpg_class.oidThe table this constraint is on; 0 if not a table constraint
contypidoidpg_type.oidThe domain this constraint is on; 0 if not a domain constraint
conindidoidpg_class.oidThe index supporting this constraint, if it's a unique, primary key, foreign key, or exclusion constraint; else 0
confrelidoidpg_class.oidIf a foreign key, the referenced table; else 0
confupdtypechar Foreign key update action code: a = no action, r = restrict, c = cascade, n = set null, d = set default
confdeltypechar Foreign key deletion action code: a = no action, r = restrict, c = cascade, n = set null, d = set default
confmatchtypechar Foreign key match type: f = full, p = partial, u = simple (unspecified)
conislocalbool  This constraint is defined locally for the relation. Note that a constraint can be locally defined and inherited simultaneously.
coninhcountint4  The number of direct inheritance ancestors this constraint has. A constraint with a nonzero number of ancestors cannot be dropped nor renamed.
connoinheritbool  为真表示此约束被定义在关系本地。它是一个不可继承约束。
conkeyint2[]pg_attribute.attnumIf a table constraint (including foreign keys, but not constraint triggers), list of the constrained columns
confkeyint2[]pg_attribute.attnumIf a foreign key, list of the referenced columns
conpfeqopoid[]pg_operator.oidIf a foreign key, list of the equality operators for PK = FK comparisons
conppeqopoid[]pg_operator.oidIf a foreign key, list of the equality operators for PK = PK comparisons
conffeqopoid[]pg_operator.oidIf a foreign key, list of the equality operators for FK = FK comparisons
conexclopoid[]pg_operator.oidIf an exclusion constraint, list of the per-column exclusion operators
conbinpg_node_tree If a check constraint, an internal representation of the expression
consrctext If a check constraint, a human-readable representation of the expression

对于排他约束,conkey仅对作为简单列引用的约束元素有用。对于其他情况,conkey中会出现一个 0,必须查阅关联索引来确定被约束的表达式。(因此,conkey与该索引的 pg_index.indkey具有相同的内容。)

注意

被引用对象发生变化时,consrc不会更新;例如,它不会跟踪列重命名。最好使用pg_get_constraintdef()提取检查约束的定义,而不是依赖这个字段。

注意

pg_class.relchecks需要和每个关系在此目录中的检查约束数量保持一致。

报告文档问题

阅读 上游文档. 反馈更正前请先核对 当前版本手册.