【问题标题】:PostgreSQL List Tables without Schema Tables没有模式表的 PostgreSQL 列表表
【发布时间】:2015-01-31 07:48:45
【问题描述】:

在阅读了 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

【问题讨论】:

    标签: postgresql


    【解决方案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 架构。

    【讨论】:

    • 谢谢@a_horse_with_no_name,SELECT * FROM information_schema.tables WHERE table_schema NOT IN ('pg_catalog', 'information_schema'); 工作得很好。希望我的笔记本电脑屏幕是高清的,所以当 psql 输出命令时(所以我可以直观地使用它)我可以看到没有启用换行的数据。例如,使用它来分析架构和公共之间的差异。
    猜你喜欢
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    • 2021-12-26
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 2019-12-28
    相关资源
    最近更新 更多