Thank you! I think I get it now, I was applying the func.sum to the wrong part. This is what I needed: qty = Session.query(model.Y).filter(model.Y.id_X==x.id).value(unc.sum (model.Y.change))
On Dec 10, 3:20 pm, Michael Bayer <[email protected]> wrote: > On Dec 10, 2009, at 5:05 PM, dw wrote: > > > > > I'm trying to port my project from ver 0.4 to ver 0.5 and I can't seem > > to figure out how to implement the new sum functions. Here's a > > simplified version of my model: > > object X: > > id, > > description > > > object Y: (transactions of object X) > > id, > > id_X, > > change > > > (this is basically an inventory system) > > > To find out the current number of X's I have I was running this under > > 0.4: > > qty = Session.query(model.Y).filter(model.Y.id_X==x.id).sum > > (model.Y.change) > > > This returned a float of how many X's there were. With 0.5, the best > > I can do is: > > qty = Session.query(func.sum(model.Y.change)).filter > > (model.Y.id_X==x.id).all() > > > The problem here is it's returning a list containing a single tuple > > containing a decimal of my result. I'd like to get just the result > > without having to do something ugly like qty = qty[0][0] every time. > > > My SQL is pretty lacking so I'm sure I'm missing something. Any > > advice is much appreciated. Thanks. > > try query.value(func.sum(col)) - will return a scalar result. > > > > > -- > > > You received this message because you are subscribed to the Google Groups > > "sqlalchemy" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
