> For the complete documentation index, see [llms.txt](https://docs.snowddl.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.snowddl.com/basic/yaml-configs/function.md).

# FUNCTION

Config path: `/<database>/<schema>/function/<name>(<dtypes>).yaml`

Example:

```yaml
arguments:
  input_val: OBJECT

returns: VARCHAR(1000)

body: |-
  GET(input_val, COALESCE('BOOKINGS_LANG', 'en'))::varchar(1000)
```

```yaml
arguments:
  x: VARCHAR(10000)

returns: VARCHAR(255)
language: java

imports:
  - stage: test_internal_stage
    path: /lib/zero-allocation-hashing-0.15.jar

handler: SnowHash.xxHash

body: |-
  import net.openhft.hashing.LongHashFunction;

  class SnowHash {
      public static LongHashFunction hash_func = LongHashFunction.xx();

      public static String xxHash(String x) {
          return Long.toHexString(hash_func.hashChars(x));
      }
  }

```

```yaml
language: python
runtime_version: "3.8"

returns: VARIANT

packages:
  - numpy
  - pandas
  - xgboost==1.5.0

handler: udf

body: |-
  import numpy as np
  import pandas as pd
  import xgboost as xgb

  def udf():
    return [np.__version__, pd.__version__, xgb.__version__]

```

## Schema

* **language** (str) - language of function (default: SQL)
* **runtime\_version** (str) - used to specify version of Python, Java, etc.
* **arguments** (dict)
  * *{key}* (ident) - argument name
  * *{value}* (str) - argument [data type](/guides/data-types.md)\
    \--- OR ---
  * *{value}* (dict)
    * <mark style="background-color:red;">**type**</mark> (str) - argument [data type](/guides/data-types.md)
    * **default** (str) - default SQL expression for optional argument
* <mark style="background-color:red;">**returns**</mark> (str) - for single return value, return data type\
  \--- OR ---
* <mark style="background-color:red;">**returns**</mark> (dict) - for table return values
  * *{key}* (ident) - return column name
  * *{value}* (str) - return column data type
* **body** (str) - function body
* **is\_secure** (bool) - is function SECURE
* **is\_aggregate** (bool) - is function AGGREGATE
* **is\_strict** (bool) - is function STRICT (always returns NULL on NULL input)
* **is\_immutable** (bool) - is function IMMUTABLE (same input always produced the same output)
* **is\_memoizable** (bool)
* **imports** (list) - files to import (usually JAR packages)
  * *{items}* (dict)
    * **stage** (ident) - name of stage
    * **path** (str) - path to file
* **packages** (list) - Snowflake system packages to import as dependencies
  * *{items}* (str) - name of package, with optional version of package
* **handler** (str) - name of class and method to be called
* **external\_access\_integrations** (list)
  * *{items}* (ident) -  name of [external access integration](/basic/yaml-configs/external-access-integration.md)
* **secrets** (dict)
  * *{key}* (str) - secret variable name used in function code
  * *{value}* (ident) - name of [secret](/basic/yaml-configs/secret.md) object
* **comment** (str)&#x20;

## Usage notes

1. Snowflake supports [overloading](https://docs.snowflake.com/en/sql-reference/udf-overview.html#overloading-of-udf-names) of function names. Multiple functions may have the same name as long as they have different arguments. It is required to use comma-separated base data types of arguments in config names.\
   \
   For example: `my_function(number).yaml`, `my_function(varchar,number).yaml`
2. Files for `imports` should be maintained using [STAGE FILES](/basic/yaml-configs/stage-file.md).
3. If function `body` is empty, `handler` and `imports` with pre-compiled JAR or Python code are required.
4. `runtime_version` should be specified as string with explicit double-quotes (e.g. `"3.8"`). Otherwise YAML parser may confuse it with number, which may cause some unwanted effects.
5. You may use [custom YAML tag](/basic/yaml-tag-include.md) `!include` to store function body in a separate file instead of storing it inside YAML.

## Links

* [CREATE FUNCTION](https://docs.snowflake.com/en/sql-reference/sql/create-function.html)
* [SHOW USER FUNCTIONS](https://docs.snowflake.com/en/sql-reference/sql/show-user-functions.html)
* [Parser & JSON Schema (GitHub)](https://github.com/littleK0i/SnowDDL/blob/master/snowddl/parser/function.py)
