A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/henriquebastos/django-aggregate-if/issues/1 below:

Add support for conditions involving joins with aliases. · Issue #1 · henriquebastos/django-aggregate-if · GitHub

Some queries relabel the table name with an alias, but aggregate-if can't follow it properly.

>>> qs = Book.objects.annotate(
...    mean_age=Avg('authors__age'))
...    mean_age2=Avg('authors__age', only=Q(authors__age__gte=0))
... )
>>> print qs
*** DatabaseError: no such column: aggregation_author.age

The generated query obtained by print books.query is:

SELECT
    "aggregation_book"."id", "aggregation_book"."isbn", 
    "aggregation_book"."name", "aggregation_book"."pages",
    "aggregation_book"."rating", "aggregation_book"."price",
    "aggregation_book"."contact_id", "aggregation_book"."publisher_id", 
    "aggregation_book"."pubdate", AVG(T5."age") AS "mean_age", 
    AVG(CASE WHEN "aggregation_author"."age" >= 0  
             THEN T5."age" ELSE null END) AS "mean_age2" 
FROM 
    "aggregation_book" 
    LEFT OUTER JOIN "aggregation_book_authors" 
        ON ("aggregation_book"."id" = "aggregation_book_authors"."book_id") 
    LEFT OUTER JOIN "aggregation_author" T5 
        ON ("aggregation_book_authors"."author_id" = T5."id") 
GROUP BY 
    "aggregation_book"."id", "aggregation_book"."isbn",
    "aggregation_book"."name", "aggregation_book"."pages", 
    "aggregation_book"."rating", "aggregation_book"."price", 
    "aggregation_book"."contact_id", "aggregation_book"."publisher_id", 
    "aggregation_book"."pubdate";

The problem is that the WHEN expression generated by the only argument is using the table name aggregation_author instead of T5.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4