I am dealing with a mySQL/sqlAlchemy execute statement that looks like this:
stmt =开发者_如何学编程 'SELECT * from myTable where id=:idVar AND pct LIKE :pctVar'
args = {idVar:5, pctVar:'5%\\%'}
result = session.execute(stmt, args).fetchall()
How do I escape the '%'? The above does not match "55%"
Try the following query with explicit ESCAPE
specification:
stmt = "SELECT * from myTable where id=:idVar AND pct LIKE :pctVar ESCAPE '\\'"
If it works, then check out NO_BACKSLASH_ESCAPES option.
精彩评论