阅读 PostgreSQL 文档后,我确定我可以使用以下查询在 PostgreSQL 中创建表名的绝对列表...
SELECT tablename FROM pg_catalog.pg_tables ORDER BY tablename ASC;
这会生成一些单独的内容(简化示例列表)......
my_table_1
my_table_1
pg_aggregate
pg_am
pg_amop
sql_features
sql_implementation_info
sql_languages
不幸的是,这也列出了带有前缀的表,例如 pg_
和 sql_
我认为它们是数据库模式的一部分。
如何使用 SELECT
查询列出不属于架构一部分的表?
我已经知道如何在 PSQL 命令行中使用 \dtM
命令来执行此操作,尽管在这种情况下它不能满足我的目的。
在示例中,我只想返回以下内容...
my_table_1
my_table_1
最佳答案
使用 information_schema
更容易对于这样的查询:
select *
from information_schema.tables
where table_schema = 'public';
或者:
select *
from information_schema.tables
where table_schema not in ('pg_catalog', 'information_schema');
information_schema.tables
已过滤掉 temp
模式。
关于没有模式表的 PostgreSQL 列表表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27260023/