sqlnetezzanzsql

Get exact match from a string in Netezza


I am trying to extract a substring from a string and do comparison with other string and see if its a complete match or not. Can someone share your thoughts on how to accomplish this using regular expressions. Thank you.

**Input column**
abc
abcd

**What I have tried?**
LIKE '%abc%'

**Output** 
abc
abcd

But I need only abc and discard abcd in this case.How can this be done using LIKE. I guess LIKE doesnt support to accomplish which is the reason I am interested to use regex for this problem. Thank you.


Solution

  • The solution will depend on how you distinguish 'abc' from 'abcd'. Based on you question, I infer the answer to that would be the regex idea of word boundaries.

    Netezza does not support general regexp functionality in LIKE, so you'll have to use something like the regexp_extract function included the Netezza SQL Extension toolkit.

    select regexp_extract('abc abcd','\babc\b');
    
     REGEXP_EXTRACT
    ----------------
     abc
    (1 row)
    

    The SQL Extension Toolkit is included with Netezza, but must be configured and made available by your administrator.