Creating UDXs in Python
Creating a user-defined extension (UDX) in Python involves designing the UDX, writing and debugging the underlying Python code, and operational testing.
To create a UDX in Python:
- Ensure that the python_path database manager configuration parameter is pointing to a Python runtime that can be used by the Db2 fenced process.
- Identify the action that the user-defined extension is to perform. For example, you might
require a function that performs tasks such as specialized string operations or comparisons; custom
mathematical analysis; or conversions such as metric to English measurements, Celsius to Fahrenheit,
or currency conversions.
Before the user-defined extensions feature was introduced, conversion and analysis tasks typically required users to export data from the database, carry out the conversion and analysis processing, then load the converted data back into the database for storage. With user-defined extensions, you can do many or all of these steps directly in the database.
- Review the existing SQL functions to confirm that your function is not already available as an SQL function. SQL offers a wide set of string, mathematical, analytical, and conversion functions. For example, if you want a function that changes the letter case of a string from uppercase to lowercase, or vice versa, SQL already provides LOWER() and UPPER() functions to do this.
- Write the Python code that implements the corresponding function and save it as a source file.
- Deploy (promote and register) the UDX as described in Deploying a UDX written in Python.
- Test and debug the UDX to identify and resolve any errors in the processing.