Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions mysql-test/main/func_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -5764,4 +5764,16 @@ NULL NULL NULL NULL NULL NULL NULL NULL
{"key": "value", "key2": "value2"} 1 0 0 1 0 1 1
{"key": "value", "key": "value2"} 1 0 0 1 0 0 1
DROP TABLE test_default_json;
SELECT json_extract(t.j, '$')
FROM (SELECT json_extract('["a",1]', '$') AS j) AS t;
json_extract(t.j, '$')
["a", 1]
SELECT json_extract(t.j, '$[0]')
FROM (SELECT json_extract('["a",1]', '$') AS j) AS t;
json_extract(t.j, '$[0]')
"a"
SELECT json_extract(t.j, '$')
FROM (SELECT json_extract('{"key":"value"}', '$') AS j) AS t;
json_extract(t.j, '$')
{"key": "value"}
# End of 12.3
9 changes: 9 additions & 0 deletions mysql-test/main/func_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -4489,4 +4489,13 @@ FROM test_default_json;

DROP TABLE test_default_json;

SELECT json_extract(t.j, '$')
FROM (SELECT json_extract('["a",1]', '$') AS j) AS t;

SELECT json_extract(t.j, '$[0]')
FROM (SELECT json_extract('["a",1]', '$') AS j) AS t;

SELECT json_extract(t.j, '$')
FROM (SELECT json_extract('{"key":"value"}', '$') AS j) AS t;

--echo # End of 12.3
7 changes: 6 additions & 1 deletion sql/item_jsonfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,12 @@ bool Item_json_str_multipath::fix_length_and_dec(THD *thd)
bool Item_func_json_extract::fix_length_and_dec(THD *thd)
{
collation.set(args[0]->collation);
max_length= args[0]->max_length * (arg_count - 1);
/*
json_extract() passes its result through json_nice() with LOOSE format,
which can expand the output (e.g. adding spaces after commas and colons).
Multiply by 2 to account for this, matching JSON_FORMAT(LOOSE) behavior.
*/
max_length= args[0]->max_length * (arg_count - 1) * 2;

mark_constant_paths(paths, args+1, arg_count-1);
set_maybe_null();
Expand Down