Postgresql查询表和表结构

89921334 2020-02-20

查询表名

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

或者

select tablename from pg_tables where schemaname='public'

查询表结构

select
col.table_schema,
col.table_name,
col.ordinal_position,
col.column_name,
col.data_type,
col.character_maximum_length,
col.numeric_precision,
col.numeric_scale,
col.is_nullable,
col.column_default,
des.description
from
information_schema.columns col left join pg_description des on
col.table_name::regclass = des.objoid
and col.ordinal_position = des.objsubid
where
table_schema = 'public'
and table_name = 'table_name'
order by
ordinal_position;

相关推荐

84593973 / 0评论 2020-06-14