📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

User-Defined Function



User-Defined Functions (UDFs) in TiDB Cloud Lake allow you to create custom operations tailored to your specific data processing needs. This page highlights the commands you will use most often and helps you choose the right function type for your use case.

Function Management Commands

CommandDescription
CREATE AGGREGATE FUNCTIONScript UDAF (JavaScript/Python runtimes)
CREATE TABLE FUNCTIONSQL-only table function returning result sets
SHOW USER FUNCTIONSLists all user-defined functions
ALTER FUNCTIONModifies existing functions
DROP FUNCTIONRemoves functions

Function Type Comparison

FeatureScalar (SQL)Scalar (Python/JavaScript)Aggregate (Script)Tabular SQL
Return TypeSingle valueSingle valueSingle valueTable/ResultSet
LanguageSQL expressionsPython/JavaScriptJavaScript/Python runtimesSQL queries
Performance⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
Enterprise RequiredNoPython runtime onlyPython runtime onlyNo
Package SupportNoPython: Yes (PACKAGES)Python: Yes (PACKAGES)No
Best ForMath calculations
String operations
Data formatting
Advanced algorithms
External libraries
Control flow logic
Custom aggregations that need scripting logicComplex queries
Multi-row results
Data transformations

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 $$; -- Scalar Function (Python/JavaScript) CREATE FUNCTION func_name(param TYPE) RETURNS TYPE LANGUAGE python HANDLER = 'handler' AS $$ code $$;

Was this page helpful?