Based on this questions and the perfect answer given there, I now need to use this approach to UPDATE a table column.
Table1 (data table)
textWithFoundItemInIt | updated_foundItem
-------------------------------------------
hallo Adam | nothing in here yet
Bert says hello | ....
Bert says byebye |
Want to find "Caesar"bdjehg |
Want to find "Caesar"bdjehg |
Want to find "Caesar"again |
Table2 (mapping table)
mappingItem
------------
Adam
Bert
Caesar
Bert
Caesar
Adam
Expected result UPDATED
textWithFoundItemInIt | updated_foundItem
--------------------------------------------
hallo Adam | Adam
Bert says hello | Bert
Bert says byebye | Bert
Want to find "Caesar"bdjehg | Caesar
Want to find "Caesar"bdjehg | Caesar
Want to find "Caesar"again | Caesar
Want to find "Caesar"again and also Bert | Caesar [or Bert]
Want to find "CaesarCaesar"again and again | Caesar
My query: Based on this answer, I came up with this Update-Statement:
UPDATE Table1
SET updated_foundItem = foundItem
FROM
(select DISTINCT textWithFoundItemInIt,
regexp_extract(textWithFoundItemInIt, r'(?i)' || mappingItems) AS foundItem
from table1, (select string_agg(mappingItem, '|') mappingItems from table2))
WHERE ... ???
But I have no clue how the correct WHERE-statement should look like. Unfortunately I cannot test many queries in bigQuery, as my dataset is very large and even making a sample for testing is currently out of scope.
Thanks a lot for your help.