Skip to content Skip to sidebar Skip to footer

Sqlalchemy Raw Sql Vs Expression Language Statements

When inserting multiple rows in a MySQL-DB via a SQLA-Expression-Language statement, f.e. Foo.__table__.insert().execute([{'bar': 1}, {'bar': 2}, {'bar': 3}]) it´s extremly slow,

Solution 1:

It seems that the special INSERT with multiple values only became recently supported(0.8 unreleased), you can see the note at the bottom of this section regarding the difference between executemany(what execute with a list does) and a multiple-VALUES INSERT:

http://docs.sqlalchemy.org/ru/latest/core/expression_api.html#sqlalchemy.sql.expression.Insert.values

This should explain the performance difference you see. You could try installing the development version and repeating the tests with the altered calling syntax, mentioned in the link, to confirm.

Post a Comment for "Sqlalchemy Raw Sql Vs Expression Language Statements"