Today I ran into an issue where using distinct() and values() on a
queryset where the model had default ordering would return apparently
non-distinct results.  After searching, I found 
http://code.djangoproject.com/ticket/9186
which indicates that this is now correct behaviour.  It took me a long
time to discover what was wrong, however, because the queryset's
_as_sql() method didn't show the the extra field that the default
ordering caused to be selected.  For example (expanding on the example
in that ticket), if I call:

{{{ PbxRecord.objects.values('extension').distinct()._as_sql() }}}

I'd get back this sql:

{{{ ('SELECT DISTINCT `datastore_pbxrecord`.`extension` FROM
`datastore_pbxrecord`', ()) }}}

And not the actual sql that will be executed when the queryset is
evaluated:

{{{ SELECT DISTINCT `datastore_pbxrecord`.`extension`,
`datastore_pbxrecord`.`id` FROM `datastore_pbxrecord` ORDER BY
`datastore_pbxrecord`.`id` ASC }}}

Why does _as_sql() not return the actual sql that will be executed?
Is there any way to obtain the real SQL that a queryset will use?
Although I only use _as_sql() for debugging, it'd be nice to know that
it is reliable.

Andrew.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to