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

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

文档 / 系统目录 / 系统目录表

SYSTEM CATALOG系统目录表

pg_constraint

检查约束、唯一约束、主键约束、外键约束

系统目录表 引入 9.0(基线) 现存至 20 devel 7 次结构变更

关系 OID
2606
关系类型
r(普通表)
字段数
28
引入版本
9.0(收录基线)
版本状态
当前稳定版
结构变更
7 次

PostgreSQL 18 手册 官方文档 源码定义

版本轨迹

相对 PostgreSQL 17:新增 2 个字段,描述更新 3 处。

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

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

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

字段

PostgreSQL 18 的 28 个字段,按定义顺序排列。说明默认用本站手册的译文,没有译文的按英文原文显示。

字段 类型 说明
oid oidNOT NULL 行标识符
conname nameNOT NULL 约束名字(不需要唯一!)
connamespace oidNOT NULL pg_namespace.oid 包含此约束的名字空间的OID
contype "char"NOT NULL c = 检查约束, f = 外键约束, n = 非空约束, p = 主键约束, u = 唯一约束, t = 约束触发器, x = 排他约束
condeferrable booleanNOT NULL 该约束是否能被延迟?
condeferred booleanNOT NULL 该约束是否默认被延迟?
conenforced booleanNOT NULL 该约束是否会被强制执行?
convalidated booleanNOT NULL 该约束是否已经验证?
conrelid oidNOT NULL pg_class.oid 该约束所在的表,如果不是表约束则为零
contypid oidNOT NULL pg_type.oid 该约束所在的域,如果不是域约束则为0
conindid oidNOT NULL pg_class.oid 如果该约束是唯一、主键、外键或排他约束,此列表示支持此约束的索引,否则为零
conparentid oidNOT NULL pg_constraint.oid 如果这是一个分区中的约束,则是父分区表中对应的约束;否则为零
confrelid oidNOT NULL pg_class.oid 如果此约束是一个外键约束,此列为被引用的表,否则为零
confupdtype "char"NOT NULL 外键更新动作代码: a = 无动作, r = 限制, c = 级联, n = 置空, d = 置为默认值
confdeltype "char"NOT NULL 外键删除动作代码: a = 无动作, r = 限制, c = 级联, n = 置空, d = 置为默认值
confmatchtype "char"NOT NULL 外键匹配类型: f = 完全, p = 部分, s = 简单
conislocal booleanNOT NULL 此约束是定义在关系本地。注意一个约束可以同时是本地定义和继承。
coninhcount smallintNOT NULL 该约束直接继承自多少个祖先。祖先数量非零的约束不能被删除,也不能被重命名。
connoinherit booleanNOT NULL 为真表示此约束被定义在关系本地。它是一个不可继承约束。
conperiod booleanNOT NULL 如果该约束被定义为 WITHOUT OVERLAPS (主键或唯一约束)或 PERIOD (外键),则为真。
conkey smallint[] pg_attribute.attnum 如果是一个表约束(包括外键但不包括约束触发器),此列是被约束列的列表
confkey smallint[] pg_attribute.attnum 如果是一个外键,此列是被引用列的列表
conpfeqop oid[] pg_operator.oid 如果是一个外键,此列是用于PK = FK比较的等值操作符的列表
conppeqop oid[] pg_operator.oid 如果是一个外键,此列是用于PK = PK比较的等值操作符的列表
conffeqop oid[] pg_operator.oid 如果是一个外键,此列是用于FK = FK比较的等值操作符的列表
confdelsetcols smallint[] pg_attribute.attnum 如果外键具有SET NULL或SET DEFAULT删除动作,则这里列出将被更新的列。 如果为空,则会更新所有引用列。
conexclop oid[] pg_operator.oid 如果是排他约束或 WITHOUT OVERLAPS 主键/唯一约束,则这里列出每列的排他操作符。
conbin pg_node_tree 如果是一个检查约束,此列是表达式的一个内部表示。建议使用 pg_get_constraintdef()提取检查约束的定义。

演化历史

