![](/img/trans.png)
[英]Postgres constraint name need to be unique across single table or entire schema?
[英]Query Constraint Clauses With Schema and Table (Postgres)
我正在尝试在postgres中查询约束子句以及架构和表。 我已经尽可能地将information_schema.check_constraints
标识为一个有用的表。 问题是
select *
from information_schema.check_constraints
结果为constraint_catalog
, constraint_schema
, constraint_name
, check_clause
。 我想要的是check_clause
,此表还为我提供了constraint_schema
。 但是,它没有提供定义此约束的表。 在我当前的数据库中,我在相同模式的不同表上定义了具有相同名称的约束(其本身可能是较差的设计,但我需要处理)。 也可以在这里获取表名吗?
select
conname,
connamespace::regnamespace as schemaname,
conrelid::regclass as tablename,
consrc as checkclause,
pg_get_constraintdef(oid) as definition
from
pg_constraint
where
contype = 'c'
and conrelid <> 0; -- to get only table constraints
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.