# Use SQL user defined functions in Managed ClickHouse®

Use SQL user defined functions (UDFs) in Managed ClickHouse® to name repeated expressions once and keep your queries readable.

You can define your own SQL UDFs, which are automatically replicated to all nodes in
the cluster and contained in backups.

> [!NOTE]
> Managed ClickHouse supports SQL UDFs only. UDF types other than SQL UDFs, such as
> [executable UDFs](https://clickhouse.com/docs/reference/functions/regular-functions/udf#executable-user-defined-functions),
> are not supported in Managed ClickHouse.

## Create a UDF in SQL

To create an SQL UDF in Managed ClickHouse, run the `CREATE FUNCTION` expression
including function parameters, constants, operators, or other function calls.

```sql
CREATE FUNCTION name AS (parameter0, ...) -> expression
```

## Limitations

- The name of your UDF needs to be unique among other functions.
- Recursive functions are not supported.
- All variables used by your UDF need to be defined in its parameter list.

## Example of using SQL UDFs

1. Create an SQL UDF.

    ```sql
    CREATE FUNCTION is_weekend AS (date) -> toDayOfWeek(date) IN (6, 7);
    ```

1. Use your `is_weekend` SQL UDF in a `SELECT` query.

    This example counts the week-end rides in the `trips` table loaded in the
    [quick start](/product/dbaas/service-specific/clickhouse/quick-start/#load-a-dataset):

    ```sql
    SELECT count()
    FROM trips
    WHERE is_weekend(pickup_date)
    ```

