gpt4 book ai didi

postgresql - 对所有模式 Postgres 运行查询

转载 作者:行者123 更新时间:2023-11-29 13:12:48 24 4
gpt4 key购买 nike

我们在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com