UDSF in Lua: Example 1
This example creates a function called adder
that adds two numbers
together and returns the result.
Code
Put the following code into the file /tmp/udsf_example1.nzl
:
function evaluate(a,b)
return a + b
end
function getName()
return "adder"
end
function getType()
return "udf"
end
function getArgs()
args={}
args[1] = { "a", double }
args[2] = { "b", double }
return args
end
function getResult()
return double
end
Compression
Compress the file /tmp/udsf_example1.nzl
into a file with the name
/tmp/udsf_example1.tar
.
Deployment
Deploy the UDX to a Db2® instance by issuing the following
CLPPlus
command:
SQL> IDA DEPLOYUDX SRC /tmp/udsf_example1.tar LANGUAGE lua PROJECT example1
Running
Use this function in a query, for example:
values adder(3,5)
This returns
the following result:1
-----------
8