W
W
WAYNEDEV2021-10-05 15:43:28
PostgreSQL
WAYNEDEV, 2021-10-05 15:43:28

How to make a left join query from two tables in different databases in node, postgres?

Hello!

There are two pools:

const pool = new Pool({
    host: 'db',
    user: 'postgres',
    password: 'pass',
    port: 5432,
    database: 'main', // и такой же пул, только с другим именем. В общем объекта два
});


How do I make a request like:
db(ТУТ использовать какой пулл?, второй или первой базы?).query(
  'SELECT db1.users.name FROM db1.users LEFT JOIN db2.rating on db1.users.id=db2.rating.user_id'
)


I would be very grateful for your help!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
galaxy, 2021-10-05
@galaxy

It is forbidden. This is not mysql, postgres does not support cross-db queries

D
dwdraugr, 2021-10-05
@dwdraugr

From physically different databases, this will not work, just take data from two databases with your hands and join it in the code.
Unless your data is not in two databases, but in one, but different schemes, but then there is nowhere for two connections to come from.

K
ky0, 2021-10-05
@ky0

Connect the base via FDW , then it will be possible to touch both in one request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question