VARARGS examples

Example #1

This VARARGS UDF takes from one to 64 arguments (the Netezza UDX implementation is currently limited to a maximum of 64 arguments), adds them together, and returns the result. The initialize() method is used to verify that all of the arguments being passed into the UDF are numbers. The global variable ARGCOUNT indicates the number of arguments that have been passed to the VARARGS UDX.
function initialize()
for i,type in pairs(ARGTYPE) do
if type != TYPE_NUMBER then
error("All arguments must be numbers!",0)
end
end
end

function evaluate( ... )
local x=0
for i=1,ARGCOUNT do
x = x + select(i, ...)
end

return x

end

function getType()
return "udf"

end

function getName()
return "varadd"

end

function getArgs()
return varargs

end

function getResult()
return double

end