I would like to do pattern matching and substring replacement in PostgreSQL with a "select-case-when-then-update-query". Example:
tableA
field1 |field2 | field3
---------------------+----------------+-----------
(varchar)bla abla 123|(varchar)abla |(varchar)123
(varchar)blub 456 |(varchar)blub |(varchar)456
remaining string in field1 after performing the substring replacement should be "bla" in row 1 and "blub 456" in row 2 (see Note below):
tableA
field1 |field2 | field3
---------------------+----------------+-----------
(varchar)bla |(varchar)abla |(varchar)123
(varchar)blub 456 |(varchar)blub |(varchar)456
So, I would like to update field1 if the following condition is true:
Pseudocode:
if string from field2 and/or string from field3 is substring of field1
then replace substring field2, field3 from field1 if remaining string in field1 > 0
Note: If there is no string or token left in field1 after substring removal the string should not be touched.