#30242: Double spaces before limit/offset clause in as_sql() of SQLCompiler
-------------------------------------+-------------------------------------
Reporter: hangpark | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: master
layer (models, ORM) | Keywords: sql
Severity: Normal | databaseoperations sqlcompiler
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
`SQLCompiler` has `as_sql()` method to create the SQL for a given query.
Specifically, end-users can get the SQL string of their `QuerySet` by this
method like:
{{{
User.objects.values('id').query.__str__()
}}}
where `User` is a basic user model.
Absolutely, this returns a SQL string `SELECT "auth_user"."id" FROM
"auth_user"`, and note that every separator between tokens is all single
space.
However, any query which has limit/offset clause produces double spaces
before limit/offset clause. For example:
{{{
User.objects.values('id')[1:2].query.__str__()
}}}
returns
{{{
SELECT "auth_user"."id" FROM "auth_user" LIMIT 1 OFFSET 1
}}}
not
{{{
SELECT "auth_user"."id" FROM "auth_user" LIMIT 1 OFFSET 1
}}}
These queries are executed as well as expected but seem not a good
practice for formatting SQL as a string.
--
Ticket URL: <https://code.djangoproject.com/ticket/30242>
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/051.1dd8f8363f32b5be8331e5372dafb836%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.