Search code examples
amazon-web-servicesamazon-athenapresto

Athena - check if column a string contains column b string


I have a table with two columns, column A is a URL string and column B is a tracking id string. I need to check whether the tracking id string is included in the URL string, and then remove it from the URL string if so. Guessing it's quite straightforward but I just think of how do it. Thanks.


Solution

  • You can check with:

    url like '%' || tracking || '%'
    

    You could remove the substring with:

    replace(url, tracking)
    

    Frankly, there is no need to check for the tracking ID first, since if it isn't present, it simply won't be replaced, so you can just use the replace(url, tracking) command.

    See: 6.9. String Functions and Operators — Presto Documentation