postgresql - 合并来自两个独立数据库的结果

标签 postgresql join

是否可以从两个独立的 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/

相关文章:

r - 使用大于和小于列名中的符号连接 data.tables 时出现问题

sql - 如何在 PostgreSQL 中表示不确定的日期

spring - 自动化 API 黑盒测试

mysql连接产品类别多关系查询

mongodb - 如何在 $lookup Mongodb 的 LocalField 中将字符串转换为 objectId

sql - NATURAL(JOIN)在生产环境中是否被认为有害?

mysql - mysql中如何连接两个不同的表

java - Hibernate ID 生成器困惑

database - 为什么 postgreSQL 会两次检查外键约束?

sql - PostgreSQL:根据列值转换列