Home Ask Login Register

Developers Planet

Your answer is one click away!

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:


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

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


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


Leave an answer

Quote of the day: live life