On 05/20/2010 10:28 AM, Bryan wrote:
> How about some sort of literal: "table1.col1 * 5" (without the quotes)
> as the value of a bindparam?  So to the bindparam it would look like a
> constant, but when it got to the server, it would be interpreted as an
> expression?  I would be loosing the automatic table/column name
> insertion that SA provides.
>
>   

Bind params don't work like that: you just cannot inject arbitrary SQL
via bind params. You have to include the expression as part of the
update statement itself. The only downside to this approach is you (may)
lose the executemany() behavior you may have been looking for
(executemany is when you pass an array of bind params to execute):

u = table1.update()
u = u.values(col1=5, col2=table1.c.col1 * 5)
engine.execute(u)

If you really need bind params, the best you can do is this, which is
probably not what you want:

u = table1.update()
u = u.values(col1=bindparam('_col1'), col2=table1.c.col1 * bindparam('_col2'))
engine.execute(u, [{'_col1': 5, '_col2': 5}])

I also just noticed that your original example:

u = table1.update()
u.values(col1=bindparam('_col1'), col2=bindparam('_col2') ...

tried to modify the update object in place, but the values() method
returns a new update object instead of modifying the original.

-Conor

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to