Skip to content
Advertisement

How to call C functions from SQL in Tarantool?

How can I call a C-function from SQL in Tarantool?

Documentation says:

C functions are imported from .so files

But where shall I specify the reference to my .so file?

It would be great to see an example.

Advertisement

Answer

You should firstly register your function via :func.create:

box.schema.func.create("function1.divide", {language = 'C', returns = 'number',
                        is_deterministic = true,
                        exports = {'LUA', 'SQL'}})

You can read more info on the subj here: https://www.tarantool.io/en/doc/latest/tutorials/c_tutorial/

Then you can use it in SQL:

box.execute('SELECT "function1.divide"()')

Also you can examine more examples in source code (test/box/function1.test.lua).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement