#30074: Cannot Un-escape LIKE wildcards without .extra()
-------------------------------------+-------------------------------------
Reporter: dwdresser | Owner: nobody
Type: New | Status: new
feature |
Component: Database | Version: 2.1
layer (models, ORM) |
Severity: Normal | Keywords: QuerySet.extra
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Currently, django escapes wildcards used in SQL LIKE clauses. See here
https://docs.djangoproject.com/en/dev/topics/db/queries/#escaping-percent-
signs-and-underscores-in-like-statements.
At times, I have found it desirable to actually want wildcards, and there
are only two options to replicate this to my knowledge:
1) Raw SQL using .extra()
2) Using a regular expression such as
.filter(somefield!__regex=<regex_lookup>)
The first option is undesirable because its using raw sql, not high level
python. The second is undesirable because SQL REGEX is much much slower
than using a LIKE clause with wildcards.
I propose adding an optional parameter (thus allowing backwards
compatibility) within .filter(), such as
.filter(somefield!__contains=FO%BAR, escape=False) which will allow the
filter expression to not escape the underscores and percentage signs.
--
Ticket URL: <https://code.djangoproject.com/ticket/30074>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.94c21c9e0b8ba2911ff1b566fde7432a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.