Tuesday, July 30, 2013

Re: .filter() and .exclude() don't add up

On Tuesday, July 30, 2013 6:26:47 PM UTC+3, Daniele Procida wrote:
On Mon, Jul 29, 2013, akaariai <akaa...@gmail.com> wrote:

>> I understood that part. But by "more general" I mean one that will work
>> for any case, without having to know where the Nulls might be.
>> So given queryset A, and its subset queryset B, we can place B against A
>> and obtain its complement.
>> Or to put it another way: give me all the items in A that are not in B.
>You can do this with a subquery in Django. non_red_things =
>queryset.exclude(pk__in=red_things). If this performs well is a different

It seems to take about twice as long to execute, so no, it doesn't perform very well.

>I think that in SQL one can use WHERE (original_condition) is not true;
>which will match both unknown (null comparison's result) and false in the
>original condition.

But this isn't available as a Django query, without using raw SQL?

No it isn't. Writing a patch that adds QuerySet.negate() operation would be fairly straightforward. If such an operation will be accepted to Django is a different question. In my opinion the main question is if queries written as "WHERE (original_condition) is not true" will perform well enough. If not, then adding the operation isn't a good idea, but if it generally performs well, then addition of it seems like a good idea to me.

 - Anssi

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.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment