sqlregexamazon-redshiftregexp-replace

Regular Expresssion find Comma in Redshift Database


I have a query which is having , in lname column. I want to find the , and replace it with blank. I want to use regex_substr but not getting any solution.

As of now i am able to resolve this using replcae function :

replace(lname,',','') as lname

I am newly learning regex. Can you please help me ?


Solution

  • According to Amazone-redshift documentation, REGEXP_REPLACE function definition is:

    REGEXP_REPLACE( source_string, pattern [, replace_string [ , position [, parameters ] ] ] )
    

    Which pattern is same as other type of SQL REGEX_REPLACE function and describe as follows:
    enter image description here

    So, your answer should be:

    select REGEXP_REPLACE('Tri,m all comma, fr,om inp,ut text,', ',', '', 1, 0);
    

    It should work in Amazone-redshift DB.

    MySQL sample solution: db<>fiddle