访问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 個月前檢視次數 50 次
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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南