访问SQL中的二维数组元素

0

【以下的问题经过翻译处理】 你好, 我有这个负载并想在aws iot规则中执行一些比较操作:

{
"state":
  {
    "reported":{
        "temp": [
                 [
                 1,
                0,
                2,
                "hello world",
                "-",
               "",
               "",
              0
               ] ,
              []
             ]
           }
     }
}

我想比较temp [0] [2]是否等于2。 我编写了这个SQL语句

SELECT * FROM '$aws / topic' WHERE state.reported.temp [0] [2] = 2

但是它会抛出以下异常

SqlParseException
Expected a comparison operation: JPathNode (List (IdentNode(state), IdentNode(reported),IdentNode(temp))) state.reported.temp [0] [2] = 2 ------------------------------------------------- ^ at 1:50

所以有人能帮忙吗? 谢谢

profile picture
专家
已提问 5 个月前46 查看次数
1 回答
0

【以下的回答经过翻译处理】 要访问集合(数组、字符串、对象)中的元素,请使用SQL函数[get](https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html)函数:

在您的情况下,使用get()而不是方括号来访问您的数组元素:

SELECT * as result FROM 'topic' where get(get(state.reported.temp,0),2) = 2
profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则