Hi,
I was using sum() to calculate the amount of donations received in (
http://natalanimal.com.br/init/default/extrato), but I've found a limit
problem, I don't know if it is a PostgreSQL limit or sum() expression limit.
*
*
*#----FIRST WAY, USING SUM()*
In my model I have a field "db.donation.total" for each donation, to
calculate this I did:
sum = db.donation.total.sum()
total = db(db.donation.id>0).select(sum)
I got total as Rows object which has a key "SUM(donation.total)" inside
_extra field as <Row {'_extra': <Row {'SUM(donation.total)': 515.0}>}>
In this case it is returning *515.0* as result.
*#---SECOND WAY LOOPING THROUGHT THE TABLE*
Now I will make the same operation looping throught the values
rows = db(db.donation.id>0).select()
total = float(0)
for row in rows: total += row.total
In this case it is returning *590.0* as result
*#---MY CONCLUSION*
I figured out that the first way using sum() is limiting the rows of the
sum, in this example sum() is considering only 35 rows when I have 41 rows.
why this is missing 6 rows in this case? I tried lot of times with the same
result set.
Thanks
--
Bruno Rocha
http://about.me/rochacbruno/bio