Great, i believe it clarifies a lot of misunderstanding from my
side :-).

Basically, correct me if am wrong:
- the query is only evaluated at the time of the "select".
- we can create "query" object for both parts of the query and
assemble them and they 'll be evaluated at the time of the "select"
- when we create such "query" object in the select part, the result
for each row can be accessed using the query object (because the query
object is automatically evaluated to a string that is the key to the
storage of the value in the row dictionnary)
- there was no chance for any of my attempt to work,because it was too
late (first() condition on a query already evaluated...)

I start to love web2py :-)

On 30 nov, 20:27, Carlos Hanson <[email protected]> wrote:
> It is probably useful to see the following as well:
>
> >>> sum = db.operations.amount.sum().coalesce_zero()
> >>> sum
>
> <gluon.dal.Expression object at 0x12e68d0>>>> print sum
>
> COALESCE(SUM(operations.amount),0)
>
> >>> monthly_amount_first = db((db.operations.date.year()==current_year) &
>
> ...                           (db.operations.date.month()==current_month)
> ...                          ).select(sum).first()>>> monthly_amount_first
>
> <Row {'_extra': <Row {'COALESCE(SUM(operations.amount),0)': 45.0}>}>>>> 
> monthly_amount_first[sum]
>
> 45.0

Reply via email to