How do I perform a batch insert in Django?

前端 未结 5 1681
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 20:12

In mysql, you can insert multiple rows to a table in one query for n > 0:

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9), ..., (n-2, n-1, n);
         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 20:51

    You might get the performance you need by doing manual transactions. What this will allow you to do is to create all the inserts in one transaction, then commit the transaction all at once. Hopefully this will help you: http://docs.djangoproject.com/en/dev/topics/db/transactions/

提交回复
热议问题