On the page: https://docs.djangoproject.com/en/dev/ref/models/querysets
/#field-lookups we can read:
''istartswith
Case-insensitive starts-with.
Example:
Entry.objects.filter(headline__istartswith='will')
SQL equivalent:
SELECT ... WHERE headline ILIKE 'Will%';''
But there is no db backend which uses ILIKE. LIKE will be used for MySQL.
Again if you assume MySQL by default in documentation then:
''startswith
Case-sensitive starts-with.
Example:
Entry.objects.filter(headline__startswith='Will')
SQL equivalent:
SELECT ... WHERE headline LIKE 'Will%';
''
is incorrect because LIKE BINARY will be used.
The same for contains, icontains, endswith and iendswith.
--
Ticket URL: <https://code.djangoproject.com/ticket/20775>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/20775#comment:1>
* cc: eromijn@… (added)
* status: new => closed
* resolution: => invalid
Comment:
But the documentation speaks of an SQL //equivalent//, not of the SQL that
the ORM query would produce.
The equivalent is provided as "this is how you would do a query like this
in SQL without the Django ORM", probably so that it's easier for people
familiar with SQL to understand the ORM syntax. In other words, I see no
error in the documentation here.
--
Ticket URL: <https://code.djangoproject.com/ticket/20775#comment:2>
* status: closed => new
* resolution: invalid =>
Comment:
But it is really confuses. If reader knows SQL very well, he knows that
there is big performance difference between LIKE, LIKE BINARY and ILIKE.
And let's scroll down to regex section:
''
regex
.........
Example:
Entry.objects.get(title__regex=r'^(An?|The) +')
SQL equivalents:
SELECT ... WHERE title REGEXP BINARY '^(An?|The) +'; -- MySQL
SELECT ... WHERE REGEXP_LIKE(title, '^(an?|the) +', 'c'); -- Oracle
SELECT ... WHERE title ~ '^(An?|The) +'; -- PostgreSQL
SELECT ... WHERE title REGEXP '^(An?|The) +'; -- SQLite
''
We also see here "SQL equivalents" but for concrete backend.
If you insist that current description is correct, I'd recommend add
concrete examples for MySQL and PostgreSQL.
--
Ticket URL: <https://code.djangoproject.com/ticket/20775#comment:3>
* stage: Unreviewed => Accepted
* type: Bug => Cleanup/optimization
Comment:
I think it's probably fine to clarify the documentation. Hopefully this
can be done in a fashion that's not overly verbose as I imagine most users
won't care about these implementation details.
--
Ticket URL: <https://code.djangoproject.com/ticket/20775#comment:4>
Comment (by areski):
Right now the documentation is easy to read for new comers, and adding
this will complicate the documentation awfully. I could agree that it may
be confusing for SQL experts but they are more likely to understand what
SQL equivalent means.
If the goal is to improve the documentation for people knowing very well
SQL, then we could simply disclose that the "SQL equivalent" is not
database or datatype specific.
--
Ticket URL: <https://code.djangoproject.com/ticket/20775#comment:5>