update_all
generates one SQL query to run - it cannot do smart things, such as changing arbitrary ruby ββbits to equivalent SQL.
You need to download all instances (e.g. via find_each
) and fix them one at a time (i.e. don't use update_all), e.g.
Foo.find_each do |foo|
Or find a way to express this cleanup operation in SQL. For example, Postgres has a regexp_replace
function regexp_replace
Foo.update_all("some_column = regexp_replace(some_column, 'your_regexp_here', '','g')")
To remove everything, replacing this regular expression. Obviously, you need to check the documentation for your database to see if it supports such a function.
source share