简体   繁体   English

AWS IoT规则JSON密钥上的SQL查询以数字开头

[英]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). 我有正在发布到事物阴影的JSON(要发布的JSON格式不受我的控制)。 The JSON looks like this: JSON如下所示:

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

I tried this query statement which would be used to send a publish to SNS: 我尝试了以下查询语句,该语句将用于向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: 问题是SQL查询不喜欢以0开头的键。我通过将0013 ...替换为此处的设备来确定了这一点,它工作得很好:

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. 因此,问题在于JSON密钥以数字开头。 If I change device to device0 it works but if you change it to 0device it fails. 如果我将设备更改为device0,则可以使用,但是如果将其更改为0device,则它将失败。 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. 根据我的判断,以数字开头的JSON密钥完全有效,因此希望可以解决此问题。

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. 由四部分组成的名称"state"."reported"."0013A200418C5535"."input_1"具有四部分,以点分隔。 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). (从技术上讲,只需要引用包含某些字符的部分,但有时仅将它们全部引用会更容易)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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