Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

When i use regex_replace in procedure in snowflake not working

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

>Solution :

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading