Naisheel Verdhan
Naisheel Verdhan

Reputation: 5133

Is it possible to use multiple databases within same query using pg-promise?

I have two related tables T1 and T2 in different databases D1 and D2. I need to do an inner join between two tables.

From here: Joining Results from Two Separate Databases it is clear that separate queries should be made to two databases and results to be consolidated on client side OR use dblink / postgres-fdw.

However, I see this issue: Multiple Databases #1 and the use of $dc parameter here: pg-promise/Database.

I believe issue: Multiple Databases #1 just facilitates allowing connecting to multiple databases within the same codebase.

The description of $dc parameter states:

This is mainly to facilitate the use of multiple databases which may need separate protocol extensions, or different implementations within a single task

However, I did not find any examples.

Is the $dc paramter just a database context object that can be accessed, or would it allow to do an inner join between two different databases?

Is there a way to do utilise two database connections but do a join across databases in without having to do it on client-side using pg-promise?

Upvotes: 2

Views: 1437

Answers (1)

vitaly-t
vitaly-t

Reputation: 25840

Is the $dc paramter just a database context object that can be accessed, or would it allow to do an inner join between two different databases?

It is the former.

Is there a way to do utilise two database connections but do a join across databases in without having to do it on client-side using pg-promise?

No. Each Database object represents only a single connection to A database.

Database Context is there to allow re-use of tasks, transactions and protocol extensions across multiple Database objects, by relying on its value.

Upvotes: 2

Related Questions