我们在 PostgreSQL 中维护了大约 100 多个模式。现在我们想查询所有模式,有什么办法吗? 除了 View 、程序和 union all? 任何允许您查询多个模式的 postgres 函数
最佳答案
以下目录查询将为数据库所有模式中的每个表生成有效查询。您可以将其复制到有效的 SQL 文件。
SELECT 'SELECT * FROM ' || table_schema || '.' || table_name || ';' AS query
FROM information_schema.tables
WHERE table_schema IN
(
SELECT schema_name
FROM information_schema.schemata
WHERE schema_name NOT LIKE 'pg_%' AND schema_name != 'information_schema'
);
这有帮助吗?
关于postgresql - 对所有模式 Postgres 运行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52777436/