相邻两个大版本之间的差异,新的在前。版本号链到该版的字段表。

  1. PostgreSQL 18 ← 17 结构变更

    conenforcedconperiod 关系说明更新

    3 处描述更新
    • conexclop If an exclusion constraint, list of the per-column exclusion operators If an exclusion constraint or WITHOUT OVERLAPS primary key/unique constraint, list of the per-column exclusion operators.
    • contype c = check constraint, f = foreign key constraint, n = not-null constraint (domains only), p = primary key constraint, u = unique constraint, t = constraint trigger, x = exclusion constraint c = check constraint, f = foreign key constraint, n = not-null constraint, p = primary key constraint, u = unique constraint, t = constraint trigger, x = exclusion constraint
    • convalidated Has the constraint been validated? Currently, can be false only for foreign keys and CHECK constraints Has the constraint been validated?
  2. PostgreSQL 17 ← 16 仅描述更新

    关系说明更新

    1 处描述更新
    • contype c = check constraint, f = foreign key constraint, p = primary key constraint, u = unique constraint, t = constraint trigger, x = exclusion constraint c = check constraint, f = foreign key constraint, n = not-null constraint (domains only), p = primary key constraint, u = unique constraint, t = constraint trigger, x = exclusion constraint
  3. PostgreSQL 16 ← 15 结构变更

    coninhcount:integer → smallint

  4. PostgreSQL 15 ← 14 结构变更

    confdelsetcols

  5. PostgreSQL 14 ← 13 仅描述更新

    6 处描述更新
    • confrelid If a foreign key, the referenced table; else 0 If a foreign key, the referenced table; else zero
    • conindid The index supporting this constraint, if it's a unique, primary key, foreign key, or exclusion constraint; else 0 The index supporting this constraint, if it's a unique, primary key, foreign key, or exclusion constraint; else zero
    • conparentid The corresponding constraint in the parent partitioned table, if this is a constraint in a partition; else 0 The corresponding constraint of the parent partitioned table, if this is a constraint on a partition; else zero
    • conrelid The table this constraint is on; 0 if not a table constraint The table this constraint is on; zero if not a table constraint
    • contypid The domain this constraint is on; 0 if not a domain constraint The domain this constraint is on; zero if not a domain constraint
    • convalidated Has the constraint been validated? Currently, can only be false for foreign keys and CHECK constraints Has the constraint been validated? Currently, can be false only for foreign keys and CHECK constraints
  6. PostgreSQL 12 ← 11 结构变更

    consrc oid:隐式列 → 常规列

    2 处描述更新
    • conbin If a check constraint, an internal representation of the expression 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.)
    • oid Row identifier (hidden attribute; must be explicitly selected) Row identifier
  7. PostgreSQL 11 ← 10 结构变更

    conparentid

  8. PostgreSQL 9.3 ← 9.2 仅描述更新

    2 处描述更新
    • confmatchtype Foreign key match type: f = full, p = partial, u = simple (unspecified) Foreign key match type: f = full, p = partial, s = simple
    • oid Row identifier (hidden system attribute; explicitly select oid). Row identifier (hidden attribute; must be explicitly selected)
  9. PostgreSQL 9.2 ← 9.1 结构变更

    connoinherit

    1 处描述更新
    • convalidated Has the constraint been validated? Currently, can only be false for foreign keys Has the constraint been validated? Currently, can only be false for foreign keys and CHECK constraints
  10. PostgreSQL 9.1 ← 9.0 结构变更

    convalidated conbin:text → pg_node_tree

字段矩阵

每个字段在 18 个收录版本里的存在情况;方格指向该版的字段表。「有变」指类型、可空、隐式或数组维数与上一版不同。

存在 有变 已移除 不存在

字段 9.09.19.29.39.49.59.61011121314151617181920
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 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 存在 存在 存在

系统列

每张表都有的 6 个系统列
  • tableoidoid-6
  • cmaxcid-5
  • xmaxxid-4
  • cmincid-3
  • xminxid-2
  • ctidtid-1

同类关系

