gpt4 book ai didi

MySQL JSON_EXTRACT 路径表达式错误

转载 作者:IT老高 更新时间:2023-10-29 00:19:55 25 4
gpt4 key购买 nike

语法对我来说是正确的,任何帮助将不胜感激!

mysql> select fieldnames from tablename limit 5;
+--------------------------------------------------------+
| fieldnames |
+--------------------------------------------------------+
| {"example-field-1": "val2"} |
| {"example-field-2": "val1"} |
| {"example-field-1": "val1", "example-field-3": "val1"} |
| {"example-field-2": "val1"} |
| {"example-field-2": "val2"} |
+--------------------------------------------------------+
mysql> select JSON_EXTRACT(fieldnames, '$.example-field-1') from tablename;
ERROR 3143 (42000): Invalid JSON path expression. The error is around character position 17 in '$.example-field-1'.

MySQL 5.7.10

最佳答案

你能试试这个来自 https://dev.mysql.com/doc/refman/5.7/en/json.html 的建议吗?

As mentioned previously, path components that name keys must be quotedif the unquoted key name is not legal in path expressions. Let $ referto this value.

select JSON_EXTRACT(fieldnames, '$."example-field-1"') from tablename;

注意

如果你有更多的字段,你必须引用每个键而不是整个路径:

select JSON_EXTRACT(fieldnames, '$."field"."example-field-1"') from tablename;

关于MySQL JSON_EXTRACT 路径表达式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35735454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com