开发者

How to bulk insert data to mysql with python

开发者 https://www.devze.com 2023-01-18 19:33 出处:网络
Currently i\'m using Alchemy as a ORM, and I look for a way to speed up my insert operation, I have bundle of XML files to import

Currently i'm using Alchemy as a ORM, and I look for a way to speed up my insert operation, I have bundle of XML files to import

for name in names:
    p=Product()
    p.name="xxx"
    sessio开发者_开发技巧n.commit()

i use above code to insert my data paser from batch xml file to mysql,it's very slow also i tried to

for name in names:
    p=Product()
    p.name="xxx"
session.commit()

but it seems didn't change anything


You could bypass the ORM for the insertion operation and use the SQL Expression generator instead.

Something like:

conn.execute(Product.insert(), [dict(name=name) for name in names])

That should create a single statement to do your inserting.

That example was taken from lower down the same page.

(I'd be interested to know what speedup you got from that)

0

精彩评论

暂无评论...
验证码 换一张
取 消