diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index 6ef294400d3..6d0e02b7d16 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -55,18 +55,21 @@ json_array_append('["a", "b"]', '$', FALSE) select json_array_append('{"k1":1, "k2":["a", "b"]}', '$.k2', 2); json_array_append('{"k1":1, "k2":["a", "b"]}', '$.k2', 2) {"k1":1, "k2":["a", "b", 2]} -SELECT JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[1]', 'x'); -JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[1]', 'x') +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1]', 'x'); +json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1]', 'x') ["a", "x", {"b": [1, 2]}, [3, 4]] -SELECT JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[2]', 'x'); -JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[2]', 'x') +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[2]', 'x'); +json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[2]', 'x') ["a", {"b": [1, 2]}, "x", [3, 4]] -SELECT JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[3]', 'x'); -JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[3]', 'x') +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[3]', 'x'); +json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[3]', 'x') ["a", {"b": [1, 2]}, [3, 4], "x"] -SELECT JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x'); -JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x') +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x'); +json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x') ["a", {"b": [1, 2]}, [3, 4], "x"] +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1].b[0]', 'x'); +json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1].b[0]', 'x') +["a", {"b": [ "x",1, 2]}, [3, 4]] select json_contains('{"k1":123, "k2":345}', '123', '$.k1'); json_contains('{"k1":123, "k2":345}', '123', '$.k1') 1 diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index 2a23bedfbd4..21c18a22f80 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -22,10 +22,11 @@ select json_array(1, "text", false, null); select json_array_append('["a", "b"]', '$', FALSE); select json_array_append('{"k1":1, "k2":["a", "b"]}', '$.k2', 2); -SELECT JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[1]', 'x'); -SELECT JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[2]', 'x'); -SELECT JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[3]', 'x'); -SELECT JSON_ARRAY_INSERT('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x'); +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1]', 'x'); +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[2]', 'x'); +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[3]', 'x'); +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x'); +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1].b[0]', 'x'); select json_contains('{"k1":123, "k2":345}', '123', '$.k1'); select json_contains('"you"', '"you"'); diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 2cdf1301267..9a625d0e1ca 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -1051,7 +1051,7 @@ String *Item_func_json_array_insert::val_str(String *str) if (s_p && (json_path_setup(&c_path->p,s_p->charset(),(const uchar *) s_p->ptr(), (const uchar *) s_p->ptr() + s_p->length()) || - c_path->p.last_step - 1 > c_path->p.steps || + c_path->p.last_step - 1 < c_path->p.steps || c_path->p.last_step->type != JSON_PATH_ARRAY)) goto error; c_path->parsed= c_path->constant;