Let's say I have a table with key/values where the key is a regular expression and the corresponding value is the replacement value. For example:
table_a:
Key Value
-----------
a 123
b 456
c 789
I need to update a value in another table using SQL by replacing every key that appears in the table above with it's corresponding value.
If I had a single replacement value, I would use something like this:
UPDATE table_b
SET some_field = REGEXP_REPLACE((SELECT STRING_AGG(table_a.key, '|')
FROM table_a), 'replacement value');
This would construct a single regular expression based on all the keys in table_a and replace any occurrence with my replacement string.
How could I do something similar but use the corresponding value from table_a as the replacement value?
Using Postgres 9.5