postgressql数据库查询数据库中的所有表及表注释、表的字段、类型、注释

一、查询Postgres数据库中的所有表信息(表名、备注)

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 即可

二、查询Postgres数据库中的表字段名、类型、注释、注释是否为空

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

注意:如果直接复制spl去运行的话,如果不能运行,请把引号改英文的。

你可能感兴趣的:(postgres)