1.获取数据库中所有table名:

  1. SELECT tablename FROM pg_tables
  2. WHERE tablename NOT LIKE 'pg%'
  3. AND tablename NOT LIKE 'sql_%'
  4. ORDER BY tablename;

2.获取数据库中所有table名及table的注解信息:

  1. SELECT tablename,obj_description(relfilenode,'pg_class') FROM pg_tables a, pg_class b
  2. WHERE
  3. a.tablename = b.relname
  4. and a.tablename NOT LIKE 'pg%'
  5. AND a.tablename NOT LIKE 'sql_%'
  6. ORDER BY a.tablename;

3.获取数据库中所有table名及table的注解信息:

  1. 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
  2. FROM pg_class as c,pg_attribute as a
  3. where c.relname = 'tablename' and a.attrelid = c.oid and a.attnum > 0

4.查询字段名、字段类型及字段长度和字段注释:

  1. select a.attnum,a.attname,concat_ws('',t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod) from '\(.*\)')) as type,d.description from pg_class c, pg_attribute a , pg_type t, pg_description d
  2. where c.relname = 'table_name' and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid and d.objoid=a.attrelid and d.objsubid=a.attnum