开发者

escape character for sqlalchemy using execute()

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