在PostgreSQL的information_schema中列出所有表的最好方法是什么?
澄清一下:我正在使用一个空DB(我没有添加任何自己的表),但我想查看information_schema结构中的每个表。
在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'来查看信息模式中的表。
列出你的表使用:
SELECT table_name FROM information_schema.tables WHERE table_schema='public'
它将只列出您创建的表。
\dt information_schema.
从psql内部,应该没问题。
你可以用also
select * from pg_tables where schemaname = 'information_schema'
一般来说,pg* tables允许您查看db中的所有内容,不受您的权限限制(当然,如果您有权限访问这些表)。