是否可以从两个独立的 postgres 数据库中JOIN
行?
我在一台服务器上使用带有几个数据库的系统,有时我真的需要这样的功能。
最佳答案
根据 http://wiki.postgresql.org/wiki/FAQ
There is no way to query a database other than the current one. Because PostgreSQL loads database-specific system catalogs, it is uncertain how a cross-database query should even behave. contrib/dblink allows cross-database queries using function calls. Of course, a client can also make simultaneous connections to different databases and merge the results on the client side.
编辑:3 年后(2014 年 3 月),此 FAQ 条目已经过修订并且更有帮助:
How do I perform queries using multiple databases?
There is no way to directly query a database other than the current one. Because PostgreSQL loads database-specific system catalogs, it is uncertain how a cross-database query should even behave.
The SQL/MED support in PostgreSQL allows a "foreign data wrapper" to be created, linking tables in a remote database to the local database. The remote database might be another database on the same PostgreSQL instance, or a database half way around the world, it doesn't matter. postgres_fdw is built-in to PostgreSQL 9.3 and includes read/write support; a read-only version for 9.2 can be compiled and installed as a contrib module.
contrib/dblink allows cross-database queries using function calls and is available for much older PostgreSQL versions. Unlike postgres_fdw it can't "push down" conditions to the remote server, so it'll often land up fetching a lot more data than you need.
Of course, a client can also make simultaneous connections to different databases and merge the results on the client side.
关于postgresql - 合并来自两个独立数据库的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4678862/