I have a post table which has a title and a description.
My goal is to clean the description by applying a set of rules. For simplicity let's say that I'd like to apply following rules:
REPLACE "H" with "Z"
REPLACE "Z" with "C"
REPLACE "C" with "X"
So if I have the string "Hello world", the output would be "Xello world" after applying the three rules.
Hello world -> Zello world -> Cello world -> Xello world
I know I can achieve this using 3 independent update queries
UPDATE post
SET description = REPLACE(description, 'H', 'Z');
UPDATE post
SET description = REPLACE(description, 'Z', 'C');
UPDATE post
SET description = REPLACE(description, 'C', 'X');
But I am wondering if there is a better way to achieve what I want. Maybe I need a procedure? a function? store the middle result in a variable?
I am using Postgres 12.