Bug #112316 Sample SQL of JSON_VALUE() function cannot be executed
Submitted: 12 Sep 2023 3:13 Modified: 16 Oct 2023 17:51
Reporter: Tomoko Hara Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: Jon Stephens CPU Architecture:Any

[12 Sep 2023 3:13] Tomoko Hara
Description:
https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html

This SQL described in the JSON_VALUE() function description field cannot be executed:

SELECT name, price FROM t1
    WHERE JSON_VALUE(j, '$.id' RETURNING UNSIGNED) = 123;

JSON is not specified in the SELECT statement. This SQL is executable:

SELECT j->"$.name" as name, j->"$.price" as price FROM t1
    WHERE JSON_VALUE(j, '$.id' RETURNING UNSIGNED) = 123;

Write the execution log:

mysql> CREATE TABLE t1(
    ->     j JSON,
    ->     INDEX i1 ( (JSON_VALUE(j, '$.id' RETURNING UNSIGNED)) )
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> INSERT INTO t1 VALUES ROW('{"id": "123", "name": "shoes", "price": "49.95"}');
Query OK, 1 row affected (0.01 sec)

mysql> SELECT name, price FROM t1
    ->     WHERE JSON_VALUE(j, '$.id' RETURNING UNSIGNED) = 123;
ERROR 1054 (42S22): Unknown column 'name' in 'field list'

mysql> SELECT j->"$.name" as name, j->"$.price" as price FROM t1
    ->     WHERE JSON_VALUE(j, '$.id' RETURNING UNSIGNED) = 123;
+---------+---------+
| name    | price   |
+---------+---------+
| "shoes" | "49.95" |
+---------+---------+
1 row in set (0.00 sec)

mysql>

If you have a better SELECT statement, make it better SQL.

How to repeat:
See description
[12 Sep 2023 7:45] MySQL Verification Team
Hello Tomoko Hara,

Thank you for the report and feedback.

regards,
Umesh
[16 Oct 2023 17:51] Jon Stephens
Fixed in mysqldoc rev 76968.

Thanks!