获取字段名、类型、注释、是否为空:
#######
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;
#######
SELECT
ROW_NUMBER () over() as 序号,
a.attname as 字段名称,
format_type(a.atttypid,a.atttypmod) as 类型及长度,
col_description(a.attrelid,a.attnum) as 注释
FROM pg_class as c,pg_attribute as a
where c.relname = 'sys_user_role' and a.attrelid = c.oid and a.attnum > 0
Navicat查询:
导出结果: