Best practice for doing cross database joins using ORM
See original GitHub issueQuestion
Hi there, in snowflake we often have multiple databases, with their own set of schemas, and tables inside those schemas. Ideally data shouldn’t have to move between these databases nor schemas, but in practice they often do.
One use case is when there might be valuable data between two different databases. In my example, I’m going to reference database A
and database B
which has schemas ant
and babboons
, which has tables apples
and bananas
respectively.
Through a direct query using snowflake SQL, you could implement a join like
select
*
from A.ant.apples a
join B.babboons.bananas b
on a.id = b.id
How can you implement a cross database join like the above example using a single session through the ORM interface? my understanding is that a session can only point towards one database.
The query would look like such:
# assume session was created with database=A
query = session.query(Ant.id, Banana.id)\
.join(Banana, Ant.id == Banana.id)
This would obviously fail because the query would search for a A.babboons.banana (Database A).
Can this be done through the ORM interface without dropping to SQL? If so, what’s the best practice in doing this?
Issue Template
Please answer these questions before submitting your issue. Thanks!
- What version of Python are you using (
python --version
)?
Python 2.7.12
- What operating system and processor architecture are you using (
python -c 'import platform; print(platform.platform())'
)?
Linux-4.9.76-3.78.amzn1.x86_64-x86_64-with-glibc2.2.5
- What are the component versions in the environment (
pip list
)?
snowflake-connector-python==1.5.8 snowflake-sqlalchemy==1.1.0
-
What did you do? If possible, provide a recipe for reproducing the error. A complete runnable program is good.
-
What did you expect to see?
N/A
- What did you see instead?
N/A
- Can you set logging to DEBUG and collect the logs?
N/A
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
This fix will be released on May 17th.
@smtakeda Thank you, @kevinjfoley and I confirmed this is working now 😃 .