选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

受支持版本: 当前版本 (18) / 17 / 16 / 15 / 14
测试与开发版本: 19 / devel
不受支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0
历史版本PostgreSQL 9.2 已于 2017 年 11 月结束社区维护,本页译文保留供仍在使用旧版本的读者参考。新系统请看当前版本

45.12. pg_constraint #

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

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

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

表 45.12. pg_constraint

Name Type References Description
conname name   Constraint name (not necessarily unique!)
connamespace oid pg_namespace.oid The OID of the namespace that contains this constraint
contype char   c = check constraint, f = foreign key constraint, p = primary key constraint, u = unique constraint, t = constraint trigger, x = exclusion constraint
condeferrable bool   Is the constraint deferrable?
condeferred bool   Is the constraint deferred by default?
convalidated bool   Has the constraint been validated? Currently, can only be false for foreign keys
conrelid oid pg_class.oid The table this constraint is on; 0 if not a table constraint
contypid oid pg_type.oid The domain this constraint is on; 0 if not a domain constraint
conindid oid pg_class.oid The index supporting this constraint, if it's a unique, primary key, foreign key, or exclusion constraint; else 0
confrelid oid pg_class.oid If a foreign key, the referenced table; else 0
confupdtype char   Foreign key update action code: a = no action, r = restrict, c = cascade, n = set null, d = set default
confdeltype char   Foreign key deletion action code: a = no action, r = restrict, c = cascade, n = set null, d = set default
confmatchtype char   Foreign key match type: f = full, p = partial, u = simple (unspecified)
conislocal bool   This constraint is defined locally for the relation. Note that a constraint can be locally defined and inherited simultaneously.
coninhcount int4   The number of direct inheritance ancestors this constraint has. A constraint with a nonzero number of ancestors cannot be dropped nor renamed.
connoinherit bool   为真表示此约束被定义在关系本地。它是一个不可继承约束。
conkey int2[] pg_attribute.attnum If a table constraint (including foreign keys, but not constraint triggers), list of the constrained columns
confkey int2[] pg_attribute.attnum If a foreign key, list of the referenced columns
conpfeqop oid[] pg_operator.oid If a foreign key, list of the equality operators for PK = FK comparisons
conppeqop oid[] pg_operator.oid If a foreign key, list of the equality operators for PK = PK comparisons
conffeqop oid[] pg_operator.oid If a foreign key, list of the equality operators for FK = FK comparisons
conexclop oid[] pg_operator.oid If an exclusion constraint, list of the per-column exclusion operators
conbin pg_node_tree   If a check constraint, an internal representation of the expression
consrc text   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需要和每个关系在此目录中的检查约束数量保持一致。

提交更正

译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。 英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。