gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
How escape % sign in django raw sql query?
- User
How escape % sign in django raw sql query?
- Assistant
In Django, you can escape the
%symbol in raw SQL queries by using double percent signs%%.For example, if you have a query like this:
codeSELECT * FROM mytable WHERE mycolumn LIKE '%text%'You can escape the
%symbol like this:pythonquery = "SELECT * FROM mytable WHERE mycolumn LIKE '%%text%%'"By using
%%instead of%, Django will pass the literal%symbol to the database.