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

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


当前回答

对于postgresql中的私有模式xxx:

SELECT table_name FROM information_schema.tables 
 WHERE table_schema = 'xxx' AND table_type = 'BASE TABLE'

如果没有table_type = 'BASE TABLE',你将列出表和视图

其他回答

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

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

\dt information_schema.

从psql内部,应该没问题。

对于postgresql中的私有模式xxx:

SELECT table_name FROM information_schema.tables 
 WHERE table_schema = 'xxx' AND table_type = 'BASE TABLE'

如果没有table_type = 'BASE TABLE',你将列出表和视图

列出你的表使用:

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

它将只列出您创建的表。

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

从information_schema.tables中选择*

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

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