On 12/4/06 3:30 PM, DavidA wrote: > I think it quickly gets more complicated than that syntax would > support.
Oh, of *course* it does -- that's why I want to discuss it more! I think, though, that we should be able to find a 80/20 point for aggregates and support most of the common use cases. That's pretty consistent with the rest of Django's ORM: we don't try to model *everything* you can do with SQL, just most of the common stuff. I'm totally OK with making complex queries be written in SQL; it actually turns out that SQL's a really good language for handing lots of data :) As long as the syntax is nice, it seems that any aggregate support would be better than none. > For example, how would you ask for more than one aggregate > value in that syntax? My common use case is grouping a bunch of > financial positions, where the SQL would look something like: > > select account, count(*), sum(quantity), sum(total_pnl) from > position > group by account > > Would I have to call queryset.groupby(account) three times: once for > count(), once for sum(quantity) and once for sum(total_pnl)? My gut would be that that particular case wouldn't be supported, but:: quantity, total_pnl = Position.objects.groupby("account").sum("quantity", "total_pnl") would work. So maybe you can only do one aggregate operation at once? That seems to mesh OK with the majority of aggregate usage *I* do... > And what exactly does queryset.groupby() return? I was thinking it would return some proxy object that supports .sum(), .avg(), etc. methods. By itself I don't think it would be very useful. > 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. I don't think I follow here - can you give me an idea of what you're talking about? > But I don't know how complicated that would be and I haven't thought of > a syntax that works nicely for the more complex cases. Again, I'm OK with just supporting the simple-ish cases if that's all we can work out. Jacob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---