On Mon, Mar 16, 2009 at 11:52 AM, koranthala <koranth...@gmail.com> wrote:
> > > > On Mar 16, 8:14 pm, Alex Gaynor <alex.gay...@gmail.com> wrote: > > On Mon, Mar 16, 2009 at 11:07 AM, koranthala <koranth...@gmail.com> > wrote: > > > > > Hi, > > > I downloaded Django 1.1 due to aggregation support. > > > But I am facing one issue which I cannot seem to overcome. > > > I have two fields which represents two different times. > > > I want to get the sum of difference of times - and I am unable to > > > do so. > > > Basically, I want to do as follows: > > > SELECT SUM (time2 - time1) FROM _TABLE_ WHERE __XXX___ > > > > > I tried 2 options: > > > 1. self.filter( XXX).aggregate(diff=Sum('time2 - time1')) > > > 2. self.filter (XXX).aggregate(t2=Sum('time2'), t1= Sum('time1')) - so > > > that I can do t2 - t1 later. > > > > > Both is not supported in Django. I have raw SQL code in model > > > Manager for the same. I thought using Django Aggregation is better. Is > > > such operations going to be supported in Django 1.1 ? > > > > > Regards > > > Koran > > > > Right now that isn't possible, is there any reason you couldn't just > bring > > the seperate SUMs into python and do the subtraction there, I realize it > > isn't quite as clean but the overhead should be minimal? > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > If I understand correctly: > Separate SUMs as in the 2nd option which I mentioned above? > It was not possible because currently aggregation methods does not > support SUM - I think because Python itself does not support SUM of > datetime objects. > > Or was it: > Separate SUM as in bring all the tuples to Python and then calculate? > It is quite big because there are more than 1 Million tuples so I dont > want to bring everything to Python. > > Please let me know whether I have understood correctly. > > > Sorry, I missed that these were dates/times. Right now there isn't complete support for aggregating on dates/times. I think here the easiest route is just to do: self.extra(select={'diff': "SUM(field1-field2"}).values('diff') Which I believe will work. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---