John Lenton wrote:
>
> I hadn't even considered having a multi-parameter tuple-returning
> "sum"; I was ok with either calling groupby thrice, or saving the
> groupby and calling the different ops in sequence. In either case, a
> database roundtrip per call.

I'm often grouping thousands of rows for my cases so doing multiple
round trips per field would be painful.

> I had thought that queryset.groupby should behave in the same way
> itertools.groupby would behave, i.e. that there would only be
> implementation (and performance) differences between
>
> queryset = Position.objects.filter(date=today)
> account_summary = itertools.groupby(queryset, operator.attrgetter('account'))
>
> and
>
> account_summary = Position.objects.filter(date=today).groupby('account')

I'm confused. Where do you specify the aggregate functions for
aggregating the specific columns (sum, avg, etc.)? Or am I
misunderstanding what this does?

> in view of the above: no. To do the above, you'd do this instead:
>
> for account, positions in account_summary:
>    print account.name

I see. Works for me.

>
> > And how would I dereference the aggregate fields in the groupby
> > results? By index? (is account_summary[0][2] the quantity sum of the
> > first account summary row?)
>
> positions would be the (lazy) iterator for that purpose, already set
> up for you (by this I mean, I don't expect it to be a performance
> gain, just a convenience).

But would there be aliases for these aggregate expessions? That is, the
equivalent of

   select sum(quantity) as tot_quantity ...


> > My idea was a queryset.groupby() could return some sort of dynamic
> > Django model class where the attributes where the aggregated fields
> > plus the fields you were grouping by and if you were grouping by a
> > relation field, it would magically work like any other model relation.
> 
> that sounds way too magic for my taste :)

True.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to