Skip to content

JavascriptUDF

Snowflake Documentation

A Javascript user-defined function (UDF) in Snowflake allows you to define a function using the JavaScript programming language.

Examples

YAML

functions:
  - name: some_function
    language: javascript
    returns: STRING
    as_: function(x) { return x.toUpperCase(); }
    args:
      - name: x
        data_type: STRING
    comment: Converts a string to uppercase

Python

js_udf = JavascriptUDF(
    name="some_function",
    returns="STRING",
    as_="function(x) { return x.toUpperCase(); }",
    args=[{"name": "x", "data_type": "STRING"}],
    comment="Converts a string to uppercase",
)

Fields

  • name (string, required) - The name of the function.
  • returns (string or DataType, required) - The data type of the function's return value.
  • as_ (string, required) - The JavaScript code to execute when the function is called.
  • args (list) - The arguments that the function takes.
  • comment (string) - A comment for the function.
  • copy_grants (bool) - Specifies whether to retain the access privileges from the original function when a new function is created using CREATE OR REPLACE FUNCTION. Defaults to False.
  • external_access_integrations (list) - External integrations accessible by the function.
  • handler (string) - The entry point for the function within the JavaScript code.
  • imports (list) - The list of JavaScript files to import.
  • null_handling (string or NullHandling) - How the function handles NULL input.
  • owner (string or Role) - The owner of the function. Defaults to "SYSADMIN".
  • packages (list) - The list of npm packages that the function depends on.
  • runtime_version (string) - The JavaScript runtime version to use.
  • secrets (dict of string to string) - Key-value pairs of secrets available to the function.
  • secure (bool) - Specifies whether the function is secure. Defaults to False.
  • volatility (string or Volatility) - The volatility of the function.