user94474
user94474

Reputation:

sql select thru multiple postgres databases

is there a way to create a select statement that would retrieve data from multiple database in postgre?

i was thinking it would be something like this:

select * from dbname1.table1, dbname2.table2 where dbname1.table1.column1 = dbname2.table2.column1

Upvotes: 2

Views: 2883

Answers (3)

Flavio Cysne
Flavio Cysne

Reputation: 1456

As Milen A. Radev wrote, it's possible to execute cross-database queries using dblink package. There is an example in this other answer: https://stackoverflow.com/a/72562629/679240

Upvotes: 0

j_random_hacker
j_random_hacker

Reputation: 51326

From here:

It is not possible to access more than one database per connection.

Update: but see Milen's answer.

Upvotes: 0

Milen A. Radev
Milen A. Radev

Reputation: 62673

Have a look at the "dblink" contrib module.

OTOH it's possible that you treat the databases in a PostgreSQL cluster as equivalent to the databases in... let's say MySQL. Which is incorrect - the PostgreSQL databases contain schemas and those are the equivalent of the databases in MySQL.

Upvotes: 4

Related Questions