2

我需要从 tarantool 所有数据中选择一个空格中的两个值。我如何像在 mysql 中一样执行对 tarantool 的请求?

select from aaa where a=1a22cadbdb or a=7f626e0123

现在我可以提出两个请求:

box.space.logs:select({'1a22cadbdb'})
box.space.logs:select({'7f626e0123'})

但我不知道如何将结果合并为一个;(

4

3 回答 3

2

以下代码将字段 [0] 合并到 lua 表

a = box.space.logs:select({'1a22cadbdb'})
b = box.space.logs:select({'7f626e0123'})
c = { field_1 = a[0], field_2 = b[0] }

select 返回一个或多个元组,因此您可以通过 [] 提取值。

有关选择的更多详细信息: http://tarantool.org/doc/book/box/box_index.html?highlight=select #lua-function.index_object.select

关于元组的更多细节:http://tarantool.org/doc/book/box/box_tuple.html?highlight=tuple #lua-module.box.tuple

于 2016-03-23T12:35:33.893 回答
1

现在 Tarantool 允许您通过 SQL 进行检索,例如 box.execute([[select from "aaa" where "a"='1a22cadbdb' or "a"='7f626e0123';]])。在执行此操作之前,您必须使用 format() 函数添加 aaa 的字段名称和类型。

于 2019-09-14T14:32:09.613 回答
0

对我来说,这项工作很好,但需要从第一次选择中检查返回:

local res = {}
for k, v in pairs (box.space.email:select({email})[1]) do
    if type(v) == 'string' then
        table.insert(res, box.space.logs:select({v})[1])
    end
end
于 2016-03-25T12:01:41.607 回答