AWS IoT Core sql 查询规则 - 比较 2 个对象数组 returns null/undefined?

AWS IoT Core sql query rule - Comparing 2 object arrays returns null/undefined?

我正在尝试比较 sql 查询中的 2 个数组。从 dynamodb 和 MQTT 代理服务器获取数据时,一切似乎都工作正常。 但是,如果我尝试比较两个数组,return 没有任何东西或其未定义。

我的sql查询:

SELECT ts, objects, (SELECT id FROM get_dynamodb('table', 'key_name', 'key_value', 'rolearn').ids) AS db, (SELECT id from objects) as obj_ids
FROM 'subscribed/topic'
WHERE objects <> []

结果:

{
   "ts": 1615807935588,
   "objects": [
      {
         "id": 1,
         "planet": "jupiter"
      },
      {
         "id": 2,
         "planet": "mars"
      },
   ],
   "db": [
      {
         "id": 2
      },
      {
         "id": 3
      }
   ],
   "obj_ids": [
      {
         "id": 1
      },
      {
         "id": 2
      }
   ]
}

到目前为止一切正常,现在我想做的就是比较“obj_ids”和“db”数组是否不同(obj_ids <> db),并通过 aws 文档 https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-operators.html#iot-sql-operators-not-eq 我可以比较两个数组。

所以如果我这样做:

SELECT ts, objects, (SELECT id FROM get_dynamodb('table', 'key_name', 'key_value', 'rolearn').ids) AS db, (SELECT id from objects) as obj_ids
FROM 'subscribed/topic'
WHERE objects <> []
AND obj_ids <> db

代码没有 return 任何内容。我已经测试过比较硬编码到查询中的 2 个对象数组,它按我的预期工作。

SELECT ([{"id": 1},{"id": 2}] <> [{"id": 1}]) as result
FROM 'subscribed/topic'

结果:

{
   "result": true
}

如有任何回应,我们将不胜感激。 谢谢!

学分来自 Ben T

正如AWS Docs WHERE clause所说:

"you cannot reference any aliases created with the AS keyword in the SELECT. The WHERE clause is evaluated first, to determine if SELECT is evaluated."

所以我需要做的就是将 (SELECT id FROM get_dynamodb('table', 'key_name', 'key_value', 'rolearn').ids)(SELECT id from objects) 移动到 WHERE 子句。

最终查询:

SELECT ts, objects
FROM 'subscribed/topic'
WHERE objects <> []
AND (SELECT id from objects) <> (SELECT id FROM get_dynamodb('table', 'key_name', 'key_value', 'rolearn').ids)