2017-05-09 52 views
0

我想查询约束条款以及架构和表格在postgres中。我已经尽可能将information_schema.check_constraints确定为有用的表格。问题是,这样做查询约束条款与架构和表(Postgres)

select * 
from information_schema.check_constraints 

结果constraint_catalogconstraint_schemaconstraint_namecheck_clausecheck_clause是我想要的,这张表也给了我constraint_schema。但是,它并没有给出这个约束被定义的表。在我当前的数据库中,我在同一个模式中的不同表上定义了相同的名称(这本身也许是糟糕的设计,但我需要处理)。是否有可能在这里获得表名?

回答

1
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 

About pg_constraint

About Object Identifier Types