没有模式表的 PostgreSQL 列表表

标签 postgresql

阅读 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/

相关文章:

node.js - sequelize postgres 批量插入忽略如果存在

macos - Postgres createdb : command not found Mac OS Terminal

postgresql - 连接系统,包括 OPC UA IoT Agent、Orion Context Broker。 Cygnus 和 Postgres 的历史数据

postgresql - 尝试编辑 Postgres 表中的任何单元格时 PhpStorm DB 控制台 View 中出现 "Table is read-only. Search path mismatch"错误

python - 如何使用脚本在 django/heroku 项目中更新我的生产数据库

python - Django datetime.datetime 到 Decimal 不支持迁移

c# - 自定义类型的 Dapper 数组

java - 如何计算具有特定值和特定用户/人(行中)的数据?

django - 为什么将 Redis 与 PostgreSQL 一起使用,为什么不只是其中之一?

sql - 为相等性和时间戳范围查询创建索引