Postgresql 中文操作指南
53.13. pg_constraint #
目录 pg_constraint 存储对表上的检查、主键、唯一键、外键和排他约束。(列约束没有被特殊处理。每个列约束等同于某个表约束。)非空约束表示为 pg_attribute 目录,不在此处。
The catalog pg_constraint stores check, primary key, unique, foreign key, and exclusion constraints on tables. (Column constraints are not treated specially. Every column constraint is equivalent to some table constraint.) Not-null constraints are represented in the pg_attribute catalog, not here.
用户定义的约束触发器(使用 CREATE CONSTRAINT TRIGGER 创建)也会导致在此表中生成一个条目。
User-defined constraint triggers (created with CREATE CONSTRAINT TRIGGER) also give rise to an entry in this table.
此处也存储了域上的检查约束。
Check constraints on domains are stored here, too.
Table 53.13. pg_constraint Columns
Table 53.13. pg_constraint Columns
Column Type Description |
oid oid Row identifier |
conname name Constraint name (not necessarily unique!) |
connamespace oid (references 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 be false only for foreign keys and CHECK constraints |
conrelid oid (references pg_class.oid) The table this constraint is on; zero if not a table constraint |
contypid oid (references pg_type.oid) The domain this constraint is on; zero if not a domain constraint |
conindid oid (references pg_class.oid) The index supporting this constraint, if it’s a unique, primary key, foreign key, or exclusion constraint; else zero |
conparentid oid (references pg_constraint.oid) The corresponding constraint of the parent partitioned table, if this is a constraint on a partition; else zero |
confrelid oid (references pg_class.oid) If a foreign key, the referenced table; else zero |
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, s = simple |
conislocal bool This constraint is defined locally for the relation. Note that a constraint can be locally defined and inherited simultaneously. |
coninhcount int2 The number of direct inheritance ancestors this constraint has. A constraint with a nonzero number of ancestors cannot be dropped nor renamed. |
connoinherit bool This constraint is defined locally for the relation. It is a non-inheritable constraint. |
conkey int2[] (references pg_attribute.attnum) If a table constraint (including foreign keys, but not constraint triggers), list of the constrained columns |
confkey int2[] (references pg_attribute.attnum) If a foreign key, list of the referenced columns |
conpfeqop oid[] (references pg_operator.oid) If a foreign key, list of the equality operators for PK = FK comparisons |
conppeqop oid[] (references pg_operator.oid) If a foreign key, list of the equality operators for PK = PK comparisons |
conffeqop oid[] (references pg_operator.oid) If a foreign key, list of the equality operators for FK = FK comparisons |
confdelsetcols int2[] (references pg_attribute.attnum) If a foreign key with a SET NULL or SET DEFAULT delete action, the columns that will be updated. If null, all of the referencing columns will be updated. |
conexclop oid[] (references 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. (It’s recommended to use pg_get_constraintdef() to extract the definition of a check constraint.) |
对于排除约束, conkey 只对作为简单列引用的约束元素有用。对于其他情况, conkey 中会出现一个零并且必须参考关联索引才能发现受约束的表达式。(因此 conkey 与索引的 pg_index . indkey 中的内容相同。)
In the case of an exclusion constraint, conkey is only useful for constraint elements that are simple column references. For other cases, a zero appears in conkey and the associated index must be consulted to discover the expression that is constrained. (conkey thus has the same contents as pg_index.indkey for the index.)