码迷,mamicode.com
首页 > 数据库 > 详细

postgresql 获取所有表名、字段名、字段类型、注释

时间:2018-07-14 21:34:36      阅读:1179      评论:0      收藏:0      [点我收藏+]

标签:desc   not   where   script   分表   elf   format   otn   过滤   

获取表名及注释:

select relname as tabname,cast(obj_description(relfilenode,‘pg_class‘) as varchar) as comment from pg_class c 
where  relkind = ‘r‘ and relname not like ‘pg_%‘ and relname not like ‘sql_%‘ order by relname

过滤掉分表:

加条件 and relchecks=0 即可

 

获取字段名、类型、注释、是否为空:
SELECT col_description(a.attrelid,a.attnum) as comment,format_type(a.atttypid,a.atttypmod) as type,a.attname as name, a.attnotnull as notnull   
FROM pg_class as c,pg_attribute as a where c.relname = ‘表名‘ and a.attrelid = c.oid and a.attnum>0

postgresql 获取所有表名、字段名、字段类型、注释

标签:desc   not   where   script   分表   elf   format   otn   过滤   

原文地址:https://www.cnblogs.com/firstdream/p/9310935.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!