I am trying to write a query in SqlAlchemy to find and replace a substring with another string if it exists in a column. What is the best way to achieve this?
I am trying to use regexp_replace
. I am unable to figure out how to use it. What I have tried so far is:
regexp_statement = table.select(sqlalchemy.func.regexp_replace(*regexp))
But this translates into wrong sql query. Select * from table_name where regexp_replace(string, search_string, replace_string)
How to properly use regexp_replace in sqlalchemy?
UPDATE
You need to use
update
, notselect
. Try to use this:OLD
You can use raw sql for that: