Any difference between
a = session.query(Accounts).filter(Accounts.key = 4).first()
and
a = session.query(Accounts).filter(Accounts.key = 4)[0]
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As @mata indicated and pointed to the source code, there is no difference in the execution path of the two. In fact, you can also enable SQL logging by setting
echo=Truewhen you create an engine, and you will see that the both SQL statements are exactly the same (some sort ofSELECT ... FROM ... WHERE ....id = ? LIMIT ? OFFSET ?)But, if the
Accounts.keyis actually a primary key, the best way to get a persistent instance by the primary key is to use theQuery.getmethod, which will generateSELECT ... FROM ... WHERE ....id = ?and it should be good enough. I assume it is not going to be faster, but is much cleaner.