--查看所有表select*from pg_catalog.pg_class where relname ='TABLE_NAME';select*from pg_catalog.pg_tables where tablename ='TABLE_NAME';--查看字段select*from pg_catalog.pg_attribute;--查看类型select*from pg_catalog.pg_type;--查看描述select*from pg_catalog.pg_description;--查找库的oidselect*from pg_catalog.pg_namespace where nspname ='TABLE_NAMESPACE';--关联查询表结构--如果不限制name_space会查到不同数据库下的同名表,查出的字段会重复select
a.attnum as attnum,
c.relname as relname,
a.attname as attname,
c.oid,
a.attrelid,
cast(obj_description(c.oid)asvarchar)as obj_description,
concat_ws('',t.typname,substring(format_type(a.atttypid,a.atttypmod)from'\(.*\)'))astype,
d.description as description
from pg_catalog.pg_attribute a
leftjoin pg_catalog .pg_class c
on a.attrelid = c.oid
leftjoin pg_catalog.pg_type t
on t.oid=a.atttypid
leftjoin pg_catalog.pg_description d
on d.objoid = a.attrelid
and d.objsubid=a.attnum
where c.relname ='TABLE_NAME'and a.attnum >0and c.relnamespace =(select b."oid"from pg_catalog.pg_tables a
leftjoin pg_catalog.pg_namespace b
on a.schemaname=b.nspname
where tablename ='TABLE_NAME'and a.schemaname='TABLE_NAMESPACE')orderby c.relname desc,a.attnum asc;