简体   繁体   中英

SQL Query on AWS IoT Rule JSON key starts with number

I've been at this for a few hours and can't figure it out. So I thought maybe someone here would have an idea.

I have JSON which is being published to a thing shadow(format of JSON being posted is not under my control). The JSON looks like this:

{"state":{"reported":{"0013A20011223344":{"input_1":1}}}}

I tried this query statement which would be used to send a publish to SNS:

SELECT "input closed" AS default FROM "$aws/things/Cell_Test_Thing/shadow/update" WHERE state.reported.0013A200418C5535.input_1 = 1

The problem is the SQL query does not like that key starting with a 0. I determined this by replacing 0013... with device here and it worked perfectly:

SELECT "input closed" AS default FROM "$aws/things/Cell_Test_Thing/shadow/update" WHERE state.reported.device.input_1 = 1

So the problem is that JSON key beginning with a number. If I change device to device0 it works but if you change it to 0device it fails. From what I can determine it is perfectly valid to start a JSON key with a number so hopefully there is a work around for this.

Ideas?

Try this:

SELECT "input closed" AS default 
FROM "$aws/things/Cell_Test_Thing/shadow/update" 
WHERE "state"."reported"."0013A200418C5535"."input_1" = 1

Each part of the name must be in quotes. This is because the name has a structure in four parts.

Why can't you just use one set of quotes? Think about it this way. The four-part name "state"."reported"."0013A200418C5535"."input_1" has four parts, separated by dots. But what if one of those parts had a dot in it?

(Technically only parts which contain certain characters need to be quoted, but sometimes it's easier just to do them all).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM