在数组中搜索 JSON 数据类型的对象 属性 时出现问题

Issue with searching for object property in array for JSON data type

我有以下架构 value 作为 JSON 类型

mysql> select * from people;
+------+---------------------------------------------------------------------------+
| id   | value                                                                     |
+------+---------------------------------------------------------------------------+
| blah | {"key1": "value1", "key2": "value2"}                                      |
| foo  | {"key1": "value1", "friends": [{"friendId": "123"}, {"friendId": "foo"}]} |
+------+---------------------------------------------------------------------------+

我希望下面的查询到 return 我行 foo 但它没有。

mysql> select * from people where value->'$.friends[*].friendId' = "123";
Empty set 

条件 value->'$.friends[*].friendId' 似乎有效,因为它适用于以下查询:

mysql> select value->'$.friends[*].friendId' from people;
+---------------------------------+
| value->'$.friends[*].friendId' |
+---------------------------------+
| NULL                            |
| ["123", "foo"]                  |
+---------------------------------+

那么查询select * from people where value->'$.friends[*].friendId' = "123";return怎么没有结果呢?

JSON_CONTAINS 与我感兴趣的 JSON 数组值结合使用:

select * from people where JSON_CONTAINS (value, {"friends": [{"friendId": "123"}]});