Thursday, May 30, 2013

Re: Is it possible to add SQL comments to a query built with the ORM?

There is no public API way. You can likely do this with .extra():
Object.objects.filter(Q(pub_date__lte=datetime.now)).extra(where=['1=1 /
* query no. 123 */'])

- Anssi

On 30 touko, 12:42, Timo Josten <t...@mkswap.net> wrote:
> Hint: This is a cross-post fromhttp://stackoverflow.com/questions/16831162/is-it-possible-to-add-sql...
>
> I am trying to identify slow querys in a large-scale Django 1.3 web
> application. As it is kind of difficult to match the raw sql query in the
> slow query log with the specific ORM statement in the code, I wondered if
> it is possible to add a SQL comment to the query constructed with the ORM,
> something like..
>
> > Object.objects.filter(Q(pub_date__lte=datetime.now)).comment('query no.
> > 123')
>
> Kind regards
> Timo

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment