Hi all,

I'm looking to get the sum of a column. I've seen plenty of examples
which illustrate using a QuerySet's extra(select={'foo': 'sum(bar)'})
method, but my Postgres pukes on that:

ERROR:  column "app_model.id" must appear in the GROUP BY clause or be
used in an aggregate function

After messing about I figured out that's because Django is asking for
every field in the table. If it would only ask for sum(bar), it'd work
great. So I need to override the QuerySet's SELECT statement... So,
write a custom Manager! Except that when I'm ready to ask for the sum,
I've spent a bunch of time filter()ing a QuerySet. And I'd like to use
all the QuerySet's built-in intelligence about the WHERE clause, the
table, etc., and I haven't seen how to make a Manager that modifies the
SELECT statement, but leaves the rest of the functionality there.

Any help would be much appreciated.

Thanks,

Steve

P.S. Tangent: getting distinct values by doing...

[k['field'] for k in q.values('field').distinct()]

...sure is ugly. I know there's been work on getting aggregation going
since early last year, but isn't there a place for a simple function
(that won't take years to get into trunk) like, say, distinct('field')?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to