在Postgre中通常需要使用sql来查询一个表的表结构,postgre也提供了数据字典保存了表和字段的信息。可以用如下的语句查询表的结构。
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 = 'XXX' and a.attrelid = c.oid and a.attnum>0
XXX代表需要查找的表名.