关系 引入 字段 版本变动 最近变更
SYSTEM CATALOG 系统目录表 70 个
pg_aggregate 9.0基线 22 113 次
聚合函数 现存
pg_am 9.0基线 4 124 次
关系访问方法 现存
pg_amop 9.0基线 9 122 次
访问方法操作符 现存
pg_amproc 9.0基线 6 121 次
访问方法支持函数 现存
pg_attrdef 9.0基线 4 122 次
列默认值 现存
pg_attribute 9.0基线 25 189 次
表列(“属性”) 现存
pg_auth_members 9.0基线 7 161 次
授权标识符成员关系 现存
pg_authid 9.0基线 12 123 次
授权标识符(角色) 现存
pg_cast 9.0基线 6 121 次
转换(数据类型转换) 现存
pg_class 9.0基线 34 189 次
表、索引、序列、视图 (“关系”) 现存
pg_collation 9.1 12 175 次
排序规则(区域设置信息) 现存
pg_constraint 9.0基线 28 187 次
检查约束、唯一约束、主键约束、外键约束 现存
pg_conversion 9.0基线 8 121 次
编码转换信息 现存
pg_database 9.0基线 18 175 次
本数据库集簇中的数据库 现存
pg_db_role_setting 9.0基线 3
每角色和每数据库的设置 现存
pg_default_acl 9.0基线 5 121 次
对象类型的默认权限 现存
pg_depend 9.0基线 7
数据库对象间的依赖 现存
pg_description 9.0基线 4 9.51 次
数据库对象上的描述或注释 现存
pg_enum 9.0基线 4 122 次
枚举标签和值定义 现存
pg_event_trigger 9.3 7 121 次
事件触发器 现存
pg_extension 9.1 8 122 次
已安装扩展 现存
pg_foreign_data_wrapper 9.0基线 8 193 次
外部数据包装器定义 现存
pg_foreign_server 9.0基线 8 121 次
外部服务器定义 现存
pg_foreign_table 9.1 3
外部表信息 现存
pg_index 9.0基线 21 155 次
索引信息 现存
pg_inherits 9.0基线 4 141 次
表继承层次 现存
pg_init_privs 9.6 5
对象初始权限 现存
pg_language 9.0基线 9 121 次
编写函数的语言 现存
pg_largeobject 9.0基线 3 9.51 次
大对象的数据页 现存
pg_largeobject_metadata 9.0基线 3 121 次
大对象的元数据 现存
pg_namespace 9.0基线 4 121 次
模式 现存
pg_opclass 9.0基线 9 121 次
访问方法操作符类 现存
pg_operator 9.0基线 15 121 次
操作符 现存
pg_opfamily 9.0基线 5 121 次
访问方法操作符族 现存
pg_parameter_acl 15 3
已授予权限的配置参数 现存
pg_partitioned_table 10 8 111 次
表的分区键的信息 现存
pg_pltemplate 9.0基线 8 9.51 次
过程语言的模板数据 于 13 移除
pg_policy 9.5 8 122 次
行安全策略 现存
pg_proc 9.0基线 30 147 次
函数和过程 现存
pg_propgraph_element 19 14
属性图元素(顶点和边) 于 20 移除
pg_propgraph_element_label 19 3
属性图中元素与标签之间的链接 于 20 移除
pg_propgraph_label 19 3
属性图标签 于 20 移除
pg_propgraph_label_property 19 4
属性图中按标签区分的属性定义 于 20 移除
pg_propgraph_property 19 6
属性图属性 于 20 移除
pg_publication 10 11 195 次
用于逻辑复制的发布 现存
pg_publication_namespace 15 3
模式到发布映射 现存
pg_publication_rel 10 6 193 次
关系与发布的映射 现存
pg_range 9.2 12 192 次
范围类型的信息 现存
pg_replication_origin 9.5 2
已注册的复制源 现存
pg_rewrite 9.0基线 8 123 次
查询重写规则 现存
pg_seclabel 9.1 5 9.51 次
数据库对象上的安全标签 现存
pg_sequence 10 8
有关序列的信息 现存
pg_shdepend 9.0基线 7
共享对象上的依赖 现存
pg_shdescription 9.0基线 3 9.51 次
共享对象上的注释 现存
pg_shseclabel 9.2 4 9.51 次
共享数据库对象上的安全标签 现存
pg_statistic 9.0基线 31 122 次
规划器统计 现存
pg_statistic_ext 10 9 174 次
扩展的规划器统计信息(定义) 现存
pg_statistic_ext_data 12 6 152 次
扩展的规划器统计信息(已构建的统计信息) 现存
pg_subscription 10 23 197 次
逻辑复制订阅 现存
pg_subscription_rel 10 4 131 次
订阅的关系状态 现存
pg_tablespace 9.0基线 5 122 次
本数据库集簇内的表空间 现存
pg_transform 9.5 5 121 次
转换(将数据类型转换为过程语言需要的形式) 现存
pg_trigger 9.0基线 19 135 次
触发器 现存
pg_ts_config 9.0基线 5 121 次
文本搜索配置 现存
pg_ts_config_map 9.0基线 4
文本搜索配置的词元映射 现存
pg_ts_dict 9.0基线 6 121 次
文本搜索字典 现存
pg_ts_parser 9.0基线 8 121 次
文本搜索分析器 现存
pg_ts_template 9.0基线 5 121 次
文本搜索模板 现存
pg_type 9.0基线 32 144 次
数据类型 现存
pg_user_mapping 9.0基线 4 121 次
将用户映射到外部服务器 现存