Get all table names in database:

SELECT   tablename   FROM   pg_tables  
WHERE   tablename   NOT   LIKE   'pg%'  
AND tablename NOT LIKE 'sql_%'
ORDER   BY   tablename;
Copy the code

Get all table names and table annotation information from database:

SELECT   tablename,obj_description(relfilenode,'pg_class')  FROM   pg_tables  a, pg_class b
WHERE   
a.tablename = b.relname
and a.tablename   NOT   LIKE   'pg%'  
AND a.tablename NOT LIKE 'sql_%'
ORDER   BY   a.tablename;
Copy the code

Select * from table;

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 = 'tablename' and a.attrelid = c.oid and a.attnum>0
Copy the code

Select * from field name, field type, field length, field comment;

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 
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
Copy the code

Reference:

  • PostgreSQL Obtains field information about all tables

Blog.csdn.net/zw3413/arti… ?

  • PostgreSQL 9.5.3 Chinese manual

www.postgres.cn/docs/9.5/in…