Thanks both of you for your replies.  I've been trying to avoid doing
it in python (lots of records) so I think I'll try mr.freeze's
solution.

On Mar 25, 5:18 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> hrm...
>
> for row in db(db.person.id > 0).select():
>    row.update_record(name = row.name + "x")
>
> This also will work, although not as efficient since the processing
> will be done in python and not the database.
>
> -Thadeus
>
> On Wed, Mar 24, 2010 at 11:10 PM, mr.freeze <nat...@freezable.com> wrote:
> > This is ugly but should work:
>
> > from gluon.sql import Expression
> > db(db.person.id>0).update(name = Expression('person.name || "x"'))
>
> > I'm almost positive there is a better way.
>
> > On Mar 24, 10:43 pm, Russell <russell.mcmur...@gmail.com> wrote:
> >> A bigger problem...
>
> >> On further testing, it looks like db(db.person.id>0).update(name =
> >> db.person.name + "x")  does NOT work.
>
> >> The DAL seems to treat this as an integer addition and the field is
> >> updated to 0 (at least on sqlite).
>
> >> On Mar 25, 4:11 pm, Russell <russell.mcmur...@gmail.com> wrote:
>
> >> > Thanks very much for the reply.
>
> >> > Sorry to say that it doesn't work.  Your answer gives this...
> >> > "UPDATE person SET name='xSUBSTR(person.name,1,(1 - 0))';"
>
> >> > On Mar 25, 3:58 pm, "mr.freeze" <nat...@freezable.com> wrote:
>
> >> > > Whoops, backwards:
> >> > > db(db.person.id>0).update(name = "%s%s" % ("x",db.person.name))
>
> >> > > On Mar 24, 9:57 pm, "mr.freeze" <nat...@freezable.com> wrote:
>
> >> > > > Try this:
> >> > > > db(db.person.id>0).update(name = "%s%s" % (db.person.name,"x"))
>
> >> > > > On Mar 24, 9:52 pm, Russell <russell.mcmur...@gmail.com> wrote:
>
> >> > > > > Hi there,
>
> >> > > > > I'm trying to prepend a string to a field.  While, this works:
>
> >> > > > > >>> db(db.person.id>0).update(name = db.person.name + "x")
>
> >> > > > > This does not:
>
> >> > > > > >>> db(db.person.id>0).update(name = "x" + db.person.name)
>
> >> > > > > Traceback (most recent call last):
> >> > > > >   File "<string>", line 1, in <fragment>
> >> > > > > TypeError: cannot concatenate 'str' and 'Expression' objects
>
> >> > > > > I have found a work-around, but it is pretty ugly:
>
> >> > > > > >>> db(db.person.id>0).update(name = db.person.name[0:0] + "x" + 
> >> > > > > >>> db.person.name)
>
> >> > > > > Does anyone have a better solution?
>
> >> > > > > 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 
> > athttp://groups.google.com/group/web2py?hl=en.

-- 
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.

Reply via email to