跳转到主要内容
← 目录图谱 / pg_constraint

SYSTEM CATALOG · 系统目录

pg_constraint

The catalog pg_constraint stores check, not-null, 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.) 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.

首次收录 PG 9.0最近收录 PG 19当前字段 28

已与 PostgreSQL 18.6 实例逐字段核对 · 原始实测记录 ↗

字段结构 PostgreSQL 18

pg_constraint
字段 / COLUMN类型 / TYPE说明 / DESCRIPTION
oid oidNOT NULL Row identifier
conname nameNOT NULL Constraint name (not necessarily unique!)
connamespace oidNOT NULL The OID of the namespace that contains this constraint引用:pg_namespace.oid
contype "char"NOT NULL文档原写法:char c = check constraint, f = foreign key constraint, n = not-null constraint, p = primary key constraint, u = unique constraint, t = constraint trigger, x = exclusion constraint
condeferrable booleanNOT NULL文档原写法:bool Is the constraint deferrable?
condeferred booleanNOT NULL文档原写法:bool Is the constraint deferred by default?
conenforced booleanNOT NULL文档原写法:bool Is the constraint enforced?
convalidated booleanNOT NULL文档原写法:bool Has the constraint been validated?
conrelid oidNOT NULL The table this constraint is on; zero if not a table constraint引用:pg_class.oid
contypid oidNOT NULL The domain this constraint is on; zero if not a domain constraint引用:pg_type.oid
conindid oidNOT NULL The index supporting this constraint, if it's a unique, primary key, foreign key, or exclusion constraint; else zero引用:pg_class.oid
conparentid oidNOT NULL The corresponding constraint of the parent partitioned table, if this is a constraint on a partition; else zero引用:pg_constraint.oid
confrelid oidNOT NULL If a foreign key, the referenced table; else zero引用:pg_class.oid
confupdtype "char"NOT NULL文档原写法:char Foreign key update action code: a = no action, r = restrict, c = cascade, n = set null, d = set default
confdeltype "char"NOT NULL文档原写法:char Foreign key deletion action code: a = no action, r = restrict, c = cascade, n = set null, d = set default
confmatchtype "char"NOT NULL文档原写法:char Foreign key match type: f = full, p = partial, s = simple
conislocal booleanNOT NULL文档原写法:bool This constraint is defined locally for the relation. Note that a constraint can be locally defined and inherited simultaneously.
coninhcount smallintNOT NULL文档原写法:int2 The number of direct inheritance ancestors this constraint has. A constraint with a nonzero number of ancestors cannot be dropped nor renamed.
connoinherit booleanNOT NULL文档原写法:bool This constraint is defined locally for the relation. It is a non-inheritable constraint.
conperiod booleanNOT NULL文档原写法:bool This constraint is defined with WITHOUT OVERLAPS (for primary keys and unique constraints) or PERIOD (for foreign keys).
conkey smallint[]文档原写法:int2[] If a table constraint (including foreign keys, but not constraint triggers), list of the constrained columns引用:pg_attribute.attnum
confkey smallint[]文档原写法:int2[] If a foreign key, list of the referenced columns引用:pg_attribute.attnum
conpfeqop oid[] If a foreign key, list of the equality operators for PK = FK comparisons引用:pg_operator.oid
conppeqop oid[] If a foreign key, list of the equality operators for PK = PK comparisons引用:pg_operator.oid
conffeqop oid[] If a foreign key, list of the equality operators for FK = FK comparisons引用:pg_operator.oid
confdelsetcols smallint[]文档原写法:int2[] 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.引用:pg_attribute.attnum
conexclop oid[] If an exclusion constraint or WITHOUT OVERLAPS primary key/unique constraint, list of the per-column exclusion operators.引用:pg_operator.oid
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.)

标记“隐式列”的字段不包含在 SELECT * 中;部分早期统计视图由同版本源码补全,额外来源会显示在字段说明中。

通用系统列 6

PostgreSQL 提供的系统属性,通常不在 SELECT * 中展开。单独保留,不与普通字段混算。

字段类型attnum
tableoidoid-6
cmaxcid-5
xmaxxid-4
cmincid-3
xminxid-2
ctidtid-1

字段演化矩阵

悬停查看字段类型
存在新增 / 类型或属性变化移除
字段 / COLUMN9.09.19.29.39.49.59.610111213141516171819
oid
conname
connamespace
contype
condeferrable
condeferred
conrelid
contypid
conindid
confrelid
confupdtype
confdeltype
confmatchtype
conislocal
coninhcount
conkey
confkey
conpfeqop
conppeqop
conffeqop
conexclop
conbin
consrc
convalidated
connoinherit
conparentid
confdelsetcols
conenforced
conperiod

9.0 是收录基线;基线中已存在的字段不标记为新增。矩阵按字段名称对齐,重命名显示为旧字段移除与新字段新增。

演化时间线

相邻大版本的变化

PostgreSQL 18 ← 17

+ conenforced+ conperiod3 处字段说明更新目录说明更新

PostgreSQL 17 ← 16

1 处字段说明更新目录说明更新

PostgreSQL 16 ← 15

~ coninhcount: integer → smallint

PostgreSQL 15 ← 14

+ confdelsetcols

PostgreSQL 14 ← 13

6 处字段说明更新

PostgreSQL 12 ← 11

− consrc~ oid: 隐式列 → 常规列2 处字段说明更新

PostgreSQL 11 ← 10

+ conparentid

PostgreSQL 9.3 ← 9.2

2 处字段说明更新

PostgreSQL 9.2 ← 9.1

+ connoinherit1 处字段说明更新

PostgreSQL 9.1 ← 9.0

+ convalidated~ conbin: text → pg_node_tree

比较任意两个版本

选择两个版本,查看字段的新增、移除与类型变化。交互比较需要 JavaScript;演化时间线可直接阅读。