Creating a Scalar user-defined function using JavaScript
In this recipe, we will be walking you through the creation of JavaScript-based Scalar UDFs and demonstrating the usage of JavaScript-based UDFs.
Getting ready
You will need to be connected to your Snowflake instance via the Web UI or the SnowSQL client to execute this recipe.
How to do it
We will be creating a series of UDFs to demonstrate the various JavaScript UDF capabilities provided by Snowflake. We will start by creating a simple UDF and will gradually increase the complexity of the UDFs that we create. The basic syntax for creating a JavaScript-based UDF is similar to the syntax for creating a SQL UDF, but with a slight difference. The difference is that if you do not specify the LANGUAGE
attribute, a UDF will default to the SQL language. The syntax for a JavaScript-based UDF is as follows:
CREATE FUNCTION <name> ( [ <arg_name> <arg_data_type> ] ) RETURNS <result_data_type> [ LANGUAGE...