Deploying a UDX written in Python

Upload and promote the UDX file, and register the UDX that uses that file.

To deploy a UDX that is written in Python, take these steps:

  1. Upload the UDX file to all Db2 nodes or to a network drive that is accessible from all Db2 nodes, for example, /opt/ibm/db2/sqllib/function/routine/x1.py. Because Python UDXs are executed as Db2 fenced processes, the UDX file must be readable for the fenced user ID.
  2. Register the UDX by using the CREATE FUNCTION statement as described in CREATE FUNCTION statement. This statement assigns a name to the UDX, declares the input parameter of the routine and the return types, and links the UDX to the actual code in the file system.

Examples

The following example shows the CREATE FUNCTION statement for a scalar function:
CREATE FUNCTION x1(integer, integer) \
returns integer  LANGUAGE PYTHON  parameter style \
NPSGENERIC  FENCED  NOT THREADSAFE  NO FINAL CALL  ALLOW PARALLEL  NO DBINFO  DETERMINISTIC  NO EXTERNAL ACTION \
RETURNS NULL ON NULL INPUT  NO SQL \
external name '/opt/ibm/db2/sqllib/function/routine/x1.py'
The following example shows the CREATE FUNCTION statement for a table function:
CREATE FUNCTION x1 (integer, integer) \
returns table (m integer)  language PYTHON  parameter style \
NPSGENERIC   FENCED  NOT THREADSAFE  NO FINAL CALL  DISALLOW PARALLEL  NO DBINFO  DETERMINISTIC  NO EXTERNAL ACTION \
RETURNS NULL ON NULL INPUT  NO SQL \
external name '/opt/ibm/db2/sqllib/function/routine/x1.py'
The following example shows the CREATE FUNCTION statement for an aggregate function:
CREATE FUNCTION x1(integer) \
returns integer  aggregate with (integer, integer) \
language PYTHON  parameter style NPSGENERIC  FENCED  NOT THREADSAFE \
ALLOW PARALLEL  NO DBINFO  DETERMINISTIC  NO EXTERNAL ACTION  CALLED ON NULL INPUT  NO SQL \
external name '/opt/ibm/db2/sqllib/function/routine/x1.py'

After the UDX has been registered it can be tested and debugged.