mysqlmariadbjson-search

JSON_SEARCH difference in MySQL and MariaDB


I just try to get path of value using JSON_SEARCH function:

SELECT JSON_SEARCH('[12, 13, {"12": 123}]', 'one', '123', null, '$[*]') path;

When I run this query in MariaDB it works and I got desired result

+===========+
| path      |
+===========+
| "$[2].12" |
+-----------+

but run same query on top MySQL 8.0 I got NULL

So I need help how to match the query for use it with MySQL


Solution

  • Bug #79233: JSON_SEARCH does not search for non-string values

    If your JSON scalar values are strings, you can find them:

    mysql> SELECT JSON_SEARCH('[12, 13, {"12": "123"}]', 'one', '123', null, '$[*]') path;
                                               ^^^^^ quoted string value
    +---------------+
    | path          |
    +---------------+
    | "$[2].\"12\"" |
    +---------------+