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

feita há 2 anos338 visualizações
1 Resposta
2
Resposta aceita

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
ESPECIALISTA
Jan_B
respondido há 2 anos
profile pictureAWS
ESPECIALISTA
Greg_B
avaliado há 2 anos

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas