0

Hi I have the following query to Database. It is working correctly in SQL, but not working in python. How to solve this? Thanks in advance.

SELECT distinct id , id FROM XX WHERE id LIKE '01%' GROUP BY id

1 Answer 1

1

Double the % to escape it, as Django treats it as a format string where % characters have special meaning:

SELECT distinct id, id FROM XX WHERE id LIKE '01%%' GROUP BY id
--                                              ^^
Sign up to request clarification or add additional context in comments.

2 Comments

But am getting a strange error as invalid literal for int() with base 10: 'XX'
@blackwindow: How are you using the query in Django? Please add your actual code to your question. Give us the full traceback for the error too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.