Thanks mr.freeze, that's got it. And so obvious too. >>>db(db.products.id>0)._update(product_code=db.products.product_code[:2]) "UPDATE products SET product_code=SUBSTR(product_code,1,(2 - 0))"
I guess my question was mainly about the SQL scalar functions supported by web2py, and the syntax for using them. For the record, web2py DAL supports: upper(), lower(), len(), and slicing. But not strip() or replace(). On Mar 17, 3:09 am, "mr.freeze" <nat...@freezable.com> wrote: > It will be faster if the update is performed on the set (without > selecting each one): > > db(db.products.id>0).update(product_code=db.products.product_code[:2]) > > You can do _update to see what SQL will be generated. > > On Mar 16, 6:12 am, selecta <gr...@delarue-berlin.de> wrote: > > > for p in db(db.products.id>0).select(): > > p.update(product_name = 'Tiger Woods') > > > or > > > [p.update(product_name = 'Tiger Woods') for p in > > db(db.products.id>0).select()] > > > On Mar 16, 12:06 pm, Russell <russell.mcmur...@gmail.com> wrote: > > > > Hi, > > > > I'm trying to update some text fields in a database. In SQL I would > > > do something like this... > > > > UPDATE products SET product_code=substr(product_code,2); > > > > or even... > > > > UPDATE products SET product_name = replace(product_name, 'Tiger', > > > 'Woods'); > > > > Does anyone have an example of how to do this with the DAL? > > > > Thanks > > > Russell -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.