历史版本。 PostgreSQL 9.2 已结束支持。 2017-11-09. 请参阅 当前版本手册.
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 | | 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 | | The table this constraint is on; 0 if not a table constraint |
contypid | oid | | The domain this constraint is on; 0 if not a domain constraint |
conindid | oid | | The index supporting this constraint, if it's a unique, primary key, foreign key, or exclusion constraint; else 0 |
confrelid | 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[] | | If a table constraint (including foreign keys, but not constraint triggers), list of the constrained columns |
confkey | int2[] | | If a foreign key, list of the referenced columns |
conpfeqop | oid[] | | If a foreign key, list of the equality operators for PK = FK comparisons |
conppeqop | oid[] | | If a foreign key, list of the equality operators for PK = PK comparisons |
conffeqop | oid[] | | If a foreign key, list of the equality operators for FK = FK comparisons |
conexclop | 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需要和每个关系在此目录中的检查约束数量保持一致。