Postgresql查询表和表结构

Posted 逆水行舟,不进则退

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Postgresql查询表和表结构相关的知识,希望对你有一定的参考价值。

查询表名

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;

以上是关于Postgresql查询表和表结构的主要内容,如果未能解决你的问题,请参考以下文章

PostgreSQL字段名和表名大小写的问题

怎样设置PostgreSQL中字段和表名对大小写敏感

如何使用 init.sql 在 Postgresql 中创建数据库、模式和表

PostgreSQL 是不是支持表(片段)的透明压缩?

查询MySQL数据表的字段名和表结构

怎样将postgresql数据迁移到oracle中