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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

7 Comments

create or replace procedure sppi() returns VARCHAR language javascript as $$ var A=new regexp_replace('Customers - (NY)','\(|\)',''); return A; $$ ; call sppi();
select regexp_replace('Customers[0].value','\[|\]|[0-9]','') as customers; // this command is working but If I implement in stored procedure it is not working.
you first comment is proving my point. You cannot call SQL functions from Javascript.
BEGIN let A := regexp_replace('Customers[0].value','\[|\]|[0-9]',''); RETURN :A; END; works for me. Are you using classic console?
what is the difference between the select and call procedure()? If I use select it is working and If I use call prodecure() it is not working?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.