Retrieve the difference between Strings on BigQuery

708 Views Asked by At

Is it possible to retrieve the difference between 2 strings using Bigquery functions.

Example.

String 1: "Hello world"

String 2: "Hello big world"

Result expepected: "big"

Thanks

1

There are 1 best solutions below

0
Daniel Zagales On

try the following:

with sample_data as (
    select 'hello world' as str_1, 'hello big world' as str_2
)

select 
    str_1
    , str_2_split
from sample_data 
, unnest(split(str_2, " ")) str_2_split
where regexp_contains(str_1, str_2_split)=false

this approach splits the second string into an array and compares it against the values in string_1.