阅读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
答案 0 :(得分: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
架构。