When i use regex_replace in procedure in snowflake not working

Viewed 94
create or replace function sppi()
    returns VARCHAR
    language javascript
    as
    $$
    var A= regexp_replace('Customers - (NY)','\\(|\\)','');
    return A;
    $$
    ;
call sppi();
1 Answers

Well your REGEXP is valid from the console/WebUI perspective:

select 'Customers - (NY)' as str, regexp_replace(str,'\\(|\\)','');
STR REGEXP_REPLACE(STR,'\(|\)','')
Customers - (NY) Customers - NY

so in javascipt functions you cannot directly call SQL functions, so if we flip to a Snowflake Scripting we can though.

BEGIN 
    let A := regexp_replace('Customers - (NY)','\\(|\\)','');
   
   RETURN :A;
END;
anonymous block
Customers - NY

where-as if you want to stay in Javasript, lets use a Javascript replace:

create or replace function sppi()
    returns VARCHAR
    language javascript
    as
    $$
    var A= 'Customers - (NY)'.replace(/\(|\)/g,'');
    return A;
    $$
    ;
select sppi();
SPPI()
Customers - NY
Related