Skip to main content

User-Defined Function

User-Defined Functions (UDFs) in Databend allow you to create custom operations tailored to your specific data processing needs. This page helps you choose the right type of function for your use case.

Function Type Comparison

FeatureScalar SQLTabular SQLEmbedded
Return TypeSingle valueTable/ResultSetSingle value
LanguageSQL expressionsSQL queriesPython/JavaScript/WASM
Performance⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
Enterprise RequiredNoNoPython: Yes
Package SupportNoNoPython: Yes
Best ForMath calculations
String operations
Data formatting
Complex queries
Multi-row results
Data transformations
Advanced algorithms
External libraries
Control flow logic

Function Management Commands

CommandDescription
CREATE SCALAR FUNCTIONCreates a scalar SQL function using unified syntax
CREATE TABLE FUNCTIONCreates a table function that returns result sets
CREATE EMBEDDED FUNCTIONCreates embedded functions (Python/JavaScript/WASM)
SHOW USER FUNCTIONSLists all user-defined functions
ALTER FUNCTIONModifies existing functions
DROP FUNCTIONRemoves functions

Unified Syntax

All local UDF types use consistent $$ syntax:

-- Scalar Function
CREATE FUNCTION func_name(param TYPE) RETURNS TYPE AS $$ expression $$;

-- Tabular Function
CREATE FUNCTION func_name(param TYPE) RETURNS TABLE(...) AS $$ query $$;

-- Embedded Function
CREATE FUNCTION func_name(param TYPE) RETURNS TYPE LANGUAGE python
HANDLER = 'handler' AS $$ code $$;
Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today