Reputation: 461
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?
Upvotes: 2
Views: 1527
Reputation: 26235
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)
Upvotes: 4
Reputation: 170856
SQL does not have support for LIMIT. So NO, is not possible to do this.
Upvotes: 0