When trying to use replaceAll()
function from a String object in Snowflake’s Javascipt UDF, it will fail with the below error message:
100132 (P0000): JavaScript execution error: Uncaught TypeError: a.replaceAll is not a function in TEST at ' return a.replaceAll('test', '');' position 11
Based on the information on Wikipedia, the string function replaceAll() was released in June 2021, with 12th Edition – ECMAScript 2021.
Since this is a new function, it has not been incorporated into Snowflake’s Javascript library.
To perform a replace all on a string, we can use the replace()
function using a regular expression with a “g” global flag. Example as below:
"Mr Blue has a blue house and a blue car".replace(/blue/g, "red");
The above Javascript code will return: “Mr Blue has a red house and a red car
“