How do I return multiple values from a UDF?


#1

How do I return multiple values from a UDF?


#2

We advise using a LIST or a MAP to return multiple values from a UDF.

Here’s an example using MAP:

Try this AQL:

insert into test.demo (PK, bn1, bn2) values ('cats_1_1', 123, 321)
register module 'udf/return_value.lua'
execute return_value.many() on test.demo where pk = 'cats_1_1'

This is the UDF (return_value.lua):

function many(rec)
    local returnMap = map()
    returnMap.first = rec.bn1
    returnMap.second = rec.bn2
    return returnMap
end

This will return something like this:

   UDF result: {second=321, first=123}