简体   繁体   中英

Peewee: delete with limit

I have a (very) large table mit >100M rows. I want to delete 1M rows with some condition without running in any table lock or timeout issue. IMO delete with limit is best choice in this case. I'm trying to find a peewee equivalent for a simple sql query

DELETE FROM users WHERE condition=1 LIMIT 10

My first approach is:

Users.delete().where(condition=10).limit(10)

but DeleteQuery doesn't have a limit method. oops...

So, what is best practice to delete a huge number of rows with peewee?

If you want delete with limit, then just use a subquery:

users_to_delete = User.select().where(...).limit(10)
Users.delete().where(User.id << users_to_delete)

SQL does not have support for LIMIT. So NO, is not possible to do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM