I’m trying to normalise a data field by removing a fairly common postfix. I’ve got as far as using the substring() function in postgres, but can’t quite get it to work. For example, if I want to strip the postfix ‘xyz’ from any values that have it;
UPDATE my_table SET my_field=substring(my_field from '#"%#"xyz' for '#');
But this is having some weird effects that I cant pin down. Any thoughts? Many thanks as always.
This will also change the value
'xyz'into an empty string. I don’t know if you want that (or if the suffix can exists “on it’s own”.The where clause is not strictly necessary but will make the update more efficient because only those rows are updated that actually meet the criteria.