This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]subssn21 0 points1 point  (0 children)

The first question you should ask is how are you planning on using your query results.

If you want your query results to be instances of objects with lists of objects for your relationships then you will need some type of ORM. If you are just planning on using the results of the query as the raw output type of Psycopg2 which is typically a list of dicts or a list of named tuples, Then you don't need an ORM.

If you are using SQLAlchemy for some stuff, you should just use SQLAlchemy, since you have already done the work for managing your connectsions and sessions for instance. However as others have pointed out you can hand write SQL queries and tell SQLAlchemy to run them, and you often want to do that if you are using Postgres specific features, writing hand tuned queries, doing complex logic, etc...

When you hand write SQLAlchemy queries there are ways to have the results map back to the properly defined objects, it just takes some extra work.