postgresql 对多个 schema 的请求
我有一个数据库,每个用户都有一个模式。
有没有办法查询每个模式中的表?
类似于: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您需要编写一个函数 - 无论是服务器端函数还是客户端函数,无论您使用什么语言 - 为每个模式执行一次查询。
您还可以创建一个在所有模式之间执行 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.
是的,您可以使用 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