I have a table with an column "Ip" all has the values like 10.x.x.x, now I want to replace the 10 with 20 of all the records. Is their any way to do this via Activerecord or Do I need to execute only raw postgres query with regexp_replace?
How to update all the values of an column with regular expression in Rails 4
ModelName.update_all("column_name = replace(columnname,'originaltext','replacement') ")
Eg:
Resource.update_all("fqdn = replace(fqdn,'d3p5','d6p6') ")
Now all the occurrences of "d3p5" of fqdn column replaced with d6p6
© 2022 - 2024 — McMap. All rights reserved.
rails console
and execute some code to change the ip addresses. Test in development mode first, of course. – Paulinapauline