Skip to main content

CREATE FUNCTION

Introduced or updated: v1.2.339

Creates an external function.

Syntax

CREATE [ OR REPLACE ] FUNCTION [ IF NOT EXISTS ] <function_name> 
AS ( <input_param_types> ) RETURNS <return_type> LANGUAGE <language_name>
HANDLER = '<handler_name>' ADDRESS = '<udf_server_address>'
[DESC='<description>']
ParameterDescription
<function_name>The name of the function.
<lambda_expression>The lambda expression or code snippet defining the function's behavior.
DESC='<description>'Description of the UDF.
<<input_param_names>A list of input parameter names. Separated by comma.
<<input_param_types>A list of input parameter types. Separated by comma.
<return_type>The return type of the function.
LANGUAGESpecifies the language used to write the function. Available values: python.
HANDLER = '<handler_name>'Specifies the name of the function's handler.
ADDRESS = '<udf_server_address>'Specifies the address of the UDF server.

Examples

This example creates an external function that calculates the greatest common divisor (GCD) of two integers:

CREATE FUNCTION gcd AS (INT, INT) 
RETURNS INT
LANGUAGE python
HANDLER = 'gcd'
ADDRESS = 'http://localhost:8815';
Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today