Reverse version of sql LIKE in sqlalchemy [duplicate]

那年仲夏 提交于 2019-12-23 19:43:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!