开发者

escape character for sqlalchemy using execute()

开发者 https://www.devze.com 2023-03-21 06:24 出处:网络
I am dealing with a mySQL/sqlAlchemy execute statement that looks like this: stmt =开发者_如何学编程 \'SELECT * from myTable where id=:idVar AND pct LIKE :pctVar\'

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

精彩评论

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