pg_constraint
用于存储约束信息的系统表
pg_constraint
是一个用于存储约束信息(不包括 NOT NULL
约束)的 系统目录 表。
pg_constraint
添加于 PostgreSQL 7.3。
用法
系统函数
系统函数 pg_get_constraintdef()
可用于获取约束的定义。
实现和可能的更改
NOT NULL 约束
在 PostgreSQL 17 之前,NOT NULL
约束存储在 pg_attribute
中。
域约束
提交 8abb3cda(来自 2015 年)包括一个建议,为 域 约束添加一个单独的表。
按 PostgreSQL 版本定义
pg_constraint (PostgreSQL 17)
Table "pg_catalog.pg_constraint" Column | Type | Collation | Nullable | Default ----------------+--------------+-----------+----------+--------- oid | oid | | not null | conname | name | | not null | connamespace | oid | | not null | contype | "char" | | not null | condeferrable | boolean | | not null | condeferred | boolean | | not null | convalidated | boolean | | not null | conrelid | oid | | not null | contypid | oid | | not null | conindid | oid | | not null | conparentid | oid | | not null | confrelid | oid | | not null | confupdtype | "char" | | not null | confdeltype | "char" | | not null | confmatchtype | "char" | | not null | conislocal | boolean | | not null | coninhcount | smallint | | not null | connoinherit | boolean | | not null | conperiod | boolean | | not null | conkey | smallint[] | | | confkey | smallint[] | | | conpfeqop | oid[] | | | conppeqop | oid[] | | | conffeqop | oid[] | | | confdelsetcols | smallint[] | | | conexclop | oid[] | | | conbin | pg_node_tree | C | | Indexes: "pg_constraint_oid_index" PRIMARY KEY, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conparentid_index" btree (conparentid) "pg_constraint_conrelid_contypid_conname_index" UNIQUE CONSTRAINT, btree (conrelid, contypid, conname) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 16)
Table "pg_catalog.pg_constraint" Column | Type | Collation | Nullable | Default ----------------+--------------+-----------+----------+--------- oid | oid | | not null | conname | name | | not null | connamespace | oid | | not null | contype | "char" | | not null | condeferrable | boolean | | not null | condeferred | boolean | | not null | convalidated | boolean | | not null | conrelid | oid | | not null | contypid | oid | | not null | conindid | oid | | not null | conparentid | oid | | not null | confrelid | oid | | not null | confupdtype | "char" | | not null | confdeltype | "char" | | not null | confmatchtype | "char" | | not null | conislocal | boolean | | not null | coninhcount | smallint | | not null | connoinherit | boolean | | not null | conkey | smallint[] | | | confkey | smallint[] | | | conpfeqop | oid[] | | | conppeqop | oid[] | | | conffeqop | oid[] | | | confdelsetcols | smallint[] | | | conexclop | oid[] | | | conbin | pg_node_tree | C | | Indexes: "pg_constraint_oid_index" PRIMARY KEY, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conparentid_index" btree (conparentid) "pg_constraint_conrelid_contypid_conname_index" UNIQUE CONSTRAINT, btree (conrelid, contypid, conname) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 15)
Table "pg_catalog.pg_constraint" Column | Type | Collation | Nullable | Default ----------------+--------------+-----------+----------+--------- oid | oid | | not null | conname | name | | not null | connamespace | oid | | not null | contype | "char" | | not null | condeferrable | boolean | | not null | condeferred | boolean | | not null | convalidated | boolean | | not null | conrelid | oid | | not null | contypid | oid | | not null | conindid | oid | | not null | conparentid | oid | | not null | confrelid | oid | | not null | confupdtype | "char" | | not null | confdeltype | "char" | | not null | confmatchtype | "char" | | not null | conislocal | boolean | | not null | coninhcount | integer | | not null | connoinherit | boolean | | not null | conkey | smallint[] | | | confkey | smallint[] | | | conpfeqop | oid[] | | | conppeqop | oid[] | | | conffeqop | oid[] | | | confdelsetcols | smallint[] | | | conexclop | oid[] | | | conbin | pg_node_tree | C | | Indexes: "pg_constraint_oid_index" PRIMARY KEY, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conparentid_index" btree (conparentid) "pg_constraint_conrelid_contypid_conname_index" UNIQUE CONSTRAINT, btree (conrelid, contypid, conname) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 14)
Table "pg_catalog.pg_constraint" Column | Type | Collation | Nullable | Default ---------------+--------------+-----------+----------+--------- oid | oid | | not null | conname | name | | not null | connamespace | oid | | not null | contype | "char" | | not null | condeferrable | boolean | | not null | condeferred | boolean | | not null | convalidated | boolean | | not null | conrelid | oid | | not null | contypid | oid | | not null | conindid | oid | | not null | conparentid | oid | | not null | confrelid | oid | | not null | confupdtype | "char" | | not null | confdeltype | "char" | | not null | confmatchtype | "char" | | not null | conislocal | boolean | | not null | coninhcount | integer | | not null | connoinherit | boolean | | not null | conkey | smallint[] | | | confkey | smallint[] | | | conpfeqop | oid[] | | | conppeqop | oid[] | | | conffeqop | oid[] | | | conexclop | oid[] | | | conbin | pg_node_tree | C | | Indexes: "pg_constraint_oid_index" PRIMARY KEY, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conparentid_index" btree (conparentid) "pg_constraint_conrelid_contypid_conname_index" UNIQUE CONSTRAINT, btree (conrelid, contypid, conname) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 13)
Table "pg_catalog.pg_constraint" Column | Type | Collation | Nullable | Default ---------------+--------------+-----------+----------+--------- oid | oid | | not null | conname | name | | not null | connamespace | oid | | not null | contype | "char" | | not null | condeferrable | boolean | | not null | condeferred | boolean | | not null | convalidated | boolean | | not null | conrelid | oid | | not null | contypid | oid | | not null | conindid | oid | | not null | conparentid | oid | | not null | confrelid | oid | | not null | confupdtype | "char" | | not null | confdeltype | "char" | | not null | confmatchtype | "char" | | not null | conislocal | boolean | | not null | coninhcount | integer | | not null | connoinherit | boolean | | not null | conkey | smallint[] | | | confkey | smallint[] | | | conpfeqop | oid[] | | | conppeqop | oid[] | | | conffeqop | oid[] | | | conexclop | oid[] | | | conbin | pg_node_tree | C | | Indexes: "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conparentid_index" btree (conparentid) "pg_constraint_conrelid_contypid_conname_index" UNIQUE, btree (conrelid, contypid, conname) "pg_constraint_contypid_index" btree (contypid) "pg_constraint_oid_index" UNIQUE, btree (oid)
文档: pg_constraint
pg_constraint (PostgreSQL 12)
Table "pg_catalog.pg_constraint" Column | Type | Collation | Nullable | Default ---------------+--------------+-----------+----------+--------- oid | oid | | not null | conname | name | | not null | connamespace | oid | | not null | contype | "char" | | not null | condeferrable | boolean | | not null | condeferred | boolean | | not null | convalidated | boolean | | not null | conrelid | oid | | not null | contypid | oid | | not null | conindid | oid | | not null | conparentid | oid | | not null | confrelid | oid | | not null | confupdtype | "char" | | not null | confdeltype | "char" | | not null | confmatchtype | "char" | | not null | conislocal | boolean | | not null | coninhcount | integer | | not null | connoinherit | boolean | | not null | conkey | smallint[] | | | confkey | smallint[] | | | conpfeqop | oid[] | | | conppeqop | oid[] | | | conffeqop | oid[] | | | conexclop | oid[] | | | conbin | pg_node_tree | C | | Indexes: "pg_constraint_conrelid_contypid_conname_index" UNIQUE, btree (conrelid, contypid, conname) "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conparentid_index" btree (conparentid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 11)
Table "pg_catalog.pg_constraint" Column | Type | Collation | Nullable | Default ---------------+--------------+-----------+----------+--------- conname | name | | not null | connamespace | oid | | not null | contype | "char" | | not null | condeferrable | boolean | | not null | condeferred | boolean | | not null | convalidated | boolean | | not null | conrelid | oid | | not null | contypid | oid | | not null | conindid | oid | | not null | conparentid | oid | | not null | confrelid | oid | | not null | confupdtype | "char" | | not null | confdeltype | "char" | | not null | confmatchtype | "char" | | not null | conislocal | boolean | | not null | coninhcount | integer | | not null | connoinherit | boolean | | not null | conkey | smallint[] | | | confkey | smallint[] | | | conpfeqop | oid[] | | | conppeqop | oid[] | | | conffeqop | oid[] | | | conexclop | oid[] | | | conbin | pg_node_tree | | | consrc | text | | | Indexes: "pg_constraint_conrelid_contypid_conname_index" UNIQUE, btree (conrelid, contypid, conname) "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conparentid_index" btree (conparentid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 10)
Table "pg_catalog.pg_constraint" Column | Type | Collation | Nullable | Default ---------------+--------------+-----------+----------+--------- conname | name | | not null | connamespace | oid | | not null | contype | "char" | | not null | condeferrable | boolean | | not null | condeferred | boolean | | not null | convalidated | boolean | | not null | conrelid | oid | | not null | contypid | oid | | not null | conindid | oid | | not null | confrelid | oid | | not null | confupdtype | "char" | | not null | confdeltype | "char" | | not null | confmatchtype | "char" | | not null | conislocal | boolean | | not null | coninhcount | integer | | not null | connoinherit | boolean | | not null | conkey | smallint[] | | | confkey | smallint[] | | | conpfeqop | oid[] | | | conppeqop | oid[] | | | conffeqop | oid[] | | | conexclop | oid[] | | | conbin | pg_node_tree | | | consrc | text | | | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 9.6)
Table "pg_catalog.pg_constraint" Column | Type | Modifiers ---------------+--------------+----------- conname | name | not null connamespace | oid | not null contype | "char" | not null condeferrable | boolean | not null condeferred | boolean | not null convalidated | boolean | not null conrelid | oid | not null contypid | oid | not null conindid | oid | not null confrelid | oid | not null confupdtype | "char" | not null confdeltype | "char" | not null confmatchtype | "char" | not null conislocal | boolean | not null coninhcount | integer | not null connoinherit | boolean | not null conkey | smallint[] | confkey | smallint[] | conpfeqop | oid[] | conppeqop | oid[] | conffeqop | oid[] | conexclop | oid[] | conbin | pg_node_tree | consrc | text | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 9.5)
Table "pg_catalog.pg_constraint" Column | Type | Modifiers ---------------+--------------+----------- conname | name | not null connamespace | oid | not null contype | "char" | not null condeferrable | boolean | not null condeferred | boolean | not null convalidated | boolean | not null conrelid | oid | not null contypid | oid | not null conindid | oid | not null confrelid | oid | not null confupdtype | "char" | not null confdeltype | "char" | not null confmatchtype | "char" | not null conislocal | boolean | not null coninhcount | integer | not null connoinherit | boolean | not null conkey | smallint[] | confkey | smallint[] | conpfeqop | oid[] | conppeqop | oid[] | conffeqop | oid[] | conexclop | oid[] | conbin | pg_node_tree | consrc | text | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 9.4)
Table "pg_catalog.pg_constraint" Column | Type | Modifiers ---------------+--------------+----------- conname | name | not null connamespace | oid | not null contype | "char" | not null condeferrable | boolean | not null condeferred | boolean | not null convalidated | boolean | not null conrelid | oid | not null contypid | oid | not null conindid | oid | not null confrelid | oid | not null confupdtype | "char" | not null confdeltype | "char" | not null confmatchtype | "char" | not null conislocal | boolean | not null coninhcount | integer | not null connoinherit | boolean | not null conkey | smallint[] | confkey | smallint[] | conpfeqop | oid[] | conppeqop | oid[] | conffeqop | oid[] | conexclop | oid[] | conbin | pg_node_tree | consrc | text | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 9.3)
Table "pg_catalog.pg_constraint" Column | Type | Modifiers ---------------+--------------+----------- conname | name | not null connamespace | oid | not null contype | "char" | not null condeferrable | boolean | not null condeferred | boolean | not null convalidated | boolean | not null conrelid | oid | not null contypid | oid | not null conindid | oid | not null confrelid | oid | not null confupdtype | "char" | not null confdeltype | "char" | not null confmatchtype | "char" | not null conislocal | boolean | not null coninhcount | integer | not null connoinherit | boolean | not null conkey | smallint[] | confkey | smallint[] | conpfeqop | oid[] | conppeqop | oid[] | conffeqop | oid[] | conexclop | oid[] | conbin | pg_node_tree | consrc | text | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 9.2)
Table "pg_catalog.pg_constraint" Column | Type | Modifiers ---------------+--------------+----------- conname | name | not null connamespace | oid | not null contype | "char" | not null condeferrable | boolean | not null condeferred | boolean | not null convalidated | boolean | not null conrelid | oid | not null contypid | oid | not null conindid | oid | not null confrelid | oid | not null confupdtype | "char" | not null confdeltype | "char" | not null confmatchtype | "char" | not null conislocal | boolean | not null coninhcount | integer | not null connoinherit | boolean | not null conkey | smallint[] | confkey | smallint[] | conpfeqop | oid[] | conppeqop | oid[] | conffeqop | oid[] | conexclop | oid[] | conbin | pg_node_tree | consrc | text | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 9.1)
Table "pg_catalog.pg_constraint" Column | Type | Modifiers ---------------+--------------+----------- conname | name | not null connamespace | oid | not null contype | "char" | not null condeferrable | boolean | not null condeferred | boolean | not null convalidated | boolean | not null conrelid | oid | not null contypid | oid | not null conindid | oid | not null confrelid | oid | not null confupdtype | "char" | not null confdeltype | "char" | not null confmatchtype | "char" | not null conislocal | boolean | not null coninhcount | integer | not null conkey | smallint[] | confkey | smallint[] | conpfeqop | oid[] | conppeqop | oid[] | conffeqop | oid[] | conexclop | oid[] | conbin | pg_node_tree | consrc | text | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 9.0)
Table "pg_catalog.pg_constraint" Column | Type | Modifiers ---------------+------------+----------- conname | name | not null connamespace | oid | not null contype | "char" | not null condeferrable | boolean | not null condeferred | boolean | not null conrelid | oid | not null contypid | oid | not null conindid | oid | not null confrelid | oid | not null confupdtype | "char" | not null confdeltype | "char" | not null confmatchtype | "char" | not null conislocal | boolean | not null coninhcount | integer | not null conkey | smallint[] | confkey | smallint[] | conpfeqop | oid[] | conppeqop | oid[] | conffeqop | oid[] | conexclop | oid[] | conbin | text | consrc | text | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 8.4)
Table "pg_catalog.pg_constraint" Column | Type | Modifiers ---------------+------------+----------- conname | name | not null connamespace | oid | not null contype | "char" | not null condeferrable | boolean | not null condeferred | boolean | not null conrelid | oid | not null contypid | oid | not null confrelid | oid | not null confupdtype | "char" | not null confdeltype | "char" | not null confmatchtype | "char" | not null conislocal | boolean | not null coninhcount | integer | not null conkey | smallint[] | confkey | smallint[] | conpfeqop | oid[] | conppeqop | oid[] | conffeqop | oid[] | conbin | text | consrc | text | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 8.3)
Table "pg_catalog.pg_constraint" Column | Type | Modifiers ---------------+------------+----------- conname | name | not null connamespace | oid | not null contype | "char" | not null condeferrable | boolean | not null condeferred | boolean | not null conrelid | oid | not null contypid | oid | not null confrelid | oid | not null confupdtype | "char" | not null confdeltype | "char" | not null confmatchtype | "char" | not null conkey | smallint[] | confkey | smallint[] | conpfeqop | oid[] | conppeqop | oid[] | conffeqop | oid[] | conbin | text | consrc | text | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
pg_constraint (PostgreSQL 8.2)
Table "pg_catalog.pg_constraint" Column | Type | Modifiers ---------------+------------+----------- conname | name | not null connamespace | oid | not null contype | "char" | not null condeferrable | boolean | not null condeferred | boolean | not null conrelid | oid | not null contypid | oid | not null confrelid | oid | not null confupdtype | "char" | not null confdeltype | "char" | not null confmatchtype | "char" | not null conkey | smallint[] | confkey | smallint[] | conbin | text | consrc | text | Indexes: "pg_constraint_oid_index" UNIQUE, btree (oid) "pg_constraint_conname_nsp_index" btree (conname, connamespace) "pg_constraint_conrelid_index" btree (conrelid) "pg_constraint_contypid_index" btree (contypid)
文档: pg_constraint
更改历史记录
- PostgreSQL 17
- PostgreSQL 16
- 列
coninhcount
从INTEGER
更改为SMALLINT
(提交 90189eef)
- 列
- PostgreSQL 15
- 添加列
confdelsetcols
(提交 d6f96ed9)
- 添加列
- PostgreSQL 12
- 删除列
consrc
(提交 96b00c43)
- 删除列
- PostgreSQL 9.3
- 列
confmatchtype
:默认外键匹配样式现在为MATCH SIMPLE
(提交 f5297bdf)
- 列
- PostgreSQL 9.2
- 列
conisonly
重命名为connoinherit
(提交 09ff76fc)
- 列
- PostgreSQL 9.0
- 添加列
conindid
(提交 c1b9ec24)
- 添加列
- PostgreSQL 8.4
- 添加列
conislocal
和coninhcount
(提交 cd902b33)
- 添加列
- PostgreSQL 8.3
- 添加列
conpfeqop
、conppeqop
和conffeqop
(提交 7bddca34)
- 添加列
- PostgreSQL 7.3
- 添加(提交 7c6df91d)
参考文献
- PostgreSQL 文档: pg_constraint