Quote aggregate alias in order by
|Reported by:||David Elias||Owned by:|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||no|
Running the aggregation tests gives an error against Firebird database.
>>> qs = Book.objects.values_list('price').annotate(count=Count('price')).order_by('-count', 'price')
Produces the following sql:
SELECT "AGGREGATION_BOOK"."PRICE", COUNT("AGGREGATION_BOOK"."PRICE") AS "COUNT" FROM "AGGREGATION_BOOK" GROUP BY "AGGREGATION_BOOK"."PRICE" ORDER BY count DESC, "AGGREGATION_BOOK"."PRICE" ASC
count in order by clause is not quoted and clashed with reserved the corresponding reserved word.
Tested the patch against MySQL and SQLite.
Change History (7)
comment:1 Changed 7 years ago by
|Triage Stage:||Unreviewed → Accepted|