Bug #103690 Can't use ->> with an expression for the path
Submitted: 13 May 23:30 Modified: 14 May 11:50
Reporter: Justin Levene Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: JSON Severity:S4 (Feature request)
Version:8.0.23, 8.0.25 OS:Any
Assigned to: CPU Architecture:Any

[13 May 23:30] Justin Levene
Description:
when using json->>"$.a" is fine,however using json->>concat("$.", "a") does not work

How to repeat:
select json_value('{"a":1, "b":2, "c":3}', "$.b"); is fine

The following do not work:

select json_value('{"a":1, "b":2, "c":3}', concat("$.","b") );

or

set @path = "$.b";
select json_value('{"a":1, "b":2, "c":3}', @path);

Suggested fix:
Allow expressions and variables in the path
[13 May 23:32] Justin Levene
Also you can't use json->>concat("$.", "a")
[14 May 6:36] MySQL Verification Team
Hello Justin Levene,

Thank you for the report and feedback.

regards,
Umesh
[14 May 11:29] Knut Anders Hatlen
Thanks for the bug report.

WL#9124, which added the ->> syntax, mentions that only a string literal is accepted for the path. It doesn't mention why only string literals are accepted, but I seem to recall it would require some bigger changes in the parser to support more complex expressions, so only the limited syntax was implemented.

WL#12228, which added JSON_VALUE, also says the path has to be a string literal. In this case, the SQL standard specifies that <JSON path specification> ::= <character string literal>, so allowing expressions would be an extension to the standard syntax.

Since this is a request for implementing more syntax, I'm reclassifying it from bug to feature request.
[14 May 11:50] Knut Anders Hatlen
Closing as a duplicate of bug#87360.