delete_all with limit

84 views
Skip to first unread message

Isha

unread,
Apr 3, 2014, 2:28:37 PM4/3/14
to rubyonra...@googlegroups.com

Hi,

I was wondering if there is a specific reason why delete_all does not accept limits? Ultimately, I want to achieve batched deletes in my application and something like delete_in_batches or even delete_allthat accepts limits would be useful.

I can try adding this but wanted to get some feedback/suggestions first.

Matt Jones

unread,
Apr 3, 2014, 5:54:47 PM4/3/14
to rubyonra...@googlegroups.com
FWIW, passing a LIMIT clause to a DELETE is included in the SQL92 standard, but actually-implemented support is spotty:

* Postgres: not supported
* Oracle: not supported (but maybe hackable with ROWNUM tricks)
* SQLite3: supported if enabled at compile time
* MySQL: supported
* SQL Server: not supported (but maybe with a TOP subquery?)

—Matt Jones
signature.asc

Mohamed Wael Khobalatte

unread,
Apr 3, 2014, 6:00:02 PM4/3/14
to rubyonra...@googlegroups.com
In addition to Matt's suggestion, there is a usual workaround for this that's achieved by copying all ids in batches to a separate table then joining on it. I guess it's tricky to achieve with Rails given this table dependency. How would you solve it if it proves needed? 
--
Mohamed Wael Khobalatte

Reply all
Reply to author
Forward
0 new messages