💭 Read a Range of Data - LIMIT and OFFSET - SQLModel ==================================================== !https://sqlmodel.tiangolo.com/tutorial/limit-and-offset/ Date: January 12, 2024 Read a Range of Data - LIMIT and OFFSET - SQLModel SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness. sqlmodel.tiangolo.com [1] Today I was running some sqlmodel queries through the sqlalchemy orm. Admittedly I've not done enough orm queries before, and I've done quite a bit of raw sql. I was trying to get objects from two separate models that had relationships setup. ``` python session.query(User, Images).where(User.id == 3).all() ``` It is incredibly slow, and gives me the following warning. ``` python SELECT statement has a cartesian product between FROM element(s) ``` What I learned from the SQLModel docs is that you should give it a join to correct this and go much faster. ``` python session.query(User, Images).join(Images).where(User.id == 3).all() ``` !!! note This post is a thought [2]. It's a short note that I make about someone else's content online #thoughts [3] References: [1]: https://sqlmodel.tiangolo.com/tutorial/limit-and-offset/ [2]: /thoughts/ [3]: /tags/thoughts/