Paul
Paul

Reputation: 3091

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%"

Upvotes: 2

Views: 2773

Answers (1)

van
van

Reputation: 77012

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.

Upvotes: 3

Related Questions