What is an efficient way of inserting thousands of records into an SQLite table using Django?

后端 未结 9 764
暖寄归人
暖寄归人 2020-11-30 17:41

I have to insert 8000+ records into a SQLite database using Django\'s ORM. This operation needs to be run as a cronjob about once per minute.
At the moment I\'m using a

9条回答
  •  抹茶落季
    2020-11-30 18:23

    I recommend using plain SQL (not ORM) you can insert multiple rows with a single insert:

    insert into A select from B;
    

    The select from B portion of your sql could be as complicated as you want it to get as long as the results match the columns in table A and there are no constraint conflicts.

提交回复
热议问题