1

I'm trying to understand why the code below works as a JavaScript UDF in Snowflake:

create or replace function clean_name_function_test(COL string)
returns string
language javascript
as
$$  
  return COL.toLowerCase().replace(' ', '-');
$$;


set test_string = 'Brand - Test';
select clean_name_function_test($test_string);

returning brand-- test and why the code below (where .replace is swapped for .replaceAll) does not:

create or replace function clean_name_function_test(COL string)
returns string
language javascript
as
$$  
  return COL.toLowerCase().replaceAll(' ', '-');
$$;


set test_string = 'Brand - Test';
select clean_name_function_test($test_string);

throwing the error JavaScript execution error: Uncaught TypeError: COL.toLowerCase(...).replaceAll is not a function in CLEAN_NAME_FUNCTION_TEST at ' return COL.toLowerCase().replaceAll(' ', '-');' position 27 stackstrace: CLEAN_NAME_FUNCTION_TEST line: 2.

followingell
  • 413
  • 6
  • 12
  • 1
    Sounds like they haven't integrated the new proposal yet. Use a global regex instead – CertainPerformance Dec 24 '20 at 01:39
  • Not sure why my question was marked as a duplicate since [How to replace all occurrences of a string?](https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string) does not answer why `replaceAll` isn't supported in Snowflake Javascript UDFs. – followingell Dec 24 '20 at 02:38
  • 1
    To complement what CertainPerformance said: `replaceAll` is a kind of new addition to JavaScript, and Snowflake's JavaScript implementation still hasn't added this (but soon it will) – Felipe Hoffa Dec 24 '20 at 03:23

0 Answers0