> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Executing Functions

An existing [UDF/UDTF](https://docs.kinetica.com/content/sql/udf.md#sql-udf) can be executed using
the `EXECUTE FUNCTION` command.  Additionally, a
[UDTF](https://docs.kinetica.com/content/sql/udf/create-function.md#sql-create-function) can be executed as a table function
within a `SELECT` statement.

```sql title="Execute UDF/UDTF Syntax" theme={null}
EXECUTE FUNCTION <function name>
(
   <function parameter 1> => <function value 1>,
   ...
   <function parameter N> => <function value N>
)
```

```sql title="Execute UDTF Table Function Syntax" theme={null}
SELECT * FROM TABLE
(
   <function name>
   (
      <function parameter 1> => <function value 1>,
      ...
      <function parameter N> => <function value N>
   )
)
```

The `<function name>` should be the name of an existing UDF.

> [!TIP]
>
> To preserve the runtime statistics of a UDF/UDTF, use the
> `KI_HINT_SAVE_UDF_STATS` hint in the call to it; see
> [below](https://docs.kinetica.com/content/sql/udf/executing-functions.md#sql-execute-function-examples) for an example.

## Function Parameters

The following are the available function parameters that may be passed to a
UDF in an `EXECUTE FUNCTION` or table function call, along with their
corresponding function values.

> [accordion] INPUT\_TABLE\_NAMES
>
> Optional set of "tables" that will be used as input to the UDF/UDTF, specified as a set of
> queries defining the source data for each "table".  The value of this parameter is either the
> `INPUT_TABLE` or `INPUT_TABLES` function, depending on the number of input "tables".
>
> <table>
>   <thead>
>     <tr>
>       <th>Value</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`INPUT_TABLE(<query>)`</td>
>       <td>If only one input table is needed, it can be passed by query or by name to the `INPUT_TABLE` function; e.g.: <pre>`INPUT_TABLE(customer)
>             INPUT_TABLE(SELECT id, name FROM customer)`</pre></td>
>     </tr>
>
>     <tr>
>       <td>`INPUT_TABLES(<queries>)`</td>
>       <td>If more than one input table is needed, each can be passed via query as a list to the `INPUT_TABLES` function; e.g.: <pre>`INPUT_TABLES
>             (
>             (SELECT id, name FROM customer),
>             (SELECT id, customer_id FROM order)
>             )`</pre></td>
>     </tr>
>   </tbody>
> </table>

> [accordion] OUTPUT\_TABLE\_NAMES
>
> Optional set of tables that will be used as output, specified as a set of names passed as a
> comma-delimited list of strings to the `OUTPUT_TABLES` function; e.g.:
>
> ```
> OUTPUT_TABLES('sales_summary', 'customer_profile')
> ```

> [accordion] PARAMS
>
> Optional list of parameters to pass to the function, specified as a set of key/value pairs
> passed  as a comma-delimited list of `<key> = '<value>'` assignments to the `KV_PAIRS`
> function; e.g.:
>
> ```
> KV_PAIRS(customer_id = '1', report_type = 'yearly')
> ```

> [accordion] OPTIONS
>
> Optional list of function execution options, specified as a set of key/value pairs passed as a
> comma-delimited list of `<key> = '<value>'` assignments to the `KV_PAIRS` function; e.g.:
>
> ```
> KV_PAIRS(run_tag = 'my-udf')
> ```
>
> All valid options from [Execute Proc](https://docs.kinetica.com/content/api/rest/execute_proc_rest.md)
> can be used here.

## Examples

To execute the `udf_st` UDF, specifying an input and output table and the hint
to save runtime statistics:

```sql Execute UDF Example theme={null}
EXECUTE FUNCTION udf_st /* KI_HINT_SAVE_UDF_STATS */
(
    INPUT_TABLE_NAMES => INPUT_TABLE(example.udf_st_in),
    OUTPUT_TABLE_NAMES => OUTPUT_TABLES('example.udf_st_out'),
    PARAMS => KV_PAIRS(sentence = 'I live in a neighborhood in a small town.')
)
```

To execute the `UDTF_ST` UDTF, specifying an input table and
returning the output as the result set of a `SELECT` statement:

```sql Execute UDTF Table Function Example theme={null}
SELECT TOP 5 score, sentence
FROM
	example.udf_st_in i,
	TABLE
	(
	    UDTF_ST
	    (
	        INPUT_TABLE_NAMES => INPUT_TABLE(example.udf_st_in),
	        PARAMS => KV_PAIRS(sentence = 'I live in a neighborhood in a small town.')
	    )
	) o
WHERE i.id = o.id
ORDER BY score DESC
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.