#11090 closed (wontfix)
Query.group_by no longer supports MySQL specific behaviour
Reported by: | miracle2k | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I used to be able to do:
qs = Model.objects.extra(select={'foo': 'custom_aggregate()'}, tables=['table']) qs.query.group_by = ['table.column']
This generated a query like:
SELECT model.a, model.b, custom_aggregate() AS foo FROM model, table GROUP BY table.column
As far as I understand, this is exploiting MySQL specific behaviour that supports collapsing multiple values within a group into a single return row, rather than enforcing every column to be either listed in GROUP BY, or be an aggregate, as Postgre does, for example.
Now, with the changes from r9805 and later also r9838, when using any kind of group_by value at all, the resulting query will actually list all select, select_related and extra_select fields in the GROUP BY clause, meaning my query is now:
SELECT model.a, model.b, custom_aggregate() AS foo FROM model, table GROUP BY table.column, model.a, model.b, foo
I realize that group_by is internal API and Django may not want to support this at all, but in case the change was unintentional, I thought I'd bring it up.
Change History (3)
comment:1 by , 15 years ago
Summary: | Query.group_by behaviour no longer supports MySQL specific behaviour → Query.group_by no longer supports MySQL specific behaviour |
---|
comment:2 by , 15 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:3 by , 12 years ago
Component: | ORM aggregation → Database layer (models, ORM) |
---|
The change was intentional, and was necessary to implement aggregates. As you noted - group_by is a Django internal, and backwards incompatibility is in no way guaranteed.