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
.