Overview
Main features of SQL UDF:- Dynamic Expansion: Expands function calls into actual SQL expressions during the query optimization phase
- Type Safety: Supports explicit declaration of parameter types and return types
- Parameterized: Supports named parameters to improve function readability
- Complex SQL expressions that need to be reused
- Simple data transformation and calculation logic
- Standardized data processing rules
Syntax
Creating SQL UDF
Parameters
Dropping SQL UDF
Showing SQL UDF
Usage Examples
Example 1: String Processing Function
Example 2: Multi-parameter Calculation Function
Example 3: Complex Expression Encapsulation
Example 4: Conditional Logic Function
Example 5: Global SQL UDF
Advanced Features
1. Nested Usage
SQL UDF supports nested calls:2. Type Conversion
SQL UDF supports implicit type conversion:3. Combination with Built-in Functions
SQL UDF can be freely combined with the database built-in functions:Viewing and Managing
Showing All Functions
Dropping Functions
Replacing Functions
Use theOR REPLACE keyword to replace an existing function:
Performance Characteristics
SQL UDF is expanded into actual SQL expressions during the query optimization phase, with the following performance characteristics:- Zero Function Call Overhead: No function call overhead like traditional UDFs
- Optimizer Visibility: The optimizer can see the complete expression for better optimization
- Predicate Pushdown: Supports predicate pushdown and other optimization rules
Limitations and Considerations
- Parameter Count Limitation: Parameter count should match variables used in expression
- Type Matching: Parameter types should match usage in expression