您当前的位置: 首页 >  彭世瑜 ar

peewee.OperationalError: too many SQL variables

彭世瑜 发布时间:2018-12-10 11:02:08 ,浏览量:3

使用peewee+sqlite批量插入数据报错

peewee.OperationalError: too many SQL variables

sqlite 每次插入有数量限制,不能插入太多,资料显示999,不过我设置为500就报错了

peewee提供了一个方式,分次插入,两种方式等价

from peewee import chunked

# Insert rows 100 at a time.
with db.atomic():
    for idx in range(0, len(data_source), 100):
        MyModel.insert_many(data_source[idx:idx+100]).execute()
        
# Insert rows 100 at a time.
with db.atomic():
    for batch in chunked(data_source, 100):
        MyModel.insert_many(batch).execute()

参考:

  1. How to increase SQLITE_MAX_VARIABLE_NUMBER at compilation-time?
  2. http://docs.peewee-orm.com/en/latest/peewee/querying.html#bulk-inserts
关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 3浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0759s