SQL access 2d array element

0

Hi I have this payload and want to do some comparison operation in aws iot rule:

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

. I want to compare if temp[0][2] is equal to 2 or not. I have written this sql statement

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

but this throws following exception

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

So anyone up for help? Thanks

1개 답변
2
수락된 답변

To access elements in a collection (array, string, object ) use the SQL function get function:

In your case, use get() instead of square brackets to access your array element:

SELECT * as result FROM 'topic' where get(get(state.reported.temp,0),2) = 2
profile pictureAWS
전문가
Jan_B
답변함 2년 전
profile pictureAWS
전문가
Greg_B
검토됨 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