Opened 16 years ago
Last modified 12 years ago
#10132 closed
Aggregations add extra values to ValuesQuerySets — at Version 1
Reported by: | Glenn Maynard | 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 (last modified by )
From http://groups.google.com/group/django-users/browse_frm/thread/15b3c24dddd2a2d5/2214eba4328126ca
Item.objects.extra(select={"note_alias": "note"}).values("note_alias").annotate(Count("id")).order_by('note_id')
generates:
SELECT (note_id) AS "note_alias", U0."id", COUNT("queries_item"."id") AS "id__count" FROM "queries_item" U0 GROUP BY "queries_item"."id", "queries_item"."name", "queries_item"."created", "queries_item"."modified", "queries_item"."creator_id", "queries_item"."note_id"
but should (possibly) generate:
SELECT (note_id) AS "note_alias", COUNT("queries_item"."id") AS "id__count" FROM queries_item GROUP BY note_alias ORDER BY note_id
Change History (2)
comment:1 by , 16 years ago
Description: | modified (diff) |
---|---|
Summary: | QuerySet values() should work on extra(select) fields → Aggregations add extra values to ValuesQuerySets |
by , 16 years ago
Attachment: | 10132-test.diff added |
---|
Note:
See TracTickets
for help on using tickets.
Fixed description formatting.
Also changed the title to reflect the problem. The
extra()
andvalues()
methods already work together. It's only the final call to add aggregation in that is triggering this.