postgresql request over several schema

ε祈祈猫儿з 提交于 2019-12-24 14:46:04

问题


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 !


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/3545990/postgresql-request-over-several-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!