Hey all! I’m wanting to create a migration to update every row by replacing a substring if it exists within the row.
I’m using raw SQL since I had issues w/ my implementations pointing towards accessing the schema.
My SQL query essentially wants to find every \n
and replace it with <br>
. If I run it as a SQL query through PSQL, it works just perfectly and my rows are updated. When I wrap it around execute/1 in a migration it fails to update rows. I’m wondering what the difference is between the same query being run in the migration to have it not identify \n
properly.
Snippet from PSQL which works
UPDATE table
SET body = regexp_replace(body, '\\n', '<br>', 'g')
WHERE body IS NOT NULL;
Snippet from migration which doesn’t work.
execute """
UPDATE table
SET body = regexp_replace(body, '\\n', '<br>', 'w')
WHERE body IS NOT NULL;
"""
The case I’d like is much more specific and at one point want to shove in this pattern: (\r\n|\r|\n)
, but I can’t get the simple replacement earlier displayed ^^ to work.
Sidenote: I tested to see if it was PSQL/Postgrex versioning not calling execute/1
properly. The function works and I’m able to replace very simple patterns such as replacing all a
's with b
's via Migration.