问题
By "reverse version of like" I mean exactly like this question. The question is how to make a query like that in sqlalchemy?
I found out that to make "SELECT LIKE" query in sqlalchemy I should make something like that
session.query(Book).filter(Book.title.like("%"+my_title+"%"))
Because like
is method of column, I don't know how to use like
method to ask about "%" + Book.title + "%"
.
回答1:
Thanks to this question, I figure out how to do that :)
session.query(Book).
filter(bindparam('book_title', book.title).contains(Book.title)).first()
来源:https://stackoverflow.com/questions/15711872/reverse-version-of-sql-like-in-sqlalchemy