1👍
✅
I think, you need this:
from django.db import connection
cursor = connection.cursor()
code = 'statin'
query = 'SELECT * FROM chemical WHERE name ~* {}'
print query.format(code)
cursor.execute(query.format(code))
print cursor.fetchall()
There’s nothing to do with Django, you have to format the string properly.
0👍
Actually, the Django ORM can perform regex lookups for you, using the __regex
lookup, as seen here: https://docs.djangoproject.com/en/1.8/ref/models/querysets/#regex
Or, as you are doing there, a case insensitive regex, with the __iregex
lookup: https://docs.djangoproject.com/en/1.8/ref/models/querysets/#iregex
- [Answer]-Django query with annotated conditional expression uses INNER JOIN. How do I get it to use OUTER JOIN?
- [Answer]-Traceback error: Django dictionary
Source:stackexchange.com