Tarantool中的SQL LIKE查询

4
什么是在Tarantool数据库中使用SQL LIKE关键字进行查询的正确方法? 例如:
SELECT * FROM space where smth LIKE '%some_value%';

我能搜索部分索引值吗,还是需要编写自己的LUA脚本实现这样的功能?

我认为由于Tarantool是NoSQL数据库,您将无法使用SQL语法编写查询。 - Alex
@Alex,从tarantool 2.0版本开始,tarantool支持SQL。 - o2gy
谢谢@o2gy,这个问题是2016年的,版本2的第一个alpha版几年后发布。 - Alex
3个回答

4

是的,你需要编写Lua脚本来迭代空间并在元组的'smth'字段上使用Lua函数gsub。目前还没有搜索字符串部分的方法。


4

如果您使用tarantool 2.x版本,则您的查询没有任何问题。

SELECT * FROM "your_space" WHERE "smth" LIKE '%some_value%';

3

优化前缀搜索可使用存储过程。 例如,此代码片段也适用于 Cyrillic 文本:

box.schema.create_space('address')
box.space.address:create_index('prefix', { type = 'tree', parts = { { 1, 'str', collation = 'unicode_ci' } }, unique = true })

select_by_prefix = function(prefix)
    local result = {}
    for _, addr in box.space.address.index.prefix:pairs(prefix, { iterator = 'GT' }) do
        if utf.casecmp(utf.sub(addr[1], 1, utf.len(prefix)), prefix) == 0 then
            table.insert(result, addr)
        else
            break
        end
    end
    return result
end

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接