Commit 9cd6ecfe authored by Anel Husakovic's avatar Anel Husakovic

MDEV-18284: JSON casting using JSON_COMPACT doesn't always work with values from subqueries

- Cherry-pick 2fcff310 (MDEV-21902)
- Closed PR #1145
Reviewed by: holyfoot@mariadb.com
parent 410c4ede
......@@ -940,5 +940,23 @@ SELECT JSON_REPLACE( JSON_DETAILED('["x"]'), '$.a', 'xx' );
JSON_REPLACE( JSON_DETAILED('["x"]'), '$.a', 'xx' )
["x"]
#
# MDEV-18284 JSON casting using JSON_COMPACT doesn't always work
# with values from subqueries
#
CREATE TABLE json_test(a JSON, b JSON);
INSERT INTO json_test VALUES ("[1,2,3]", '{"a":"foo"}');
SELECT * FROM json_test;
a b
[1,2,3] {"a":"foo"}
SELECT json_object("a", json_compact(a), "b", b)
FROM (SELECT * FROM json_test) AS json_test_values;
json_object("a", json_compact(a), "b", b)
{"a": [1,2,3], "b": "{\"a\":\"foo\"}"}
SELECT json_object("a", json_compact(a), "b", json_compact(b))
FROM (SELECT * FROM json_test) AS json_test_values;
json_object("a", json_compact(a), "b", json_compact(b))
{"a": [1,2,3], "b": {"a":"foo"}}
DROP TABLE json_test;
#
# End of 10.2 tests
#
......@@ -560,6 +560,21 @@ SELECT
SELECT JSON_REPLACE( JSON_DETAILED('["x"]'), '$.a', 'xx' );
--echo #
--echo # MDEV-18284 JSON casting using JSON_COMPACT doesn't always work
--echo # with values from subqueries
--echo #
CREATE TABLE json_test(a JSON, b JSON);
INSERT INTO json_test VALUES ("[1,2,3]", '{"a":"foo"}');
SELECT * FROM json_test;
SELECT json_object("a", json_compact(a), "b", b)
FROM (SELECT * FROM json_test) AS json_test_values;
SELECT json_object("a", json_compact(a), "b", json_compact(b))
FROM (SELECT * FROM json_test) AS json_test_values;
DROP TABLE json_test;
--echo #
--echo # End of 10.2 tests
--echo #
......@@ -4564,6 +4564,7 @@ class Item_ref :public Item_ident
{
return ref ? (*ref)->real_item() : this;
}
bool is_json_type() { return (*ref)->is_json_type(); }
bool walk(Item_processor processor, bool walk_subquery, void *arg)
{
if (ref && *ref)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment