diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index 4e03a867d8d..c7e6e2f7374 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -34,6 +34,9 @@ NULL select json_query('{"key1":123, "key1": [1,2,3]}', '$.key1'); json_query('{"key1":123, "key1": [1,2,3]}', '$.key1') [1,2,3] +select json_array(); +json_array() +[] select json_array(1); json_array(1) [1] @@ -150,6 +153,9 @@ json_remove(@j, '$.b') select json_remove(@j, '$.a'); json_remove(@j, '$.a') {"b": [2, 3]} +select json_object(); +json_object() +{} select json_object("ki", 1, "mi", "ya"); json_object("ki", 1, "mi", "ya") {"ki": 1, "mi": "ya"} diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index 017a9c4e84b..6f382512998 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -13,6 +13,7 @@ select json_query('{"key1":{"a":1, "b":[1,2]}}', '$.key1'); select json_query('{"key1": 1}', '$.key1'); select json_query('{"key1":123, "key1": [1,2,3]}', '$.key1'); +select json_array(); select json_array(1); select json_array(1, "text", false, null); @@ -63,6 +64,7 @@ set @j = '{"a": 1, "b": [2, 3]}'; select json_remove(@j, '$.b'); select json_remove(@j, '$.a'); +select json_object(); select json_object("ki", 1, "mi", "ya"); select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2"); diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index fff467c92ae..65c2f65920e 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -877,6 +877,14 @@ void Item_func_json_array::fix_length_and_dec() ulonglong char_length= 4; uint n_arg; + if (arg_count == 0) + { + collation.set(&my_charset_utf8_general_ci); + tmp_val.set_charset(&my_charset_utf8_general_ci); + max_length= 2; + return; + } + if (agg_arg_charsets_for_string_result(collation, args, arg_count)) return;