Yes, that's the way to do it if the calculations must be done in Python. 
You can only use the direct update method if the database itself can do the 
calculations (via a SQL expression). For example, here is what you can do 
in PostgreSQL: 
http://www.postgresql.org/docs/9.4/static/functions-math.html.

Anthony

On Wednesday, September 30, 2015 at 8:36:48 PM UTC-4, Dave S wrote:
>
>
>
> On Tuesday, September 29, 2015 at 1:25:33 PM UTC-7, Anthony wrote:
>>
>> You can do it in one line - just let the database do the incrementing by 
>> passing an expression in the .update() method:
>>
>> db(db.mytable).update(counter=db.mytable.counter + 1)
>>
>> Much more efficient because you don't have to load any records from the 
>> db or do any processing in Python.
>>
>>
>
> For the fearsome case where some additional python logic was needed to 
> compute the new value, would you use
> newcount = complex_calc(row.count, obtuse_parameters)
> row.update_record(count = newcount)
>
> or can lambda's be used in the db(...).update() call?
>
> /dps
>
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to