在PostgreSQL的information_schema中列出所有表的最好方法是什么?

澄清一下:我正在使用一个空DB(我没有添加任何自己的表),但我想查看information_schema结构中的每个表。


当前回答

select * from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE'

只订你们的桌子

其他回答

如果你想要一个快速而肮脏的一行查询:

从information_schema.tables中选择*

您可以直接在查询工具中运行它,而不必打开psql。

(其他帖子建议更具体的information_schema查询,但作为一个新手,我发现这个一行查询可以帮助我掌握表格)

您应该能够从information_schema中运行select *。获得Postgres为特定数据库管理的每个表的列表。

您还可以添加where table_schema = 'information_schema'来查看信息模式中的表。

1.从information_schema中获取所有表和视图。表,包括information_schema和pg_catalog。

select * from information_schema.tables

2.获取属于特定模式的表和视图

select * from information_schema.tables
    where table_schema not in ('information_schema', 'pg_catalog')

3.只获取表(几乎\dt)

select * from information_schema.tables
    where table_schema not in ('information_schema', 'pg_catalog') and
    table_type = 'BASE TABLE'
\dt information_schema.

从psql内部,应该没问题。

列出你的表使用:

SELECT table_name FROM information_schema.tables WHERE table_schema='public'

它将只列出您创建的表。