Re: Conditional aggregations.

2011-06-29 Thread Cal Leeming [Simplicity Media Ltd]
Excellent work on this akaariai! I think the best way I could help with this ticket, would be to use it in development in our future branch over the next few months with some of our complex reporting systems. Absolutely packed with work at the moment, so this would be in the next 2 - 3 months. Eit

Re: Conditional aggregations.

2011-06-29 Thread Jeremy Dunck
On Wed, Jun 29, 2011 at 3:55 PM, Simon Riggs wrote: ... > I'm not sure I like your ORM syntax to generate that though. Why not > just pass through the case statement directly? That way *any* legal > CASE statement can be used, without inventing new ORM syntax each > time. Tables get aliased depen

Re: Conditional aggregations.

2011-06-29 Thread Simon Riggs
On Wed, Jun 29, 2011 at 9:27 PM, akaariai wrote: > On Jun 28, 5:46 pm, Javier Guerra Giraldez wrote: >> i might be totally wrong (wouldn't be first time..) but i've found >> myself having to adapt to local dialects almost every time i see some >> SQL inside a function, especially on mysql and sql

Re: Conditional aggregations.

2011-06-29 Thread akaariai
On Jun 28, 5:46 pm, Javier Guerra Giraldez wrote: > i might be totally wrong (wouldn't be first time..) but i've found > myself having to adapt to local dialects almost every time i see some > SQL inside a function, especially on mysql and sqlite.   maybe it's > because of the bad quality of code

Re: Conditional aggregations.

2011-06-28 Thread Javier Guerra Giraldez
On Tue, Jun 28, 2011 at 9:26 AM, akaariai wrote: >> this looks quite non-portable > > How? The CASE statement is specified in SQL standard, and it is > implemented in all database I have used. i might be totally wrong (wouldn't be first time..) but i've found myself having to adapt to local diale

Re: Conditional aggregations.

2011-06-28 Thread akaariai
On Jun 28, 5:18 pm, Javier Guerra Giraldez wrote: > On Tue, Jun 28, 2011 at 8:41 AM, akaariai wrote: > > This should translate to the following SQL: > > SELECT sum(case when house.price > 41000 and house.price < 43000 then > > 1 else 0 end) as expensive_house, > >       sum(case when house.price

Re: Conditional aggregations.

2011-06-28 Thread Javier Guerra Giraldez
On Tue, Jun 28, 2011 at 8:41 AM, akaariai wrote: > This should translate to the following SQL: > SELECT sum(case when house.price > 41000 and house.price < 43000 then > 1 else 0 end) as expensive_house, >       sum(case when house.price > 43000 then 1 else 0 end) as > really_expensive_house, ... >

Re: Conditional aggregations.

2011-06-28 Thread akaariai
On Jun 27, 4:54 pm, Russell Keith-Magee wrote: > > queryset.aggregate( > >    expensive_house=Count(house__price, > > only=(Q(house__price__gt=41000), Q(house__price__lt=43000))), > >    ... > >    ) > > Ok, so that's you're syntax proposal. Now show me the SQL that this > translates into. In part

Re: Conditional aggregations.

2011-06-27 Thread Russell Keith-Magee
On Fri, Jun 24, 2011 at 11:54 PM, stan wrote: > This topic is discussed on the Ticket #11305 : > https://code.djangoproject.com/ticket/11305 > > Like many folks, I am hit by the scenario where a relative simple > query become a design decision because my «boss» asked me : "Hey Stan, > can you add

Conditional aggregations.

2011-06-24 Thread stan
This topic is discussed on the Ticket #11305 : https://code.djangoproject.com/ticket/11305 Like many folks, I am hit by the scenario where a relative simple query become a design decision because my «boss» asked me : "Hey Stan, can you add me a column with the number of valid items in each catego