MySQL JSON_EXTRACT路径表达式错误

时间:2021-09-16 15:06:55

The syntax looks right to me, any help would be appreciated!

语法看起来对我来说,任何帮助将不胜感激!

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

MySQL 5.7.10

1 个解决方案

#1


11  

Can you try this advice from https://dev.mysql.com/doc/refman/5.7/en/json.html

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

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

如前所述,如果路径表达式中的未加引号的键名称不合法,则必须引用命名键的路径组件。让$引用这个值。

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

#1


11  

Can you try this advice from https://dev.mysql.com/doc/refman/5.7/en/json.html

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

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

如前所述,如果路径表达式中的未加引号的键名称不合法,则必须引用命名键的路径组件。让$引用这个值。

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