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, 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.
CREATE FUNCTION name AS (parameter0, ...) -> expressionLimitations
- 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
Create an SQL UDF.
CREATE FUNCTION is_weekend AS (date) -> toDayOfWeek(date) IN (6, 7);Use your
is_weekendSQL UDF in aSELECTquery.This example counts the week-end rides in the
tripstable loaded in the quick start:SELECT count() FROM trips WHERE is_weekend(pickup_date)
Last updated on