Could anyone explain the difference between filter and filter_by functions in SQLAlchemy?
Which one should I be using?
Could anyone explain the difference between filter and filter_by functions in SQLAlchemy? Which one
Share
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.
filter_byis used for simple queries on the column names using regular kwargs, likedb.users.filter_by(name='Joe')The same can be accomplished with
filter, not using kwargs, but instead using the ‘==’ equality operator, which has been overloaded on the db.users.name object:db.users.filter(db.users.name=='Joe')You can also write more powerful queries using
filter, such as expressions like:db.users.filter(or_(db.users.name=='Ryan', db.users.country=='England'))