Stefan Weiss February 2016

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?

Answers


sorin February 2016

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


coleifer February 2016

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)

Post Status

Asked in February 2016
Viewed 1,374 times
Voted 13
Answered 2 times

Search




Leave an answer