#27719: Add queryset.alias() to mimic .annotate() for aggregations without loading data -------------------------------------+------------------------------------- Reporter: Marc Tamlyn | Owner: nobody Type: New feature | Status: new Component: Database layer | Version: master (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Josh Smeaton): I'm kind of on the fence with this. The 90% case is expressions in WHERE clauses. We **need** expression support in filter/exclude, including the ability to filter without a left-hand-side (column reference) for things such as EXISTS( subq ). Having `alias()` feels like a fairly big hack. Let's look at your list of example usages of aliases: .filter(name__lookup=value) - Yes, Yes, Yes. But solved by expressions-in- filters. .order_by('name') - Already supports expressions .annotate(SomeOtherExpression('name')) - Already supported. .values('name') (and related APIs)` - If you want the values, then it's already in the select list and should be kept there. But expressions in values works now, no? .distinct() - Already in the select list, refer by name. .date() (and datetimes) - unsure about this, fairly uncommon? .defer('name') (and only) - it's already in the select list Out of all of the above, except for `filter` we always want the expression in the select list anyway. And when we use defer, we still want it in the annotations list so we can use it later (I think). Am I missing something? The only time you might not want the value in the select list is if you're running a filter and possibly an order by. **maybe** an annotation over another expression where the other expression shouldn't be selected, but I feel that'd be a very small set of users, just to avoid creating two objects that are effectively the same. -- Ticket URL: <https://code.djangoproject.com/ticket/27719#comment:5> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.b916ab565d520cab8f2e168608345181%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.