Thanks for the as_sql() function as can now can
see the SQL detail. Which reveals a problem in
getting DISTINCT to draw from a fields or fields that can in fact
return the unique result of the query. Perhaps it is my usage
of the function so I'm listing an examble
below.

To further simplify my example and testing I'm  using an internal
product number that in this instance refers to all editions of the
book Moby Dick by Herman Melville.

qset = (Q(editionid__contains=q_bookid))

results = Titles.objects.filter(qset).order_by().distinct()
assert False, resultsa.query.as_sql()

Here is the SQL it generates results...

('SELECT DISTINCT "books_titles"."id", "books_titles"."keywords",
"books_titles"."editionid", "books_titles"."author",
"books_titles"."title", "books_titles"."price",
"books_titles"."bookid" FROM "books_titles" WHERE
"books_titles"."author"::text LIKE %s ', (u'%842838%',))

Now with the above if I read correctly the DISTINCT is being placed on
book_titles.id
which of course will always be unique and
always return every instance, which does not  return a unique list.

So for output I get something like...

EditionId BookID Author    Title
========= ====== ========= =====================
2001      200    Melville  Moby does Captain Bly
2002      200    Melville  Moby does Captain Bly
2004      200    Melville  Moby does Captain Bly

When in fact all I need for the seeding the
initial search results is

EditionId BookID Author    Title
========= ====== ========= =====================
2001      200    Melville  Moby does Captain Bly

At least now though the SQL is explicit
and I can perhaps dig a bit into the code
to see how it works, but if anyone can offer
any further insights it would be of great
help.

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

Reply via email to