This is more a question of understanding how things work than a issue
I'm working with Django 1.9 and Oracle 12 and python 3.4
I have a model Resources
When I do the following query to find all the uid's from matching resources
in the Django shell
* Resources.objects.filter(remote_source=source.pk).values_list('uid')*
I get the following SQL:
DEBUG (0.002) QUERY = 'SELECT * FROM (SELECT "_SUB".*, ROWNUM AS "_RN" FROM
(SELECT "DATA_MASTER"."RESOURCES"."UID" AS Col1 FROM
"DATA_MASTER"."RESOURCES" WHERE
"DATA_MASTER"."RESOURCES"."REMOTE_SOURCE_ID" = :arg0) "_SUB" WHERE ROWNUM
<= 21) WHERE "_RN" > 0' - PARAMS = ('6�mbe�$��S]�\x03\n\x0f�',);
args=(b'6\xcbmbe\xac$\xe7\xe0S]\x99\x03\n\x0f\xce',)
A list of tuples is returned as expected.
However, when I do the same query, but now in a list comprehension to parse
out the uid field I get a different (more optimized) query.
[ x[0] for x in
*Resources.objects.filter(remote_source=a.pk).values_list('uid')* if x[0] ]
DEBUG (0.100) QUERY = 'SELECT "DATA_MASTER"."RESOURCES"."UID" FROM
"DATA_MASTER"."RESOURCES" WHERE
"DATA_MASTER"."RESOURCES"."REMOTE_SOURCE_ID" = :arg0' - PARAMS =
('6�mbe�$��S]�\x03\n\x0f�',);
args=(b'6\xcbmbe\xac$\xe7\xe0S]\x99\x03\n\x0f\xce',)
my question is : why do I get a SELECT * FROM in the first situation and
why a SELECT "DATA_MASTER"."RESOURCES"."UID"
in the second situation. I would expect the SELECT <field> query always in
a values_list query. i.e. how does the django orm know it lives inside the
list comprehension.?
BTW, on PostgreSQL I always get the SELECT <field> query, regardless of the
context.
Cheers Div
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" 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].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/f8ca9a22-2593-49f9-b28a-f9234ded3cb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.