DB2 User Defined Functions (UDFs) allow developers to extend the built-in functionality of the database by creating custom functions that can be invoked in SQL statements. DB2 supports several types of SQL UDFs:
Scalar Functions: Return a single value and can be used wherever an SQL expression is valid.
Table Functions: Return a table result set and can be used in the FROM clause of SELECT statements.
SnowConvert AI Translation Support: SnowConvert AI supports translation of Inline UDFs, SQL Scalar Functions, and SQL Table Functions with the following migration approaches:
Inline Functions: Will be kept as Inline Functions in Snowflake.
Non-inline UDFs: If they are Snowflake Scripting compliant, they will be transformed into Snowflake Scripting UDFs
Complex UDFs: Any UDFs that don’t fit the above two categories will be migrated to Stored Procedures instead.
In cases where UDFs are converted to procedures, an EWI message will be added to inform the user why the UDF could not be directly migrated to a Snowflake UDF and was converted to a procedure instead.
DB2 CREATE FUNCTION statements support various options that control the behavior, performance, and security characteristics of the function. These options specify how the function should be executed, what SQL operations it can perform, whether it’s deterministic, and how it handles parallel execution, among other settings.
The following table shows the DB2 to Snowflake UDF option equivalencies:
DB2 Option
Snowflake Equivalent
Notes
LANGUAGE SQL
LANGUAGE SQL
Translated to Snowflake’s equivalent syntax
SPECIFIC specific_name
Not Needed
Snowflake doesn’t support specific names for UDFs
DETERMINISTIC / NOT DETERMINISTIC
IMMUTABLE / MUTABLE
Preserved in Snowflake UDF definition
EXTERNAL ACTION / NO EXTERNAL ACTION
Not Needed
Snowflake doesn’t have equivalent option
READS SQL DATA
LANGUAGE SQL
Snowflake UDFs can read data by default
CONTAINS SQL
LANGUAGE SQL
Basic SQL support is default in Snowflake
MODIFIES SQL DATA
Not Needed
UDFs that modify data are converted to stored procedures
ALLOW PARALLEL / DISALLOW PARALLEL
Not Needed
Snowflake handles parallelization automatically
STATIC DISPATCH
Not Needed
Not applicable in Snowflake’s architecture
CALLED ON NULL INPUT
Default Behavior
Snowflake UDFs handle NULL inputs by default
INHERIT SPECIAL REGISTERS
Not Needed
Snowflake doesn’t have equivalent special registers
PREDICATES (...)
Not Needed
Snowflake doesn’t support predicate pushdown specifications
INHERIT ISOLATION LEVEL
Not Needed
Snowflake uses different transaction isolation model
SECURED / NOT SECURED
Not Needed
Snowflake uses different security model
PARAMETER CCSID
Not Needed
Character set handling differs in Snowflake
Note
Options marked as “Not Needed” will be removed during migration because Snowflake either handles the functionality automatically (e.g., parallelization, NULL input handling) or the option is not applicable in Snowflake’s architecture (e.g., special registers, isolation levels).
Inline UDFs in DB2 are simple functions that contain a single SQL expression or return statement without complex procedural logic. These functions are typically defined with a direct RETURN clause followed by a simple expression, calculation, or query.
SnowConvert AI preserves these as Inline Functions in Snowflake, maintaining their simplicity and performance characteristics.
Note
Some parts in the output code are omitted for clarity reasons.
Scalar UDFs in DB2 are functions that return a single value and can contain more complex logic than inline functions. These functions may include procedural constructs such as variable declarations, conditional statements, loops, and multiple SQL statements. Unlike inline UDFs, scalar UDFs with complex logic use a BEGIN...END block structure to encapsulate their functionality.
SnowConvert AI Migration: If the scalar UDF logic is compatible with Snowflake Scripting syntax, it will be translated to a Snowflake Scripting UDF. This preserves the function’s behavior while adapting it to Snowflake’s UDF implementation. Functions that contain unsupported constructs will be converted to stored procedures instead.
Note
Some parts in the output code are omitted for clarity reasons.
SnowConvert AI will not translate UDFs containing the following elements into SnowScripting UDFs, as these features are unsupported in SnowScripting UDFs:
Table UDFs (Table-Valued Functions) in DB2 are functions that return a table result set rather than a single value. These functions can be used in the FROM clause of SELECT statements. Table UDFs are defined with a RETURNS TABLE clause that specifies the structure of the returned table.
SnowConvert AI Migration: Table UDFs that are compatible with Snowflake’s table function syntax will be translated to Snowflake Table Functions. This preserves their functionality while adapting them to Snowflake’s implementation. Functions that contain unsupported Snowflake Scripting elements will be converted to stored procedures that return result sets instead.
Note
Some parts in the output code are omitted for clarity reasons.
Some DB2 UDFs cannot be directly migrated as Snowflake UDFs due to limitations in Snowflake Scripting UDFs. When a DB2 UDF contains elements that are not supported in Snowflake Scripting UDFs (such as SQL DML statements, cursors, result sets, or calls to other UDFs), SnowConvert AI will migrate these functions as Stored Procedures instead.
SnowConvert AI Migration: These UDFs are converted to stored procedures with an EWI message explaining why the direct UDF migration was not possible.
Note
Some parts in the output code are omitted for clarity reasons.
The main limitation is that the resulting converted procedure must be invoked using the CALL syntax, preventing its use directly within standard SQL expressions like the original UDF.