Hey all,

I'm trying to write a PR for adding Postgres9.4's "FILTER" syntax for aggregates, but I've hit a bug I can't figure how to fix [and nobody's awake on IRC :)]


Basically, for the query:

        qset = FilterAggParentModel.objects.annotate(
zero_count=FilterAgg(Count('filteraggtestmodel'), Q(filteraggtestmodel__integer_field=1)),

It generates the SQL:

SELECT "postgres_tests_filteraggparentmodel"."id",
COUNT("postgres_tests_filteraggtestmodel"."id") FILTER(WHERE "postgres_tests_filteraggtestmodel"."integer_field" = 0) AS "zero_count",
    COUNT("postgres_tests_filteraggtestmodel"."id") AS "child_count"
FROM "postgres_tests_filteraggparentmodel"
LEFT OUTER JOIN "postgres_tests_filteraggtestmodel" ON ("postgres_tests_filteraggparentmodel"."id" = "postgres_tests_filteraggtestmodel"."parent_id") GROUP BY "postgres_tests_filteraggparentmodel"."id", "postgres_tests_filteraggtestmodel"."integer_field"

The problem being that "postgres_tests_filteraggtestmodel"."integer_field" is included in the GROUP BY clause...

Does anyone who understands this part of the ORM have a suggestion for how to fix this?


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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to