Bulk insert with SQLAlchemy ORM

前端 未结 10 1116
刺人心
刺人心 2020-11-30 17:15

Is there any way to get SQLAlchemy to do a bulk insert rather than inserting each individual object. i.e.,

doing:

INSERT INTO `foo` (`bar`) VALUES (1         


        
10条回答
  •  我在风中等你
    2020-11-30 18:08

    Direct support was added to SQLAlchemy as of version 0.8

    As per the docs, connection.execute(table.insert().values(data)) should do the trick. (Note that this is not the same as connection.execute(table.insert(), data) which results in many individual row inserts via a call to executemany). On anything but a local connection the difference in performance can be enormous.

提交回复
热议问题