PostgreSQL 根据表名查询字段,类型,注释,非空 去掉表名则是查询所有的。
可以用来写数据库设计文档,或者其他需要查询表字段,类型,注释的地方
SELECT
a.attname as 字段名,
REPLACE(format_type(a.atttypid,a.atttypmod),'character varying','varchar') as 类型,
a.attnotnull as 非空, col_description(a.attrelid,a.attnum) as 注释
FROM
pg_class as c,pg_attribute as a
where a.attrelid = c.oid and a.attnum>0 and c.relname ='tableA'
and col_description(a.attrelid,a.attnum) is not null
查询结果: