1

I'm trying to estimate a distance using this formula, but when I try to execute it in tarantool sql

box.execute [[SELECT "weight" + sqrt( cos("lat" - 12.31252) * ...]]

it shows:

function SQRT() is not available in SQL
Function 'COS' does not exist

how to make those functions available?

Kokizzu
  • 24,974
  • 37
  • 137
  • 233

1 Answers1

2

Those are not yet available in tarantool SQL out-of-the-box, but you can use box.schema.func.create to call arbitrary lua code from SQL. Here's what you need to do:

box.schema.func.create(
  'COS', {
    returns="number", 
    body="function (num) return math.cos(num) end", 
    is_sandboxed=false,
    param_list={"number"}, 
    exports = {'LUA', 'SQL'}
  })

Then call it like this:

box.execute("SELECT cos(123)")

To learn more about this, you can refer to the documentation on calling Lua from SQL.