On Sep 30, 2008, at 5:52 PM, Jack Stahl wrote:

>
> Hello all,
>
> I'd like to use SQL Alchemy to do a single insert with multiple
> values , such as:
>
> INSERT INTO foobar (foo, bar) VALUES ('value1', 0), ('value2', 1);
>
> I've found a few ways to do this using a SQLAlchemy connection /
> the .execute() method on the Insert object.
> However, my problem is that my system is designed such that I
> compiling queries and executing them through my own MySQL cursor
> query.compile():
>
> query = table.table.insert(values=values).compile()
> cursor.execute(str(query), query.params)
>
> Is there support for multiple values in compiled query objects?  It
> appeared that I could somehow use compile bind parameters to support,
> but my efforts were futile.

well, you might have noticed that saying table.insert(values={dict})  
does create a statement with bind parameters.  While the query.params  
member specifically assumes a single set of params, you can execute  
with a list of params that override whatever you put in values, i.e.:

i = t.insert().values(x="dummy")
cursor.executemany(str(i), [{'x':'foo'}, {'x':'bar'}, ...])

to control the bind parameter generation more formally, use bindparam():

i = t.insert().values(x=bindparam('x'), y=bindparam('y'))

but as far as bundling the "many" params with the SQL construct, you'd  
have to roll that part yourself.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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