I am trying to convert state names to abbreviations and I am using the replace function. I am able to run the snippet successfully but names remain the same without being converted to abbreviation:
UPDATE county SET state_name = replace(state_name, '(Texas)', 'TX');
UPDATE county SET state_name = replace(state_name, '(Utah)', 'UT');
UPDATE county SET state_name = replace(state_name, '(Vermont)', 'VT');
UPDATE county SET state_name = replace(state_name, '(Virginia)', 'VA');
UPDATE county SET state_name = replace(state_name, '(Washington)', 'WA');
UPDATE county SET state_name = replace(state_name, '(West Virginia)', 'WV');
UPDATE county SET state_name = replace(state_name, '(Wisconsin)', 'WI');
UPDATE county SET state_name = replace(state_name, '(Wyoming)', 'WY');
UPDATE county SET state_name = replace(state_name, '(Puerto Rico)', 'PR');
--Let's check the result
select * from county;
select replace('flimflam (Texas) blahblah', '(Texas)', 'TX') as state
return?state_name
has leading and/or trailing whitespace, or it's in capital letters, or for whatever reason the pattern is just not what OP is expecting. ....hopefully, whatever it is, it's systematic!