Opened 16 years ago

Closed 16 years ago

Last modified 12 years ago

#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 miracle2k, 16 years ago

Summary: Query.group_by behaviour no longer supports MySQL specific behaviourQuery.group_by no longer supports MySQL specific behaviour

comment:2 by Russell Keith-Magee, 16 years ago

Resolution: wontfix
Status: newclosed

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.

comment:3 by Anssi Kääriäinen, 12 years ago

Component: ORM aggregationDatabase layer (models, ORM)
Note: See TracTickets for help on using tickets.
Back to Top