postgresql 对多个 schema 的请求

发布于 2024-09-16 05:40:15 字数 151 浏览 2 评论 0原文

我有一个数据库,每个用户都有一个模式。

有没有办法查询每个模式中的表?

类似于: select id, name from *.simulation 不起作用...

感谢您的帮助!

I have a database, with every users having a schema.

Is there a way to query a table in every schema?

Something like: select id, name from *.simulation doesn't work...

Thank you for your help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑饮青盏花 2024-09-23 05:40:15

不,您需要编写一个函数 - 无论是服务器端函数还是客户端函数,无论您使用什么语言 - 为每个模式执行一次查询。

您还可以创建一个在所有模式之间执行 UNION ALL 的 VIEW,但是如果您的模式是动态添加和删除的,那么维护工作将非常繁重。

No, you will need to write a function - either a server side function or a client side function in whatever language you're using - that executes the query once for each schema.

You could also create a VIEW that does UNION ALL between all the schemas, but that's going to be a lot of work to maintain if your schemas are dynamically added and removed.

固执像三岁 2024-09-23 05:40:15

是的,您可以使用 SET search_path TO ... 来指向所有架构。如果您不知道模式的所有名称,请将其包装在一个函数中,该函数首先选择所有模式,然后设置整个 search_path。

http://www.postgresql.org/docs/current/interactive/ sql-set.html

Yes you can, use SET search_path TO ... to point to all schema's. If you don't know all the names of the schemas, wrap it in a function that first selects all schemas and then set the entire search_path.

http://www.postgresql.org/docs/current/interactive/sql-set.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文