Db2 routines in Rust
This is a basic example of a C-compatible Db2 UDF created in Rust. It is meant to demonstrate that FFI-style Rust code can be called from Db2. Our routine is very simple and the output is doulbe the input integer.
Compile the shared library as any other Rust project:
cargo build --releaseCopy the file target/release/libdb2rustrn.so to the ~/sqllib/function/ directory on the Db2 server.
The file create.db2 has the DDL statement to create the function.
You will need the following authorites in order to run it:
One of:
- CREATEIN on the current schema
- IMPLICITSCHEMA if the schema does not exist
- DBADM
As well one of:
- SYSADM
- CREATE_EXTERNAL_ROUTINE and CREATE_NOT_FENCED_ROUTINE
Create the function using the CLP:
db2 connect to <dbname>
db2 -td@ -f create.db2db2 "values DoubleExample(17)"
1
-----------
34
1 record(s) selected.