Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to perform a join across multiple sessions in sqlalchemy?

If I have multiple sessions to different databases, is there a way to perform a join across them in one query?

For instance, I'm integrating two programs, with a table in the middle to translate id's from one to another. I'm currently just trying to run separate queries, building the next one using the data from the previous one. It seems to be getting a bit messy and I would like to do it in one query.

I haven't found anything that says this is possible, and knowing that the query is done on the session itself leads me to believe this might not be.

Thanks

like image 584
Mark Avatar asked Nov 02 '22 21:11

Mark


1 Answers

if these are truly separate database servers, you'd need to use a system like dblink to establish a transparent proxy from one database to the other. Otherwise, if these databases are on the same server, there's usually some way to refer to tables in other schemas/databases, but it highly depends on the type of database in use.

But in any case, these routines would all involve being able to address all the databases on a single connection, which means in a single session. If you can't do it in one SQL statement, then you can't use a SQL JOIN, you'd need to collate data in memory.

like image 109
zzzeek Avatar answered Nov 09 '22 11:11

zzzeek