question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best practice for doing cross database joins using ORM

See original GitHub issue

Question

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!

  1. What version of Python are you using (python --version)?

Python 2.7.12

  1. 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

  1. What are the component versions in the environment (pip list)?

snowflake-connector-python==1.5.8 snowflake-sqlalchemy==1.1.0

  1. What did you do? If possible, provide a recipe for reproducing the error. A complete runnable program is good.

  2. What did you expect to see?

N/A

  1. What did you see instead?

N/A

  1. Can you set logging to DEBUG and collect the logs?

N/A

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
smtakedacommented, May 10, 2018

This fix will be released on May 17th.

1reaction
tchoedakcommented, May 17, 2018

@smtakeda Thank you, @kevinjfoley and I confirmed this is working now 😃 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best practice for doing cross database joins using ORM
Best practice for doing cross database joins using ORM. https://github.com/snowflakedb/snowflake-sqlalchemy/issues/47.
Read more >
python - Building queries with a cross database join using ...
I am using SQLalchemy ORM. I have not been able to find any solution online that meets my specific case. My question is...
Read more >
Quick Tips in Pics #1: Cross-Database Joins - The Data School
Cross -Database Joins at a Glance ... Don't forget! Joining across databases joins at the row level. If you want to join on...
Read more >
Integrate your data with cross-database joins in Tableau 10
From tips on using Tableau more effectively to learning how everyday people are dealing with data challenges, the Tableau blog is a place...
Read more >
Cross-Database Joins - Sisense
Cross -database joins are enabled by our Postgres-based data cache. Each customer's data is stored in the same database, with one schema per...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found