From: Ian B. <ia...@co...> - 2004-04-06 02:39:14
|
On Apr 5, 2004, at 3:24 PM, Philippe Normand wrote: > On Sun, Apr 04, 2004 at 04:17:32PM -0500, Ian Bicking wrote: >> On Apr 4, 2004, at 8:33 AM, Philippe Normand wrote: >>> How can I use func.SUM() since it can't reside in where condition ? >>> For COUNT(), there's a way with Table.select().count(). What's the >>> trick for SUM() ? >>> I didn't found any Table.select().sum('attribute') >> >> You can't really use SUM -- it's also left in sqlbuilder from >> sqlbuilder's past life as a general query builder. It would be >> interesting to add that as a method to SelectResults, like count. >> > > Would this patch answer your request ? Looks okay. I'd like to have tests to go with any new code, though. If tests/test.py is too hairy for you, a test in the form of an interactive script will do. Also, it occurs to me that these are all about accumulation -- count, sum, max, min, and no doubt others. It might be nice to generalize this, like SelectResult.accumulate(expression), where sum looks like: def sum(self, column): return self.accumulate(sqlbuilder.func.SUM(column)) ... though sum should probably also for a string column; accumulate doesn't have to check for that -- though if it is passed a string it should interpret it as a SQL expression, so you could do selectResult.accumulate('SUM(a_column)') -- Ian Bicking | ia...@co... | http://blog.ianbicking.org |