summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2017-02-14 11:11:47 +0100
committerSergei Golubchik <serg@mariadb.org>2017-02-14 20:43:41 +0100
commit6f6d0531dca711f13842cfca761afd073c595f57 (patch)
treeb46a9f617e86bcca3a19d24bb2f8c5f9c31ff182
parente0fa2ce40f03add01bb3d934480e74e3ee64dd6c (diff)
downloadmariadb-git-6f6d0531dca711f13842cfca761afd073c595f57.tar.gz
MDEV-11439 No data type JSON, but CAST(something AS JSON) pretends to work
Use JSON_COMPACT(X) instead of CAST(X AS JSON). Bonus - X is validated to be a valid JSON. Fix a typo in the error message.
-rw-r--r--mysql-test/r/func_json.result12
-rw-r--r--mysql-test/suite/json/r/json_no_table.result742
-rw-r--r--mysql-test/suite/json/t/json_no_table.test414
-rw-r--r--mysql-test/t/func_json.test6
-rw-r--r--sql/item.h2
-rw-r--r--sql/item_create.cc3
-rw-r--r--sql/item_func.h2
-rw-r--r--sql/item_jsonfunc.cc70
-rw-r--r--sql/item_jsonfunc.h15
-rw-r--r--sql/share/errmsg-utf8.txt2
-rw-r--r--sql/sql_yacc.yy1
11 files changed, 636 insertions, 633 deletions
diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result
index 4c1c82ed331..91640974b22 100644
--- a/mysql-test/r/func_json.result
+++ b/mysql-test/r/func_json.result
@@ -402,14 +402,14 @@ json_object("a", json_object("b", "abcd"))
select json_object("a", '{"b": "abcd"}');
json_object("a", '{"b": "abcd"}')
{"a": "{\"b\": \"abcd\"}"}
-select json_object("a", cast('{"b": "abcd"}' as json));
-json_object("a", cast('{"b": "abcd"}' as json))
+select json_object("a", json_compact('{"b": "abcd"}'));
+json_object("a", json_compact('{"b": "abcd"}'))
{"a": {"b": "abcd"}}
-select cast(NULL AS JSON);
-cast(NULL AS JSON)
+select json_compact(NULL);
+json_compact(NULL)
NULL
-select json_depth(cast(NULL as JSON));
-json_depth(cast(NULL as JSON))
+select json_depth(json_compact(NULL));
+json_depth(json_compact(NULL))
NULL
select json_depth('[[], {}]');
json_depth('[[], {}]')
diff --git a/mysql-test/suite/json/r/json_no_table.result b/mysql-test/suite/json/r/json_no_table.result
index 7265c4a9f30..cf4cd5b8af8 100644
--- a/mysql-test/suite/json/r/json_no_table.result
+++ b/mysql-test/suite/json/r/json_no_table.result
@@ -1,34 +1,36 @@
-SELECT CAST(0.0e0 AS JSON) = -0.0e0;
-CAST(0.0e0 AS JSON) = -0.0e0
+SELECT JSON_COMPACT(0.0e0) = -0.0e0;
+JSON_COMPACT(0.0e0) = -0.0e0
1
-SELECT CAST(CAST(0 AS DECIMAL) AS JSON) = CAST(-0.0e0 AS DECIMAL);
-CAST(CAST(0 AS DECIMAL) AS JSON) = CAST(-0.0e0 AS DECIMAL)
+SELECT JSON_COMPACT(CAST(0 AS DECIMAL)) = CAST(-0.0e0 AS DECIMAL);
+JSON_COMPACT(CAST(0 AS DECIMAL)) = CAST(-0.0e0 AS DECIMAL)
1
-SELECT CAST(0.0e0 AS JSON) = CAST(-0.0e0 AS DECIMAL);
-CAST(0.0e0 AS JSON) = CAST(-0.0e0 AS DECIMAL)
+SELECT JSON_COMPACT(0.0e0) = CAST(-0.0e0 AS DECIMAL);
+JSON_COMPACT(0.0e0) = CAST(-0.0e0 AS DECIMAL)
1
-SELECT CAST(CAST(0 AS DECIMAL) AS JSON) = -0.0e0;
-CAST(CAST(0 AS DECIMAL) AS JSON) = -0.0e0
+SELECT JSON_COMPACT(CAST(0 AS DECIMAL)) = -0.0e0;
+JSON_COMPACT(CAST(0 AS DECIMAL)) = -0.0e0
1
-SELECT CAST(CAST(0 AS SIGNED) AS JSON) = -0.0e0;
-CAST(CAST(0 AS SIGNED) AS JSON) = -0.0e0
+SELECT JSON_COMPACT(CAST(0 AS SIGNED)) = -0.0e0;
+JSON_COMPACT(CAST(0 AS SIGNED)) = -0.0e0
1
-SELECT CAST(CAST(0 AS SIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL);
-CAST(CAST(0 AS SIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL)
+SELECT JSON_COMPACT(CAST(0 AS SIGNED)) = CAST(-0.0e0 AS DECIMAL);
+JSON_COMPACT(CAST(0 AS SIGNED)) = CAST(-0.0e0 AS DECIMAL)
1
-SELECT CAST(CAST(0 AS UNSIGNED) AS JSON) = -0.0e0;
-CAST(CAST(0 AS UNSIGNED) AS JSON) = -0.0e0
+SELECT JSON_COMPACT(CAST(0 AS UNSIGNED)) = -0.0e0;
+JSON_COMPACT(CAST(0 AS UNSIGNED)) = -0.0e0
1
-SELECT CAST(CAST(0 AS UNSIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL);
-CAST(CAST(0 AS UNSIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL)
+SELECT JSON_COMPACT(CAST(0 AS UNSIGNED)) = CAST(-0.0e0 AS DECIMAL);
+JSON_COMPACT(CAST(0 AS UNSIGNED)) = CAST(-0.0e0 AS DECIMAL)
1
-select cast('"abc"' as json);
-cast('"abc"' as json)
+select json_compact('"abc"');
+json_compact('"abc"')
"abc"
error ER_INVALID_JSON_TEXT_IN_PARAM
-select cast('abc' as json);
-cast('abc' as json)
-abc
+select json_compact('abc');
+json_compact('abc')
+NULL
+Warnings:
+Warning 4038 Syntax error in JSON text in argument 1 to function 'json_compact' at position 1
# String literal - valid JSON
select JSON_VALID('123');
@@ -75,13 +77,13 @@ JSON_VALID('123')
set names 'utf8';
# Json expression
-select JSON_VALID(cast('[123]' as JSON ));
-JSON_VALID(cast('[123]' as JSON ))
+select JSON_VALID(json_compact('[123]'));
+JSON_VALID(json_compact('[123]'))
1
# Json expression NULL
-select JSON_VALID(cast(NULL as JSON ));
-JSON_VALID(cast(NULL as JSON ))
+select JSON_VALID(json_compact(NULL));
+JSON_VALID(json_compact(NULL))
NULL
# Bare NULL
@@ -111,8 +113,8 @@ select JSON_VALID( CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8')
JSON_VALID( CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8') )
0
# OK, though:
-select JSON_VALID( CAST(CURDATE() as JSON) );
-JSON_VALID( CAST(CURDATE() as JSON) )
+select JSON_VALID( json_compact(CURDATE()) );
+JSON_VALID( json_compact(CURDATE()) )
0
# Function result - NULL
@@ -485,20 +487,20 @@ NULL
select json_depth(null);
json_depth(null)
NULL
-select json_depth(cast(null as json));
-json_depth(cast(null as json))
+select json_depth(json_compact(null));
+json_depth(json_compact(null))
NULL
-select json_depth(cast('[]' as json)),
-json_depth(cast('{}' as json)),
-json_depth(cast('null' as json)),
+select json_depth(json_compact('[]')),
+json_depth(json_compact('{}')),
+json_depth(json_compact('null')),
json_depth(json_quote('foo'));
-json_depth(cast('[]' as json)) json_depth(cast('{}' as json)) json_depth(cast('null' as json)) json_depth(json_quote('foo'))
+json_depth(json_compact('[]')) json_depth(json_compact('{}')) json_depth(json_compact('null')) json_depth(json_quote('foo'))
1 1 1 1
-select json_depth(cast('[[2], 3, [[[4]]]]' as json));
-json_depth(cast('[[2], 3, [[[4]]]]' as json))
+select json_depth(json_compact('[[2], 3, [[[4]]]]'));
+json_depth(json_compact('[[2], 3, [[[4]]]]'))
5
-select json_depth(cast('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}' as json));
-json_depth(cast('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}' as json))
+select json_depth(json_compact('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}'));
+json_depth(json_compact('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}'))
6
SELECT JSON_DEPTH
(
@@ -521,8 +523,8 @@ JSON_DEPTH
SELECT JSON_DEPTH( '"abc"' );
JSON_DEPTH( '"abc"' )
1
-SELECT JSON_DEPTH( CAST( '"abc"' AS JSON ) );
-JSON_DEPTH( CAST( '"abc"' AS JSON ) )
+SELECT JSON_DEPTH( json_compact( '"abc"') );
+JSON_DEPTH( json_compact( '"abc"') )
1
error ER_INVALID_TYPE_FOR_JSON
SELECT JSON_DEPTH( 1 );
@@ -534,8 +536,8 @@ JSON_DEPTH( 'abc' )
NULL
Warnings:
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_depth' at position 1
-SELECT JSON_DEPTH( CAST( 1 AS JSON ) );
-JSON_DEPTH( CAST( 1 AS JSON ) )
+SELECT JSON_DEPTH( json_compact( 1) );
+JSON_DEPTH( json_compact( 1) )
1
SELECT JSON_DEPTH
(
@@ -1002,168 +1004,184 @@ select json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'));
json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'))
INTEGER
# ----------------------------------------------------------------------
-# Test of CAST(literal AS JSON)
+# Test of json_compact(literal)
# ----------------------------------------------------------------------
-select json_type(cast(cast('2014-11-25 18:00' as datetime) as json));
-json_type(cast(cast('2014-11-25 18:00' as datetime) as json))
+select json_type(json_compact(cast('2014-11-25 18:00' as datetime)));
+json_type(json_compact(cast('2014-11-25 18:00' as datetime)))
INTEGER
-select json_type(cast(cast('2014-11-25' as date) as json));
-json_type(cast(cast('2014-11-25' as date) as json))
+select json_type(json_compact(cast('2014-11-25' as date)));
+json_type(json_compact(cast('2014-11-25' as date)))
INTEGER
-select json_type(cast(cast('18:00:59' as time) as json));
-json_type(cast(cast('18:00:59' as time) as json))
+select json_type(json_compact(cast('18:00:59' as time)));
+json_type(json_compact(cast('18:00:59' as time)))
INTEGER
-select json_type(cast(127 as json));
-json_type(cast(127 as json))
+select json_type(json_compact(127));
+json_type(json_compact(127))
INTEGER
-select json_type(cast(255 as json));
-json_type(cast(255 as json))
+select json_type(json_compact(255));
+json_type(json_compact(255))
INTEGER
-select json_type(cast(32767 as json));
-json_type(cast(32767 as json))
+select json_type(json_compact(32767));
+json_type(json_compact(32767))
INTEGER
-select json_type(cast(65535 as json));
-json_type(cast(65535 as json))
+select json_type(json_compact(65535));
+json_type(json_compact(65535))
INTEGER
-select json_type(cast(8388607 as json));
-json_type(cast(8388607 as json))
+select json_type(json_compact(8388607));
+json_type(json_compact(8388607))
INTEGER
-select json_type(cast(16777215 as json));
-json_type(cast(16777215 as json))
+select json_type(json_compact(16777215));
+json_type(json_compact(16777215))
INTEGER
-select json_type(cast(2147483647 as json));
-json_type(cast(2147483647 as json))
+select json_type(json_compact(2147483647));
+json_type(json_compact(2147483647))
INTEGER
-select json_type(cast(4294967295 as json));
-json_type(cast(4294967295 as json))
+select json_type(json_compact(4294967295));
+json_type(json_compact(4294967295))
INTEGER
-select json_type(cast(9223372036854775807 as json));
-json_type(cast(9223372036854775807 as json))
+select json_type(json_compact(9223372036854775807));
+json_type(json_compact(9223372036854775807))
INTEGER
-select json_type(cast(18446744073709551615 as json));
-json_type(cast(18446744073709551615 as json))
+select json_type(json_compact(18446744073709551615));
+json_type(json_compact(18446744073709551615))
INTEGER
-select json_type(cast(true as json));
-json_type(cast(true as json))
+select json_type(json_compact(true));
+json_type(json_compact(true))
INTEGER
-select json_type(cast(b'10101' as json));
-json_type(cast(b'10101' as json))
+select json_type(json_compact(b'10101'));
+json_type(json_compact(b'10101'))
NULL
Warnings:
-Warning 4036 Character disallowd in JSON in argument 1 to function 'json_type' at position 1
-select json_type(cast(cast(3.14 as decimal(5,2)) as json));
-json_type(cast(cast(3.14 as decimal(5,2)) as json))
+Warning 4036 Character disallowed in JSON in argument 1 to function 'json_type' at position 1
+select json_type(json_compact(cast(3.14 as decimal(5,2))));
+json_type(json_compact(cast(3.14 as decimal(5,2))))
DOUBLE
-select json_type(cast(3.14 as json));
-json_type(cast(3.14 as json))
+select json_type(json_compact(3.14));
+json_type(json_compact(3.14))
DOUBLE
-select json_type(cast(3.14E30 as json));
-json_type(cast(3.14E30 as json))
+select json_type(json_compact(3.14E30));
+json_type(json_compact(3.14E30))
NULL
Warnings:
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 7
-select json_type(cast(cast('10101abcde' as binary) as json));
-json_type(cast(cast('10101abcde' as binary) as json))
+select json_type(json_compact(cast('10101abcde' as binary)));
+json_type(json_compact(cast('10101abcde' as binary)))
INTEGER
-select json_type(cast(ST_GeomFromText('POINT(1 1)') as json));
-json_type(cast(ST_GeomFromText('POINT(1 1)') as json))
+select json_type(json_compact(ST_GeomFromText('POINT(1 1)')));
+json_type(json_compact(ST_GeomFromText('POINT(1 1)')))
NULL
Warnings:
-Warning 4036 Character disallowd in JSON in argument 1 to function 'json_type' at position 1
-select json_type(cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json));
-json_type(cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json))
+Warning 4036 Character disallowed in JSON in argument 1 to function 'json_type' at position 1
+select json_type(json_compact(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)')));
+json_type(json_compact(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)')))
NULL
Warnings:
-Warning 4036 Character disallowd in JSON in argument 1 to function 'json_type' at position 1
-select json_type(cast(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
- (5 5,7 5,7 7,5 7, 5 5))') as json));
-json_type(cast(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
- (5 5,7 5,7 7,5 7, 5 5))') as json))
+Warning 4036 Character disallowed in JSON in argument 1 to function 'json_type' at position 1
+select json_type(json_compact(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
+ (5 5,7 5,7 7,5 7, 5 5))')));
+json_type(json_compact(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
+ (5 5,7 5,7 7,5 7, 5 5))')))
NULL
Warnings:
-Warning 4036 Character disallowd in JSON in argument 1 to function 'json_type' at position 1
-select json_type(cast(null as json));
-json_type(cast(null as json))
+Warning 4036 Character disallowed in JSON in argument 1 to function 'json_type' at position 1
+select json_type(json_compact(null));
+json_type(json_compact(null))
NULL
-select json_type(cast(null as json)) is null;
-json_type(cast(null as json)) is null
+select json_type(json_compact(null)) is null;
+json_type(json_compact(null)) is null
1
select json_type(null) is null;
json_type(null) is null
1
-select cast(cast('2014-11-25 18:00' as datetime) as json);
-cast(cast('2014-11-25 18:00' as datetime) as json)
-2014-11-25 18:00:00
-select cast(cast('2014-11-25' as date) as json);
-cast(cast('2014-11-25' as date) as json)
-2014-11-25
-select cast(cast('18:00:59' as time) as json);
-cast(cast('18:00:59' as time) as json)
-18:00:59
-select cast(127 as json);
-cast(127 as json)
+select json_compact(cast('2014-11-25 18:00' as datetime));
+json_compact(cast('2014-11-25 18:00' as datetime))
+NULL
+Warnings:
+Warning 4038 Syntax error in JSON text in argument 1 to function 'json_compact' at position 5
+select json_compact(cast('2014-11-25' as date));
+json_compact(cast('2014-11-25' as date))
+NULL
+Warnings:
+Warning 4038 Syntax error in JSON text in argument 1 to function 'json_compact' at position 5
+select json_compact(cast('18:00:59' as time));
+json_compact(cast('18:00:59' as time))
+NULL
+Warnings:
+Warning 4038 Syntax error in JSON text in argument 1 to function 'json_compact' at position 3
+select json_compact(127);
+json_compact(127)
127
-select cast(255 as json);
-cast(255 as json)
+select json_compact(255);
+json_compact(255)
255
-select cast(32767 as json);
-cast(32767 as json)
+select json_compact(32767);
+json_compact(32767)
32767
-select cast(65535 as json);
-cast(65535 as json)
+select json_compact(65535);
+json_compact(65535)
65535
-select cast(8388607 as json);
-cast(8388607 as json)
+select json_compact(8388607);
+json_compact(8388607)
8388607
-select cast(16777215 as json);
-cast(16777215 as json)
+select json_compact(16777215);
+json_compact(16777215)
16777215
-select cast(2147483647 as json);
-cast(2147483647 as json)
+select json_compact(2147483647);
+json_compact(2147483647)
2147483647
-select cast(4294967295 as json);
-cast(4294967295 as json)
+select json_compact(4294967295);
+json_compact(4294967295)
4294967295
-select cast(9223372036854775807 as json);
-cast(9223372036854775807 as json)
+select json_compact(9223372036854775807);
+json_compact(9223372036854775807)
9223372036854775807
-select cast(18446744073709551615 as json);
-cast(18446744073709551615 as json)
+select json_compact(18446744073709551615);
+json_compact(18446744073709551615)
18446744073709551615
-select cast(true as json);
-cast(true as json)
-1
-select cast(b'10101' as json);
-cast(b'10101' as json)
-
-select cast(cast(3.14 as decimal(5,2)) as json);
-cast(cast(3.14 as decimal(5,2)) as json)
+select json_compact(true);
+json_compact(true)
+1
+select json_compact(b'10101');
+json_compact(b'10101')
+NULL
+Warnings:
+Warning 4036 Character disallowed in JSON in argument 1 to function 'json_compact' at position 1
+select json_compact(cast(3.14 as decimal(5,2)));
+json_compact(cast(3.14 as decimal(5,2)))
3.14
-select cast(3.14 as json);
-cast(3.14 as json)
+select json_compact(3.14);
+json_compact(3.14)
3.14
-select cast(3.14e0 as json);
-cast(3.14e0 as json)
+select json_compact(3.14e0);
+json_compact(3.14e0)
3.14
-select cast(cast('10101abcde' as binary) as json);
-cast(cast('10101abcde' as binary) as json)
-10101abcde
-select cast(ST_GeomFromText('POINT(1 1)') as json);
-cast(ST_GeomFromText('POINT(1 1)') as json)
-
-select cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json);
-cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json)
-
-select cast(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
- (5 5,7 5,7 7,5 7, 5 5))') as json);
-cast(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
- (5 5,7 5,7 7,5 7, 5 5))') as json)
-
-select cast(null as json);
-cast(null as json)
-NULL
-select cast(null as json) is null;
-cast(null as json) is null
+select json_compact(cast('10101abcde' as binary));
+json_compact(cast('10101abcde' as binary))
+NULL
+Warnings:
+Warning 4038 Syntax error in JSON text in argument 1 to function 'json_compact' at position 6
+select json_compact(ST_GeomFromText('POINT(1 1)'));
+json_compact(ST_GeomFromText('POINT(1 1)'))
+NULL
+Warnings:
+Warning 4036 Character disallowed in JSON in argument 1 to function 'json_compact' at position 1
+select json_compact(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)'));
+json_compact(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)'))
+NULL
+Warnings:
+Warning 4036 Character disallowed in JSON in argument 1 to function 'json_compact' at position 1
+select json_compact(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
+ (5 5,7 5,7 7,5 7, 5 5))'));
+json_compact(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
+ (5 5,7 5,7 7,5 7, 5 5))'))
+NULL
+Warnings:
+Warning 4036 Character disallowed in JSON in argument 1 to function 'json_compact' at position 1
+select json_compact(null);
+json_compact(null)
+NULL
+select json_compact(null) is null;
+json_compact(null) is null
1
# ----------------------------------------------------------------------
# Test of JSON_KEYS function.
@@ -1265,8 +1283,8 @@ ERROR 42000: Incorrect parameter count in the call to native function 'JSON_KEYS
select cast(json_keys('{"a": 1}') as char);
cast(json_keys('{"a": 1}') as char)
["a"]
-select cast(cast(1 as json) as char);
-cast(cast(1 as json) as char)
+select cast(json_compact(1) as char);
+cast(json_compact(1) as char)
1
select cast(json_keys(NULL) as char);
cast(json_keys(NULL) as char)
@@ -1595,11 +1613,11 @@ jdoc
# ----------------------------------------------------------------------
# Test of JSON_ARRAY_APPEND function.
# ----------------------------------------------------------------------
-select json_array_append(NULL, '$.b', cast(1 as json));
-json_array_append(NULL, '$.b', cast(1 as json))
+select json_array_append(NULL, '$.b', json_compact(1));
+json_array_append(NULL, '$.b', json_compact(1))
NULL
-select json_array_append('[1,2,3]', NULL, cast(1 as json));
-json_array_append('[1,2,3]', NULL, cast(1 as json))
+select json_array_append('[1,2,3]', NULL, json_compact(1));
+json_array_append('[1,2,3]', NULL, json_compact(1))
NULL
select json_array_append('[1,2,3]', '$', NULL);
json_array_append('[1,2,3]', '$', NULL)
@@ -1610,35 +1628,35 @@ select json_array_append(NULL, NULL);
ERROR 42000: Incorrect parameter count in the call to native function 'json_array_append'
select json_array_append(NULL, NULL, NULL, NULL);
ERROR 42000: Incorrect parameter count in the call to native function 'json_array_append'
-SELECT JSON_ARRAY_APPEND(cast('1' as json), '$', 3);
-JSON_ARRAY_APPEND(cast('1' as json), '$', 3)
+SELECT JSON_ARRAY_APPEND(json_compact('1'), '$', 3);
+JSON_ARRAY_APPEND(json_compact('1'), '$', 3)
[1, 3]
-SELECT JSON_ARRAY_APPEND(cast('{"a": 3}' as json), '$', 3);
-JSON_ARRAY_APPEND(cast('{"a": 3}' as json), '$', 3)
+SELECT JSON_ARRAY_APPEND(json_compact('{"a": 3}'), '$', 3);
+JSON_ARRAY_APPEND(json_compact('{"a": 3}'), '$', 3)
[{"a": 3}, 3]
error ER_INVALID_JSON_PATH_WILDCARD
-select json_array_append(cast('{"a": {"b": [3]}}' as json), '$**[0]', 6);
-json_array_append(cast('{"a": {"b": [3]}}' as json), '$**[0]', 6)
+select json_array_append(json_compact('{"a": {"b": [3]}}'), '$**[0]', 6);
+json_array_append(json_compact('{"a": {"b": [3]}}'), '$**[0]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_array_append'
# Auto-wrapping, since because the paths identify scalars.
# should return {"a": "foo", "b": ["bar", 4], "c": ["wibble", "grape"]}
SELECT JSON_ARRAY_APPEND('{"a": "foo", "b": "bar", "c": "wibble"}',
-'$.b', cast(4 as json),
-'$.c', cast('"grape"' as json));
+'$.b', json_compact(4),
+'$.c', json_compact('"grape"'));
JSON_ARRAY_APPEND('{"a": "foo", "b": "bar", "c": "wibble"}',
-'$.b', cast(4 as json),
-'$.c', cast('"grape"' as json))
+'$.b', json_compact(4),
+'$.c', json_compact('"grape"'))
{"a": "foo", "b": ["bar", 4], "c": ["wibble", "grape"]}
# should return {"a": "foo", "b": [1, 2, 3, 4],
# "c": ["apple", "pear", "grape"]}
SELECT JSON_ARRAY_APPEND('{"a" : "foo","b": [1, 2, 3], "c": ["apple", "pear"]}',
-'$.b', cast(4 as json),
-'$.c', cast('"grape"' as json));
+'$.b', json_compact(4),
+'$.c', json_compact('"grape"'));
JSON_ARRAY_APPEND('{"a" : "foo","b": [1, 2, 3], "c": ["apple", "pear"]}',
-'$.b', cast(4 as json),
-'$.c', cast('"grape"' as json))
+'$.b', json_compact(4),
+'$.c', json_compact('"grape"'))
{"a": "foo", "b": [1, 2, 3, 4], "c": ["apple", "pear", "grape"]}
SELECT JSON_ARRAY_APPEND('{"a" : "foo","b": [1, 2, 3], "c": ["apple", "pear"]}',
'$.b', 4,
@@ -1700,11 +1718,11 @@ json_array_append('3', '$[0][0][0][0]', 100)
# ----------------------------------------------------------------------
# Test of JSON_INSERT function.
# ----------------------------------------------------------------------
-select json_insert(NULL, '$.b', cast(1 as json));
-json_insert(NULL, '$.b', cast(1 as json))
+select json_insert(NULL, '$.b', json_compact(1));
+json_insert(NULL, '$.b', json_compact(1))
NULL
-select json_insert('[1,2,3]', NULL, cast(1 as json));
-json_insert('[1,2,3]', NULL, cast(1 as json))
+select json_insert('[1,2,3]', NULL, json_compact(1));
+json_insert('[1,2,3]', NULL, json_compact(1))
NULL
select json_insert('[1,2,3]', '$[3]', NULL);
json_insert('[1,2,3]', '$[3]', NULL)
@@ -1755,79 +1773,79 @@ select json_insert('{"a": 3}', '$.a[1]', 4, '$.a[2]', '5');
json_insert('{"a": 3}', '$.a[1]', 4, '$.a[2]', '5')
{"a": [3, 4, "5"]}
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": [1], "b": 2}' as json), '$.*[1]', 6);
-json_insert(cast('{"a": [1], "b": 2}' as json), '$.*[1]', 6)
+select json_insert(json_compact('{"a": [1], "b": 2}'), '$.*[1]', 6);
+json_insert(json_compact('{"a": [1], "b": 2}'), '$.*[1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": 1, "b": 2}' as json), '$.*[1]', 6);
-json_insert(cast('{"a": 1, "b": 2}' as json), '$.*[1]', 6)
+select json_insert(json_compact('{"a": 1, "b": 2}'), '$.*[1]', 6);
+json_insert(json_compact('{"a": 1, "b": 2}'), '$.*[1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": {"b": 3}}' as json), '$.a.*[1]', 6);
-json_insert(cast('{"a": {"b": 3}}' as json), '$.a.*[1]', 6)
+select json_insert(json_compact('{"a": {"b": 3}}'), '$.a.*[1]', 6);
+json_insert(json_compact('{"a": {"b": 3}}'), '$.a.*[1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": {"b": [3]}}' as json), '$.a.*[1]', 6);
-json_insert(cast('{"a": {"b": [3]}}' as json), '$.a.*[1]', 6)
+select json_insert(json_compact('{"a": {"b": [3]}}'), '$.a.*[1]', 6);
+json_insert(json_compact('{"a": {"b": [3]}}'), '$.a.*[1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": {"b": 3}}' as json), '$**[1]', 6);
-json_insert(cast('{"a": {"b": 3}}' as json), '$**[1]', 6)
+select json_insert(json_compact('{"a": {"b": 3}}'), '$**[1]', 6);
+json_insert(json_compact('{"a": {"b": 3}}'), '$**[1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
-json_insert(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6)
+select json_insert(json_compact('{"a": {"b": [3]}}'), '$**[1]', 6);
+json_insert(json_compact('{"a": {"b": [3]}}'), '$**[1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[1]' as json), '$[*][1]', 6);
-json_insert(cast('[1]' as json), '$[*][1]', 6)
+select json_insert(json_compact('[1]'), '$[*][1]', 6);
+json_insert(json_compact('[1]'), '$[*][1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[1]' as json), '$**[1]', 6);
-json_insert(cast('[1]' as json), '$**[1]', 6)
+select json_insert(json_compact('[1]'), '$**[1]', 6);
+json_insert(json_compact('[1]'), '$**[1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[1, [2], 3]' as json), '$[*][1]', 6);
-json_insert(cast('[1, [2], 3]' as json), '$[*][1]', 6)
+select json_insert(json_compact('[1, [2], 3]'), '$[*][1]', 6);
+json_insert(json_compact('[1, [2], 3]'), '$[*][1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[1, [2], 3]' as json), '$**[1]', 6);
-json_insert(cast('[1, [2], 3]' as json), '$**[1]', 6)
+select json_insert(json_compact('[1, [2], 3]'), '$**[1]', 6);
+json_insert(json_compact('[1, [2], 3]'), '$**[1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[[1]]' as json), '$[*][1]', 6);
-json_insert(cast('[[1]]' as json), '$[*][1]', 6)
+select json_insert(json_compact('[[1]]'), '$[*][1]', 6);
+json_insert(json_compact('[[1]]'), '$[*][1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[[1]]' as json), '$**[1]', 6);
-json_insert(cast('[[1]]' as json), '$**[1]', 6)
+select json_insert(json_compact('[[1]]'), '$**[1]', 6);
+json_insert(json_compact('[[1]]'), '$**[1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_insert'
-select json_insert(cast('{"a": 3}' as json), '$[1]', 6);
-json_insert(cast('{"a": 3}' as json), '$[1]', 6)
+select json_insert(json_compact('{"a": 3}'), '$[1]', 6);
+json_insert(json_compact('{"a": 3}'), '$[1]', 6)
[{"a": 3}, 6]
SELECT JSON_INSERT('{ "a" : "foo", "b" : [ 1, 2, 3 ] }', '$.a', true);
JSON_INSERT('{ "a" : "foo", "b" : [ 1, 2, 3 ] }', '$.a', true)
@@ -2054,9 +2072,9 @@ select json_array_insert( '[ 1, 2, 3 ]', '$[1]', true, '$[1]', false );
json_array_insert( '[ 1, 2, 3 ]', '$[1]', true, '$[1]', false )
[1, false, true, 2, 3]
select json_array_insert( '[ 1, 2, 3 ]', '$[1]',
-cast( '[ "a", "b", "c", "d" ]' as json ), '$[1][2]', false );
+json_compact( '[ "a", "b", "c", "d" ]'), '$[1][2]', false );
json_array_insert( '[ 1, 2, 3 ]', '$[1]',
-cast( '[ "a", "b", "c", "d" ]' as json ), '$[1][2]', false )
+json_compact( '[ "a", "b", "c", "d" ]'), '$[1][2]', false )
[1, ["a", "b", false, "c", "d"], 2, 3]
error ER_INVALID_JSON_TEXT_IN_PARAM
SELECT JSON_ARRAY_INSERT(JSON_EXTRACT('[1', '$'), '$[0]', 1);
@@ -2073,11 +2091,11 @@ Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_extract
# ----------------------------------------------------------------------
# Test of JSON_SET function.
# ----------------------------------------------------------------------
-select json_set(NULL, '$.b', cast(1 as json));
-json_set(NULL, '$.b', cast(1 as json))
+select json_set(NULL, '$.b', json_compact(1));
+json_set(NULL, '$.b', json_compact(1))
NULL
-select json_set('[1,2,3]', NULL, cast(1 as json));
-json_set('[1,2,3]', NULL, cast(1 as json))
+select json_set('[1,2,3]', NULL, json_compact(1));
+json_set('[1,2,3]', NULL, json_compact(1))
NULL
select json_set('[1,2,3]', '$[3]', NULL);
json_set('[1,2,3]', '$[3]', NULL)
@@ -2135,8 +2153,8 @@ select json_set('{"a": 3}', '$.a[1]', 4, '$.a[2]', '5');
json_set('{"a": 3}', '$.a[1]', 4, '$.a[2]', '5')
{"a": [3, 4, "5"]}
error ER_INVALID_JSON_PATH_WILDCARD
-select json_set(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
-json_set(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6)
+select json_set(json_compact('{"a": {"b": [3]}}'), '$**[1]', 6);
+json_set(json_compact('{"a": {"b": [3]}}'), '$**[1]', 6)
NULL
Warnings:
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_set'
@@ -2154,25 +2172,25 @@ JSON_OBJECT( 'b', false ), '$.a.c', true)
{"a": {"b": false, "c": true}}
select json_set('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.a',
-cast('{}' as json));
+json_compact('{}'));
json_set('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.a',
-cast('{}' as json))
+json_compact('{}'))
{"a": {}, "b": [1, 2, 3]}
select json_set('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.c',
-cast('[true, false]' as json));
+json_compact('[true, false]'));
json_set('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.c',
-cast('[true, false]' as json))
+json_compact('[true, false]'))
{"a": "foo", "b": [1, 2, 3], "c": [true, false]}
select json_set('1', '$[3]', 2);
json_set('1', '$[3]', 2)
[1, 2]
select json_set('{ "a" : "foo"}', '$.a',
-cast('{"b": false}' as json), '$.a.c', true);
+json_compact('{"b": false}'), '$.a.c', true);
json_set('{ "a" : "foo"}', '$.a',
-cast('{"b": false}' as json), '$.a.c', true)
+json_compact('{"b": false}'), '$.a.c', true)
{"a": {"b": false, "c": true}}
SELECT JSON_SET
(
@@ -2204,13 +2222,13 @@ SELECT JSON_SET
(
'{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.c',
-JSON_ARRAY( CAST( 'true' AS JSON ), CAST( 'false' AS JSON ) )
+JSON_ARRAY( json_compact( 'true'), json_compact( 'false') )
);
JSON_SET
(
'{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.c',
-JSON_ARRAY( CAST( 'true' AS JSON ), CAST( 'false' AS JSON ) )
+JSON_ARRAY( json_compact( 'true'), json_compact( 'false') )
)
{"a": "foo", "b": [1, 2, 3], "c": [true, false]}
SELECT JSON_SET
@@ -2242,11 +2260,11 @@ JSON_SET
# ----------------------------------------------------------------------
# Test of JSON_REPLACE function.
# ----------------------------------------------------------------------
-select json_replace(NULL, '$.b', cast(1 as json));
-json_replace(NULL, '$.b', cast(1 as json))
+select json_replace(NULL, '$.b', json_compact(1));
+json_replace(NULL, '$.b', json_compact(1))
NULL
-select json_replace('[1,2,3]', NULL, cast(1 as json));
-json_replace('[1,2,3]', NULL, cast(1 as json))
+select json_replace('[1,2,3]', NULL, json_compact(1));
+json_replace('[1,2,3]', NULL, json_compact(1))
NULL
select json_replace('[1,2,3]', '$[2]', NULL);
json_replace('[1,2,3]', '$[2]', NULL)
@@ -2320,11 +2338,11 @@ true)
# ----------------------------------------------------------------------
# Test of JSON_ARRAY function.
# ----------------------------------------------------------------------
-select json_array(NULL, '$.b', cast(1 as json));
-json_array(NULL, '$.b', cast(1 as json))
+select json_array(NULL, '$.b', json_compact(1));
+json_array(NULL, '$.b', json_compact(1))
[null, "$.b", 1]
-select json_array('[1,2,3]', NULL, cast(1 as json));
-json_array('[1,2,3]', NULL, cast(1 as json))
+select json_array('[1,2,3]', NULL, json_compact(1));
+json_array('[1,2,3]', NULL, json_compact(1))
["[1,2,3]", null, 1]
select json_array('[1,2,3]', '$[3]', NULL);
json_array('[1,2,3]', '$[3]', NULL)
@@ -2338,8 +2356,8 @@ json_array(3.14)
select json_array('[1,2,3]');
json_array('[1,2,3]')
["[1,2,3]"]
-select json_array(cast('[1,2,3]' as json));
-json_array(cast('[1,2,3]' as json))
+select json_array(json_compact('[1,2,3]'));
+json_array(json_compact('[1,2,3]'))
[[1,2,3]]
select json_array(1,2,3);
json_array(1,2,3)
@@ -2373,11 +2391,11 @@ json_object( 'a', 1 )
select json_object( 'a', 1, 'b', 'foo' );
json_object( 'a', 1, 'b', 'foo' )
{"a": 1, "b": "foo"}
-select json_object( 'a', 1, 'b', 'foo', 'c', cast( '{ "d": "wibble" }' as json ) );
-json_object( 'a', 1, 'b', 'foo', 'c', cast( '{ "d": "wibble" }' as json ) )
+select json_object( 'a', 1, 'b', 'foo', 'c', json_compact( '{ "d": "wibble" }') );
+json_object( 'a', 1, 'b', 'foo', 'c', json_compact( '{ "d": "wibble" }') )
{"a": 1, "b": "foo", "c": { "d": "wibble" }}
-select json_object( 'a', true, 'b', false, 'c', cast( 'null' as json) );
-json_object( 'a', true, 'b', false, 'c', cast( 'null' as json) )
+select json_object( 'a', true, 'b', false, 'c', json_compact( 'null') );
+json_object( 'a', true, 'b', false, 'c', json_compact( 'null') )
{"a": true, "b": false, "c": null}
select json_valid( json_object( '"a"', 1 ) );
json_valid( json_object( '"a"', 1 ) )
@@ -2717,43 +2735,43 @@ JSON_SEARCH
)
$.one potato
select json_type(case (null is null) when 1 then
-cast('null' as json) else
-cast('[1,2,3]' as json) end);
+json_compact('null') else
+json_compact('[1,2,3]') end);
json_type(case (null is null) when 1 then
-cast('null' as json) else
-cast('[1,2,3]' as json) end)
+json_compact('null') else
+json_compact('[1,2,3]') end)
NULL
select json_type(case (null is not null) when 1 then
-cast('null' as json) else
-cast('[1,2,3]' as json) end);
+json_compact('null') else
+json_compact('[1,2,3]') end);
json_type(case (null is not null) when 1 then
-cast('null' as json) else
-cast('[1,2,3]' as json) end)
+json_compact('null') else
+json_compact('[1,2,3]') end)
ARRAY
select json_type( if(null is null,
-cast('null' as json),
-cast('[1,2,3]' as json)) );
+json_compact('null'),
+json_compact('[1,2,3]')) );
json_type( if(null is null,
-cast('null' as json),
-cast('[1,2,3]' as json)) )
+json_compact('null'),
+json_compact('[1,2,3]')) )
NULL
select json_type( if(null is not null,
-cast('null' as json),
-cast('[1,2,3]' as json)));
+json_compact('null'),
+json_compact('[1,2,3]')));
json_type( if(null is not null,
-cast('null' as json),
-cast('[1,2,3]' as json)))
+json_compact('null'),
+json_compact('[1,2,3]')))
ARRAY
-select cast(json_extract(cast(concat('[', cast('["A",2]' as json), ']') as json),
+select cast(json_extract(json_compact(concat('[', json_compact('["A",2]'), ']')),
'$[0][1]') as char) = 2;
-cast(json_extract(cast(concat('[', cast('["A",2]' as json), ']') as json),
+cast(json_extract(json_compact(concat('[', json_compact('["A",2]'), ']')),
'$[0][1]') as char) = 2
1
# ----------------------------------------------------------------------
# Test of aggregate function MAX, MIN.
# ----------------------------------------------------------------------
-select max(cast('[1,2,3]' as json));
-max(cast('[1,2,3]' as json))
+select max(json_compact('[1,2,3]'));
+max(json_compact('[1,2,3]'))
[1,2,3]
# ----------------------------------------------------------------------
# Test of JSON_QUOTE, JSON_UNQUOTE
@@ -2838,26 +2856,26 @@ char_length(json_unquote('""'))
select json_unquote('"" ');
json_unquote('"" ')
-select json_unquote(cast(json_quote('abc') as json));
-json_unquote(cast(json_quote('abc') as json))
+select json_unquote(json_compact(json_quote('abc')));
+json_unquote(json_compact(json_quote('abc')))
abc
-select cast('{"abc": "foo"}' as json);
-cast('{"abc": "foo"}' as json)
+select json_compact('{"abc": "foo"}');
+json_compact('{"abc": "foo"}')
+{"abc":"foo"}
+select json_unquote(json_compact('{"abc": "foo"}'));
+json_unquote(json_compact('{"abc": "foo"}'))
{"abc": "foo"}
-select json_unquote(cast('{"abc": "foo"}' as json));
-json_unquote(cast('{"abc": "foo"}' as json))
-{"abc": "foo"}
-select json_extract(cast('{"abc": "foo"}' as json), '$.abc');
-json_extract(cast('{"abc": "foo"}' as json), '$.abc')
+select json_extract(json_compact('{"abc": "foo"}'), '$.abc');
+json_extract(json_compact('{"abc": "foo"}'), '$.abc')
"foo"
-select json_unquote(json_extract(cast('{"abc": "foo"}' as json), '$.abc'));
-json_unquote(json_extract(cast('{"abc": "foo"}' as json), '$.abc'))
+select json_unquote(json_extract(json_compact('{"abc": "foo"}'), '$.abc'));
+json_unquote(json_extract(json_compact('{"abc": "foo"}'), '$.abc'))
foo
select json_unquote('["a", "b", "c"]');
json_unquote('["a", "b", "c"]')
["a", "b", "c"]
-select json_unquote(cast('["a", "b", "c"]' as json));
-json_unquote(cast('["a", "b", "c"]' as json))
+select json_unquote(json_compact('["a", "b", "c"]'));
+json_unquote(json_compact('["a", "b", "c"]'))
["a", "b", "c"]
select charset(json_unquote('"abc"'));
charset(json_unquote('"abc"'))
@@ -2868,8 +2886,8 @@ json_quote(convert(X'e68891' using utf8))
select json_quote(convert(X'e68891' using utf8mb4));
json_quote(convert(X'e68891' using utf8mb4))
"我"
-select cast(json_quote(convert(X'e68891' using utf8)) as json);
-cast(json_quote(convert(X'e68891' using utf8)) as json)
+select json_compact(json_quote(convert(X'e68891' using utf8)));
+json_compact(json_quote(convert(X'e68891' using utf8)))
"我"
select json_unquote(convert(X'e68891' using utf8));
json_unquote(convert(X'e68891' using utf8))
@@ -2882,17 +2900,21 @@ json_quote(json_quote(json_quote('abc'))))));
json_unquote(json_unquote(json_unquote( # long round trip of it
json_quote(json_quote(json_quote('abc'))))))
abc
-select cast(cast('2015-01-15 23:24:25' as datetime) as json);
-cast(cast('2015-01-15 23:24:25' as datetime) as json)
-2015-01-15 23:24:25
-select json_unquote(cast(cast('2015-01-15 23:24:25' as datetime) as json));
-json_unquote(cast(cast('2015-01-15 23:24:25' as datetime) as json))
+select json_compact(cast('2015-01-15 23:24:25' as datetime));
+json_compact(cast('2015-01-15 23:24:25' as datetime))
+NULL
+Warnings:
+Warning 4038 Syntax error in JSON text in argument 1 to function 'json_compact' at position 5
+select json_unquote(json_compact(cast('2015-01-15 23:24:25' as datetime)));
+json_unquote(json_compact(cast('2015-01-15 23:24:25' as datetime)))
2015-01-15 23:24:25
-select cast(st_geomfromtext('point(1 1)') as json);
-cast(st_geomfromtext('point(1 1)') as json)
-
-select json_unquote(cast(st_geomfromtext('point(1 1)') as json));
-json_unquote(cast(st_geomfromtext('point(1 1)') as json))
+select json_compact(st_geomfromtext('point(1 1)'));
+json_compact(st_geomfromtext('point(1 1)'))
+NULL
+Warnings:
+Warning 4036 Character disallowed in JSON in argument 1 to function 'json_compact' at position 1
+select json_unquote(json_compact(st_geomfromtext('point(1 1)')));
+json_unquote(json_compact(st_geomfromtext('point(1 1)')))
SELECT JSON_UNQUOTE( '"abc"' );
JSON_UNQUOTE( '"abc"' )
@@ -2907,9 +2929,9 @@ SELECT JSON_UNQUOTE( 123 );
JSON_UNQUOTE( 123 )
123
SELECT JSON_UNQUOTE
-( CAST( CAST( '"abc"' AS JSON ) AS CHAR ) );
+( CAST( json_compact( '"abc"') AS CHAR ) );
JSON_UNQUOTE
-( CAST( CAST( '"abc"' AS JSON ) AS CHAR ) )
+( CAST( json_compact( '"abc"') AS CHAR ) )
abc
SELECT JSON_UNQUOTE
(
@@ -2943,8 +2965,8 @@ error ER_INCORRECT_TYPE
SELECT JSON_QUOTE( 123 );
JSON_QUOTE( 123 )
NULL
-SELECT CAST( JSON_QUOTE( '123' ) AS JSON );
-CAST( JSON_QUOTE( '123' ) AS JSON )
+SELECT json_compact( JSON_QUOTE( '123' ));
+json_compact( JSON_QUOTE( '123' ))
"123"
# ----------------------------------------------------------------------
# Test of JSON_CONTAINS
@@ -2953,78 +2975,78 @@ CAST( JSON_QUOTE( '123' ) AS JSON )
select json_contains(NULL, NULL);
json_contains(NULL, NULL)
NULL
-select json_contains(cast('{"a": 1, "b": 2}' as json), NULL);
-json_contains(cast('{"a": 1, "b": 2}' as json), NULL)
+select json_contains(json_compact('{"a": 1, "b": 2}'), NULL);
+json_contains(json_compact('{"a": 1, "b": 2}'), NULL)
NULL
-select json_contains(NULL, cast('null' as json));
-json_contains(NULL, cast('null' as json))
+select json_contains(NULL, json_compact('null'));
+json_contains(NULL, json_compact('null'))
NULL
-select json_contains(cast('[1]' as json), cast('[1]' as json), NULL);
-json_contains(cast('[1]' as json), cast('[1]' as json), NULL)
+select json_contains(json_compact('[1]'), json_compact('[1]'), NULL);
+json_contains(json_compact('[1]'), json_compact('[1]'), NULL)
NULL
# should give 0:
-select json_contains(cast(3.14 as json), cast(3 as json));
-json_contains(cast(3.14 as json), cast(3 as json))
+select json_contains(json_compact(3.14), json_compact(3));
+json_contains(json_compact(3.14), json_compact(3))
0
# should give 0: not at top level
-select json_contains(cast('{"a": {"b": 7}}' as json), cast('{"b": 7}' as json));
-json_contains(cast('{"a": {"b": 7}}' as json), cast('{"b": 7}' as json))
+select json_contains(json_compact('{"a": {"b": 7}}'), json_compact('{"b": 7}'));
+json_contains(json_compact('{"a": {"b": 7}}'), json_compact('{"b": 7}'))
0
# but path argument will fix it:
-select json_contains(cast('{"a": {"b": 7}}' as json), cast('{"b": 7}' as json), '$.a');
-json_contains(cast('{"a": {"b": 7}}' as json), cast('{"b": 7}' as json), '$.a')
+select json_contains(json_compact('{"a": {"b": 7}}'), json_compact('{"b": 7}'), '$.a');
+json_contains(json_compact('{"a": {"b": 7}}'), json_compact('{"b": 7}'), '$.a')
1
# but arrays "introspect"
-select json_contains(cast('[1,[2.0, 3.0]]' as json), cast('[2.0]' as json));
-json_contains(cast('[1,[2.0, 3.0]]' as json), cast('[2.0]' as json))
+select json_contains(json_compact('[1,[2.0, 3.0]]'), json_compact('[2.0]'));
+json_contains(json_compact('[1,[2.0, 3.0]]'), json_compact('[2.0]'))
1
-select json_contains(cast('[1, 2, [3, [4, 5]], 6, 7]' as json), cast('5' as json));
-json_contains(cast('[1, 2, [3, [4, 5]], 6, 7]' as json), cast('5' as json))
+select json_contains(json_compact('[1, 2, [3, [4, 5]], 6, 7]'), json_compact('5'));
+json_contains(json_compact('[1, 2, [3, [4, 5]], 6, 7]'), json_compact('5'))
1
# should give 0: just a key
-select json_contains(cast('{"a": 1, "b": 2}' as json), cast('"a"' as json));
-json_contains(cast('{"a": 1, "b": 2}' as json), cast('"a"' as json))
+select json_contains(json_compact('{"a": 1, "b": 2}'), json_compact('"a"'));
+json_contains(json_compact('{"a": 1, "b": 2}'), json_compact('"a"'))
0
# should give 0: one candidate element doesn't match
-select json_contains(cast('[1]' as json), cast('[1,2]' as json));
-json_contains(cast('[1]' as json), cast('[1,2]' as json))
+select json_contains(json_compact('[1]'), json_compact('[1,2]'));
+json_contains(json_compact('[1]'), json_compact('[1,2]'))
0
# should all give 1
-select json_contains(cast('null' as json), cast('null' as json));
-json_contains(cast('null' as json), cast('null' as json))
+select json_contains(json_compact('null'), json_compact('null'));
+json_contains(json_compact('null'), json_compact('null'))
1
# simple object subset
-select json_contains(cast('{"a": 1, "b": 2}' as json), cast( '{"a": 1}' as json));
-json_contains(cast('{"a": 1, "b": 2}' as json), cast( '{"a": 1}' as json))
+select json_contains(json_compact('{"a": 1, "b": 2}'), json_compact( '{"a": 1}'));
+json_contains(json_compact('{"a": 1, "b": 2}'), json_compact( '{"a": 1}'))
1
# simple vector subset
-select json_contains(cast('[1, 2, 3]' as json), cast('[1, 3]' as json));
-json_contains(cast('[1, 2, 3]' as json), cast('[1, 3]' as json))
+select json_contains(json_compact('[1, 2, 3]'), json_compact('[1, 3]'));
+json_contains(json_compact('[1, 2, 3]'), json_compact('[1, 3]'))
1
# auto-wrap, should give 1
-select json_contains(cast('[1, 2, 3]' as json), cast(3 as json));
-json_contains(cast('[1, 2, 3]' as json), cast(3 as json))
+select json_contains(json_compact('[1, 2, 3]'), json_compact(3));
+json_contains(json_compact('[1, 2, 3]'), json_compact(3))
1
# ok even with nested cast off elements
-select json_contains(cast('{"person": {"id": 1, "country": "norway"}}' as json),
-cast('{"person": {"country": "norway"}}' as json));
-json_contains(cast('{"person": {"id": 1, "country": "norway"}}' as json),
-cast('{"person": {"country": "norway"}}' as json))
+select json_contains(json_compact('{"person": {"id": 1, "country": "norway"}}'),
+json_compact('{"person": {"country": "norway"}}'));
+json_contains(json_compact('{"person": {"id": 1, "country": "norway"}}'),
+json_compact('{"person": {"country": "norway"}}'))
1
# vector reordering and duplicates is ok
-select json_contains(cast('[1,3,5]' as json), cast('[5,3,1,5]' as json));
-json_contains(cast('[1,3,5]' as json), cast('[5,3,1,5]' as json))
+select json_contains(json_compact('[1,3,5]'), json_compact('[5,3,1,5]'));
+json_contains(json_compact('[1,3,5]'), json_compact('[5,3,1,5]'))
1
# ok even with more elts in candidate than in doc
-select json_contains(cast('[{"b": 4, "a":7}]' as json), cast('[{"a":7},{"b":4}]' as json));
-json_contains(cast('[{"b": 4, "a":7}]' as json), cast('[{"a":7},{"b":4}]' as json))
+select json_contains(json_compact('[{"b": 4, "a":7}]'), json_compact('[{"a":7},{"b":4}]'));
+json_contains(json_compact('[{"b": 4, "a":7}]'), json_compact('[{"a":7},{"b":4}]'))
1
-select json_contains(cast('[{"b": 4, "a":7}, 5]' as json), cast('[5, {"a":7, "b":4}]' as json));
-json_contains(cast('[{"b": 4, "a":7}, 5]' as json), cast('[5, {"a":7, "b":4}]' as json))
+select json_contains(json_compact('[{"b": 4, "a":7}, 5]'), json_compact('[5, {"a":7, "b":4}]'));
+json_contains(json_compact('[{"b": 4, "a":7}, 5]'), json_compact('[5, {"a":7, "b":4}]'))
1
# ok even with mixed number types that compare equal
-select json_contains(cast('[{"b": 4, "a":7}, 5.0]' as json), cast('[5, {"a":7.0E0, "b":4}]' as json));
-json_contains(cast('[{"b": 4, "a":7}, 5.0]' as json), cast('[5, {"a":7.0E0, "b":4}]' as json))
+select json_contains(json_compact('[{"b": 4, "a":7}, 5.0]'), json_compact('[5, {"a":7.0E0, "b":4}]'));
+json_contains(json_compact('[{"b": 4, "a":7}, 5.0]'), json_compact('[5, {"a":7.0E0, "b":4}]'))
1
select json_contains( '{"customer": "cust3"}', '{"customer": "cust1"}' );
json_contains( '{"customer": "cust3"}', '{"customer": "cust1"}' )
@@ -3055,57 +3077,57 @@ JSON_CONTAINS('{"a":1}', '{"a":1,"b":2}')
0
SELECT JSON_CONTAINS
(
-CAST('[1, 4, 6]' AS JSON),
-CAST('[1, 6]' AS JSON)
+json_compact('[1, 4, 6]'),
+json_compact('[1, 6]')
);
JSON_CONTAINS
(
-CAST('[1, 4, 6]' AS JSON),
-CAST('[1, 6]' AS JSON)
+json_compact('[1, 4, 6]'),
+json_compact('[1, 6]')
)
1
SELECT JSON_CONTAINS
(
-CAST('{"person": {"id": 1, "country": "norway"}}' AS JSON),
-CAST('{"person": {"country": "norway"}}' AS JSON)
+json_compact('{"person": {"id": 1, "country": "norway"}}'),
+json_compact('{"person": {"country": "norway"}}')
);
JSON_CONTAINS
(
-CAST('{"person": {"id": 1, "country": "norway"}}' AS JSON),
-CAST('{"person": {"country": "norway"}}' AS JSON)
+json_compact('{"person": {"id": 1, "country": "norway"}}'),
+json_compact('{"person": {"country": "norway"}}')
)
1
SELECT JSON_CONTAINS
(
-CAST('[1,3,5]' AS JSON),
-CAST('[5,3,1,5]' AS JSON)
+json_compact('[1,3,5]'),
+json_compact('[5,3,1,5]')
);
JSON_CONTAINS
(
-CAST('[1,3,5]' AS JSON),
-CAST('[5,3,1,5]' AS JSON)
+json_compact('[1,3,5]'),
+json_compact('[5,3,1,5]')
)
1
SELECT JSON_CONTAINS
(
-CAST('[3.14]' AS JSON),
-CAST('[3]' AS JSON)
+json_compact('[3.14]'),
+json_compact('[3]')
);
JSON_CONTAINS
(
-CAST('[3.14]' AS JSON),
-CAST('[3]' AS JSON)
+json_compact('[3.14]'),
+json_compact('[3]')
)
0
SELECT JSON_CONTAINS
(
-CAST('[1, 2, 3]' AS JSON),
-CAST(3 AS JSON)
+json_compact('[1, 2, 3]'),
+json_compact(3)
);
JSON_CONTAINS
(
-CAST('[1, 2, 3]' AS JSON),
-CAST(3 AS JSON)
+json_compact('[1, 2, 3]'),
+json_compact(3)
)
1
SELECT JSON_CONTAINS();
@@ -3119,17 +3141,17 @@ ERROR 42000: Incorrect parameter count in the call to native function 'JSON_CONT
# Item_func_json_quote::fix_length_and_dec. Bug found by Knut.
# Similar issue for JSON_UNQUOTE and JSON_TYPE.
# ----------------------------------------------------------------------
-select json_object("a", ifnull(json_quote('test'), cast('null' as json)));
-json_object("a", ifnull(json_quote('test'), cast('null' as json)))
+select json_object("a", ifnull(json_quote('test'), json_compact('null')));
+json_object("a", ifnull(json_quote('test'), json_compact('null')))
{"a": "\"test\""}
-select cast(concat('[', json_quote('ab'), ']') as json);
-cast(concat('[', json_quote('ab'), ']') as json)
+select json_compact(concat('[', json_quote('ab'), ']'));
+json_compact(concat('[', json_quote('ab'), ']'))
["ab"]
-select cast(concat('[', json_unquote('"12"'), ']') as json);
-cast(concat('[', json_unquote('"12"'), ']') as json)
+select json_compact(concat('[', json_unquote('"12"'), ']'));
+json_compact(concat('[', json_unquote('"12"'), ']'))
[12]
-select cast(concat('["', json_type(cast(1 as json)), '"]') as json);
-cast(concat('["', json_type(cast(1 as json)), '"]') as json)
+select json_compact(concat('["', json_type( json_compact(1)), '"]'));
+json_compact(concat('["', json_type( json_compact(1)), '"]'))
["INTEGER"]
#
# Bug#20912438: ITEM_TYPE_HOLDER::DISPLAY_LENGTH(ITEM*): ASSERTION `0' FAILED
@@ -3138,12 +3160,12 @@ cast(concat('["', json_type(cast(1 as json)), '"]') as json)
(SELECT JSON_KEYS('{ "key80": "2015-04-20 11:53:55" }') LIMIT 0);
JSON_KEYS('{ "key80": "2015-04-20 11:53:55"}')
["key80"]
-SELECT CAST(1 AS JSON) UNION ALL SELECT CAST(1 AS JSON);
-CAST(1 AS JSON)
+SELECT json_compact(1) UNION ALL SELECT json_compact(1);
+json_compact(1)
1
1
-SELECT COUNT(*), CAST(NULL AS JSON);
-COUNT(*) CAST(NULL AS JSON)
+SELECT COUNT(*), json_compact(NULL);
+COUNT(*) json_compact(NULL)
1 NULL
error ER_INVALID_JSON_TEXT_IN_PARAM
SELECT COUNT(*), JSON_EXTRACT('not valid json!', '$');
@@ -3306,8 +3328,8 @@ json_search( '{ "keyA": [ "foot" ], "keyB": [ "food" ] }', ?, 'foo%' )
select json_quote( json_type( json_object() ) );
json_quote( json_type( json_object() ) )
"OBJECT"
-select json_quote( json_type( cast('{}' as json) ) );
-json_quote( json_type( cast('{}' as json) ) )
+select json_quote( json_type( json_compact('{}') ) );
+json_quote( json_type( json_compact('{}') ) )
"OBJECT"
#
# Bug#21148020 OUTPUT FROM JSON_TYPE() IS TRUNCATED
@@ -3608,6 +3630,6 @@ JSON_REPLACE('[[[1]]]', '$[0][0][0]', 100)
#
SELECT JSON_ARRAY(LEAST(NULL, NULL), GREATEST(NULL, NULL), LEAST(j1, NULL),
GREATEST(NULL, j2), LEAST(j1, j2), GREATEST(j1, j2)) AS j
-FROM (SELECT CAST('1' AS JSON) AS j1, CAST('2' AS JSON) AS j2) t;
+FROM (SELECT json_compact('1') AS j1, json_compact('2') AS j2) t;
j
[null, null, null, null, "1", "2"]
diff --git a/mysql-test/suite/json/t/json_no_table.test b/mysql-test/suite/json/t/json_no_table.test
index 584af56a3a9..d7b302c98a6 100644
--- a/mysql-test/suite/json/t/json_no_table.test
+++ b/mysql-test/suite/json/t/json_no_table.test
@@ -7,21 +7,21 @@
# Some extra checks for comparisons between positive and negative zero.
# All should be equal.
-SELECT CAST(0.0e0 AS JSON) = -0.0e0;
-SELECT CAST(CAST(0 AS DECIMAL) AS JSON) = CAST(-0.0e0 AS DECIMAL);
-SELECT CAST(0.0e0 AS JSON) = CAST(-0.0e0 AS DECIMAL);
-SELECT CAST(CAST(0 AS DECIMAL) AS JSON) = -0.0e0;
-SELECT CAST(CAST(0 AS SIGNED) AS JSON) = -0.0e0;
-SELECT CAST(CAST(0 AS SIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL);
-SELECT CAST(CAST(0 AS UNSIGNED) AS JSON) = -0.0e0;
-SELECT CAST(CAST(0 AS UNSIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL);
+SELECT JSON_COMPACT(0.0e0) = -0.0e0;
+SELECT JSON_COMPACT(CAST(0 AS DECIMAL)) = CAST(-0.0e0 AS DECIMAL);
+SELECT JSON_COMPACT(0.0e0) = CAST(-0.0e0 AS DECIMAL);
+SELECT JSON_COMPACT(CAST(0 AS DECIMAL)) = -0.0e0;
+SELECT JSON_COMPACT(CAST(0 AS SIGNED)) = -0.0e0;
+SELECT JSON_COMPACT(CAST(0 AS SIGNED)) = CAST(-0.0e0 AS DECIMAL);
+SELECT JSON_COMPACT(CAST(0 AS UNSIGNED)) = -0.0e0;
+SELECT JSON_COMPACT(CAST(0 AS UNSIGNED)) = CAST(-0.0e0 AS DECIMAL);
# Test that CAST string argument isn't treated as ANY_JSON_ATOM
# in that a MySQL string needs to be parsed to JSON here; it is not
# auto-converted to a JSON string as in ANY_JSON_ATOM contexts.
-select cast('"abc"' as json);
+select json_compact('"abc"');
--echo error ER_INVALID_JSON_TEXT_IN_PARAM
-select cast('abc' as json);
+select json_compact('abc');
--echo
--echo # String literal - valid JSON
@@ -50,11 +50,11 @@ set names 'utf8';
--echo
--echo # Json expression
-select JSON_VALID(cast('[123]' as JSON ));
+select JSON_VALID(json_compact('[123]'));
--echo
--echo # Json expression NULL
-select JSON_VALID(cast(NULL as JSON ));
+select JSON_VALID(json_compact(NULL));
--echo
--echo # Bare NULL
@@ -80,7 +80,7 @@ select JSON_VALID( CAST('2015-01-15' AS DATE) );
--echo # The date string doesn't parse as JSON text, so wrong:
select JSON_VALID( CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8') );
--echo # OK, though:
-select JSON_VALID( CAST(CURDATE() as JSON) );
+select JSON_VALID( json_compact(CURDATE()) );
--echo
--echo # Function result - NULL
@@ -299,14 +299,14 @@ SELECT JSON_LENGTH
--echo # Test of JSON_DEPTH function.
--echo # ----------------------------------------------------------------------
select json_depth(null);
-select json_depth(cast(null as json));
+select json_depth(json_compact(null));
#select i, json_depth(j) from t1;
-select json_depth(cast('[]' as json)),
- json_depth(cast('{}' as json)),
- json_depth(cast('null' as json)),
+select json_depth(json_compact('[]')),
+ json_depth(json_compact('{}')),
+ json_depth(json_compact('null')),
json_depth(json_quote('foo'));
-select json_depth(cast('[[2], 3, [[[4]]]]' as json));
-select json_depth(cast('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}' as json));
+select json_depth(json_compact('[[2], 3, [[[4]]]]'));
+select json_depth(json_compact('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}'));
# examples from the wl7909 spec
# returns 1
@@ -325,7 +325,7 @@ SELECT JSON_DEPTH
SELECT JSON_DEPTH( '"abc"' );
# returns 1
-SELECT JSON_DEPTH( CAST( '"abc"' AS JSON ) );
+SELECT JSON_DEPTH( json_compact( '"abc"') );
--echo error ER_INVALID_TYPE_FOR_JSON
SELECT JSON_DEPTH( 1 );
@@ -334,7 +334,7 @@ SELECT JSON_DEPTH( 1 );
SELECT JSON_DEPTH( 'abc' );
# returns 1
-SELECT JSON_DEPTH( CAST( 1 AS JSON ) );
+SELECT JSON_DEPTH( json_compact( 1) );
# returns 2
SELECT JSON_DEPTH
@@ -608,93 +608,93 @@ select json_type('3.14');
select json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'));
--echo # ----------------------------------------------------------------------
---echo # Test of CAST(literal AS JSON)
+--echo # Test of json_compact(literal)
--echo # ----------------------------------------------------------------------
-select json_type(cast(cast('2014-11-25 18:00' as datetime) as json));
-select json_type(cast(cast('2014-11-25' as date) as json));
-select json_type(cast(cast('18:00:59' as time) as json));
-# select json_type(cast(cast('2014-11-25 18:00' as timestamp) as json)); -- cast target type not supported
-
-# select json_type(cast(cast('1999' as year) as json)); -- cast target type not supported
-select json_type(cast(127 as json));
-select json_type(cast(255 as json));
-select json_type(cast(32767 as json));
-select json_type(cast(65535 as json));
-select json_type(cast(8388607 as json));
-select json_type(cast(16777215 as json));
-select json_type(cast(2147483647 as json));
-select json_type(cast(4294967295 as json));
-select json_type(cast(9223372036854775807 as json));
-select json_type(cast(18446744073709551615 as json));
-select json_type(cast(true as json));
-select json_type(cast(b'10101' as json));
-
-select json_type(cast(cast(3.14 as decimal(5,2)) as json));
-select json_type(cast(3.14 as json));
-select json_type(cast(3.14E30 as json));
-# select json_type(cast(cast(3.14 as numeral(5,2)) as json)); -- cast target type not supported
-
-# select json_type(cast(cast(3.14 as double) as json)); -- cast target type not supported
-# select json_type(cast(cast(3.14 as float) as json)); -- cast target type not supported
-
-# select json_type(cast(cast(b'10101' as bit(10)) as json)); -- cast target type not supported
-# select json_type(cast(cast('10101abcde' as blob) as json)); -- cast target type not supported
-select json_type(cast(cast('10101abcde' as binary) as json));
-
-# select json_type(cast(cast('a' as enum('a','b','c')) as json)); -- cast target type not supported
-# select json_type(cast(cast('a,c' as set('a','b','c')) as json)); -- cast target type not supported
-
-select json_type(cast(ST_GeomFromText('POINT(1 1)') as json));
-select json_type(cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json));
-select json_type(cast(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
- (5 5,7 5,7 7,5 7, 5 5))') as json));
-select json_type(cast(null as json));
-select json_type(cast(null as json)) is null; # check that it is an SQL NULL
+select json_type(json_compact(cast('2014-11-25 18:00' as datetime)));
+select json_type(json_compact(cast('2014-11-25' as date)));
+select json_type(json_compact(cast('18:00:59' as time)));
+# select json_type(json_compact(cast('2014-11-25 18:00' as timestamp))); -- cast target type not supported
+
+# select json_type(json_compact(cast('1999' as year))); -- cast target type not supported
+select json_type(json_compact(127));
+select json_type(json_compact(255));
+select json_type(json_compact(32767));
+select json_type(json_compact(65535));
+select json_type(json_compact(8388607));
+select json_type(json_compact(16777215));
+select json_type(json_compact(2147483647));
+select json_type(json_compact(4294967295));
+select json_type(json_compact(9223372036854775807));
+select json_type(json_compact(18446744073709551615));
+select json_type(json_compact(true));
+select json_type(json_compact(b'10101'));
+
+select json_type(json_compact(cast(3.14 as decimal(5,2))));
+select json_type(json_compact(3.14));
+select json_type(json_compact(3.14E30));
+# select json_type(json_compact(cast(3.14 as numeral(5,2)))); -- cast target type not supported
+
+# select json_type(json_compact(cast(3.14 as double))); -- cast target type not supported
+# select json_type(json_compact(cast(3.14 as float))); -- cast target type not supported
+
+# select json_type(json_compact(cast(b'10101' as bit(10)))); -- cast target type not supported
+# select json_type(json_compact(cast('10101abcde' as blob))); -- cast target type not supported
+select json_type(json_compact(cast('10101abcde' as binary)));
+
+# select json_type(json_compact(cast('a' as enum('a','b','c')))); -- cast target type not supported
+# select json_type(json_compact(cast('a,c' as set('a','b','c')))); -- cast target type not supported
+
+select json_type(json_compact(ST_GeomFromText('POINT(1 1)')));
+select json_type(json_compact(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)')));
+select json_type(json_compact(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
+ (5 5,7 5,7 7,5 7, 5 5))')));
+select json_type(json_compact(null));
+select json_type(json_compact(null)) is null; # check that it is an SQL NULL
select json_type(null) is null; # is an SQL NULL
#
# same, but now show the printable value:
#
-select cast(cast('2014-11-25 18:00' as datetime) as json);
-select cast(cast('2014-11-25' as date) as json);
-select cast(cast('18:00:59' as time) as json);
-# select cast(cast('2014-11-25 18:00' as timestamp) as json); -- cast target type not supported
-
-# select cast(cast('1999' as year) as json); -- cast target type not supported
-select cast(127 as json);
-select cast(255 as json);
-select cast(32767 as json);
-select cast(65535 as json);
-select cast(8388607 as json);
-select cast(16777215 as json);
-select cast(2147483647 as json);
-select cast(4294967295 as json);
-select cast(9223372036854775807 as json);
-select cast(18446744073709551615 as json);
-select cast(true as json);
-select cast(b'10101' as json);
-
-select cast(cast(3.14 as decimal(5,2)) as json);
-select cast(3.14 as json);
-select cast(3.14e0 as json);
-# select cast(cast(3.14 as numeral(5,2)) as json); -- cast target type not supported
-
-# select cast(cast(3.14 as double) as json); -- cast target type not supported
-# select cast(cast(3.14 as float) as json); -- cast target type not supported
-
-# select cast(cast(b'10101' as bit(10) as json); -- cast target type not supported
-# select cast(cast('10101abcde' as blob) as json); -- cast target type not supported
-select cast(cast('10101abcde' as binary) as json);
-
-# select cast(cast('a' as enum('a','b','c') as json); -- cast target type not supported
-# select cast(cast('a,c' as set('a','b','c') as json); -- cast target type not supported
-
-select cast(ST_GeomFromText('POINT(1 1)') as json);
-select cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json);
-select cast(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
- (5 5,7 5,7 7,5 7, 5 5))') as json);
-select cast(null as json);
-select cast(null as json) is null; # check that it is an SQL NULL
+select json_compact(cast('2014-11-25 18:00' as datetime));
+select json_compact(cast('2014-11-25' as date));
+select json_compact(cast('18:00:59' as time));
+# select json_compact(cast('2014-11-25 18:00' as timestamp)); -- cast target type not supported
+
+# select json_compact(cast('1999' as year)); -- cast target type not supported
+select json_compact(127);
+select json_compact(255);
+select json_compact(32767);
+select json_compact(65535);
+select json_compact(8388607);
+select json_compact(16777215);
+select json_compact(2147483647);
+select json_compact(4294967295);
+select json_compact(9223372036854775807);
+select json_compact(18446744073709551615);
+select json_compact(true);
+select json_compact(b'10101');
+
+select json_compact(cast(3.14 as decimal(5,2)));
+select json_compact(3.14);
+select json_compact(3.14e0);
+# select json_compact(cast(3.14 as numeral(5,2))); -- cast target type not supported
+
+# select json_compact(cast(3.14 as double)); -- cast target type not supported
+# select json_compact(cast(3.14 as float)); -- cast target type not supported
+
+# select json_compact(cast(b'10101' as bit(10)); -- cast target type not supported
+# select json_compact(cast('10101abcde' as blob)); -- cast target type not supported
+select json_compact(cast('10101abcde' as binary));
+
+# select json_compact(cast('a' as enum('a','b','c')); -- cast target type not supported
+# select json_compact(cast('a,c' as set('a','b','c')); -- cast target type not supported
+
+select json_compact(ST_GeomFromText('POINT(1 1)'));
+select json_compact(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)'));
+select json_compact(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
+ (5 5,7 5,7 7,5 7, 5 5))'));
+select json_compact(null);
+select json_compact(null) is null; # check that it is an SQL NULL
--echo # ----------------------------------------------------------------------
--echo # Test of JSON_KEYS function.
@@ -761,7 +761,7 @@ SELECT JSON_KEYS('{}', '$', '$');
--echo # conversion tests.
--echo # ----------------------------------------------------------------------
select cast(json_keys('{"a": 1}') as char);
-select cast(cast(1 as json) as char);
+select cast(json_compact(1) as char);
select cast(json_keys(NULL) as char);
#select cast(j as char) from keys1;
@@ -996,8 +996,8 @@ select json_extract( '[ { "a": [3,4] }, { "b": 2 } ]', '$[0].a', '$[1].a' ) jdoc
--echo # ----------------------------------------------------------------------
# NULLs
-select json_array_append(NULL, '$.b', cast(1 as json));
-select json_array_append('[1,2,3]', NULL, cast(1 as json));
+select json_array_append(NULL, '$.b', json_compact(1));
+select json_array_append('[1,2,3]', NULL, json_compact(1));
select json_array_append('[1,2,3]', '$', NULL);
# wrong # args
@@ -1009,25 +1009,25 @@ select json_array_append(NULL, NULL);
select json_array_append(NULL, NULL, NULL, NULL);
# auto-wrap
-SELECT JSON_ARRAY_APPEND(cast('1' as json), '$', 3);
-SELECT JSON_ARRAY_APPEND(cast('{"a": 3}' as json), '$', 3);
+SELECT JSON_ARRAY_APPEND(json_compact('1'), '$', 3);
+SELECT JSON_ARRAY_APPEND(json_compact('{"a": 3}'), '$', 3);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_array_append(cast('{"a": {"b": [3]}}' as json), '$**[0]', 6);
+select json_array_append(json_compact('{"a": {"b": [3]}}'), '$**[0]', 6);
# Examples from the specification
--echo # Auto-wrapping, since because the paths identify scalars.
--echo # should return {"a": "foo", "b": ["bar", 4], "c": ["wibble", "grape"]}
SELECT JSON_ARRAY_APPEND('{"a": "foo", "b": "bar", "c": "wibble"}',
- '$.b', cast(4 as json),
- '$.c', cast('"grape"' as json));
+ '$.b', json_compact(4),
+ '$.c', json_compact('"grape"'));
--echo # should return {"a": "foo", "b": [1, 2, 3, 4],
--echo # "c": ["apple", "pear", "grape"]}
SELECT JSON_ARRAY_APPEND('{"a" : "foo","b": [1, 2, 3], "c": ["apple", "pear"]}',
- '$.b', cast(4 as json),
- '$.c', cast('"grape"' as json));
+ '$.b', json_compact(4),
+ '$.c', json_compact('"grape"'));
# without CAST: cf. not required for ANY_JSON_ATOM arguments in specification
SELECT JSON_ARRAY_APPEND('{"a" : "foo","b": [1, 2, 3], "c": ["apple", "pear"]}',
@@ -1070,8 +1070,8 @@ select json_array_append('3', '$[0][0][0][0]', 100);
--echo # ----------------------------------------------------------------------
# NULLs
-select json_insert(NULL, '$.b', cast(1 as json));
-select json_insert('[1,2,3]', NULL, cast(1 as json));
+select json_insert(NULL, '$.b', json_compact(1));
+select json_insert('[1,2,3]', NULL, json_compact(1));
select json_insert('[1,2,3]', '$[3]', NULL);
# wrong # args
@@ -1104,35 +1104,35 @@ select json_insert('{"a": 3}', '$.a[1]', 4, '$.a[2]', '5');
# wild card & auto-wrap (scalars)
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": [1], "b": 2}' as json), '$.*[1]', 6);
+select json_insert(json_compact('{"a": [1], "b": 2}'), '$.*[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": 1, "b": 2}' as json), '$.*[1]', 6);
+select json_insert(json_compact('{"a": 1, "b": 2}'), '$.*[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": {"b": 3}}' as json), '$.a.*[1]', 6);
+select json_insert(json_compact('{"a": {"b": 3}}'), '$.a.*[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": {"b": [3]}}' as json), '$.a.*[1]', 6);
+select json_insert(json_compact('{"a": {"b": [3]}}'), '$.a.*[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": {"b": 3}}' as json), '$**[1]', 6);
+select json_insert(json_compact('{"a": {"b": 3}}'), '$**[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
+select json_insert(json_compact('{"a": {"b": [3]}}'), '$**[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[1]' as json), '$[*][1]', 6);
+select json_insert(json_compact('[1]'), '$[*][1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[1]' as json), '$**[1]', 6);
+select json_insert(json_compact('[1]'), '$**[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[1, [2], 3]' as json), '$[*][1]', 6);
+select json_insert(json_compact('[1, [2], 3]'), '$[*][1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[1, [2], 3]' as json), '$**[1]', 6);
+select json_insert(json_compact('[1, [2], 3]'), '$**[1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[[1]]' as json), '$[*][1]', 6);
+select json_insert(json_compact('[[1]]'), '$[*][1]', 6);
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_insert(cast('[[1]]' as json), '$**[1]', 6);
+select json_insert(json_compact('[[1]]'), '$**[1]', 6);
# auto-wrap object
-select json_insert(cast('{"a": 3}' as json), '$[1]', 6);
+select json_insert(json_compact('{"a": 3}'), '$[1]', 6);
# Examples from the specification
@@ -1270,7 +1270,7 @@ select json_insert('[]', '$[*][1]', 6);
# multiple paths,
select json_array_insert( '[ 1, 2, 3 ]', '$[1]', true, '$[1]', false );
select json_array_insert( '[ 1, 2, 3 ]', '$[1]',
- cast( '[ "a", "b", "c", "d" ]' as json ), '$[1][2]', false );
+ json_compact( '[ "a", "b", "c", "d" ]'), '$[1][2]', false );
# test an error while evaluating the document expression
--echo error ER_INVALID_JSON_TEXT_IN_PARAM
@@ -1285,8 +1285,8 @@ select json_array_insert( '[ 1, 2, 3 ]', '$[1]', json_extract( '[', '$' ) );
--echo # ----------------------------------------------------------------------
# NULLs
-select json_set(NULL, '$.b', cast(1 as json));
-select json_set('[1,2,3]', NULL, cast(1 as json));
+select json_set(NULL, '$.b', json_compact(1));
+select json_set('[1,2,3]', NULL, json_compact(1));
select json_set('[1,2,3]', '$[3]', NULL);
# wrong # args
@@ -1323,7 +1323,7 @@ select json_set('{"a": 3}', '$.a[1]', 4, '$.a[2]', '5');
# auto-wrap plus ellipsis with nested hits should give: {"a": [{"b": [3, 6]}, 6]}
--echo error ER_INVALID_JSON_PATH_WILDCARD
-select json_set(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
+select json_set(json_compact('{"a": {"b": [3]}}'), '$**[1]', 6);
# Examples from the specification: Include when missing functions are
# available.
@@ -1341,7 +1341,7 @@ select json_set(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
# # returns { "a" : "foo", "b" : [ 1, 2, 3 ], "c" : [ true, false ] }
# SELECT JSON_SET('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
# '$.c',
-# JSON_ARRAY( CAST( 'true' AS JSON ), CAST( 'false' AS JSON ) ));
+# JSON_ARRAY( json_compact( 'true'), json_compact( 'false') ));
# # returns [ 1, null, null, 2 ]
# SELECT JSON_SET('1', '$[3]', 2);
@@ -1353,19 +1353,19 @@ SELECT JSON_SET('{ "a" : "foo"}', '$.a',
# returns { "a" : {}, "b" : [ 1, 2, 3 ] }
select json_set('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.a',
- cast('{}' as json));
+ json_compact('{}'));
# returns { "a" : "foo", "b" : [ 1, 2, 3 ], "c" : [ true, false ] }
select json_set('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.c',
- cast('[true, false]' as json));
+ json_compact('[true, false]'));
# returns [ 1, null, null, 2 ]
select json_set('1', '$[3]', 2);
# should return { "a": { "b": false, "c": true } }
select json_set('{ "a" : "foo"}', '$.a',
- cast('{"b": false}' as json), '$.a.c', true);
+ json_compact('{"b": false}'), '$.a.c', true);
# examples from wl7909 spec
# returns {"a": {}, "b": [1, 2, 3]}
@@ -1389,7 +1389,7 @@ SELECT JSON_SET
(
'{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
'$.c',
- JSON_ARRAY( CAST( 'true' AS JSON ), CAST( 'false' AS JSON ) )
+ JSON_ARRAY( json_compact( 'true'), json_compact( 'false') )
);
# returns [1, 2]
@@ -1413,8 +1413,8 @@ SELECT JSON_SET
--echo # ----------------------------------------------------------------------
# NULLs
-select json_replace(NULL, '$.b', cast(1 as json));
-select json_replace('[1,2,3]', NULL, cast(1 as json));
+select json_replace(NULL, '$.b', json_compact(1));
+select json_replace('[1,2,3]', NULL, json_compact(1));
select json_replace('[1,2,3]', '$[2]', NULL);
# wrong # args
@@ -1468,8 +1468,8 @@ SELECT JSON_REPLACE('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
--echo # ----------------------------------------------------------------------
# NULLs
-select json_array(NULL, '$.b', cast(1 as json));
-select json_array('[1,2,3]', NULL, cast(1 as json));
+select json_array(NULL, '$.b', json_compact(1));
+select json_array('[1,2,3]', NULL, json_compact(1));
select json_array('[1,2,3]', '$[3]', NULL);
@@ -1477,7 +1477,7 @@ select json_array('[1,2,3]', '$[3]', NULL);
select json_array();
select json_array(3.14);
select json_array('[1,2,3]');
-select json_array(cast('[1,2,3]' as json));
+select json_array(json_compact('[1,2,3]'));
select json_array(1,2,3);
select json_array(b'0', b'1', b'10');
@@ -1503,8 +1503,8 @@ select json_object();
select json_object( 'a', null );
select json_object( 'a', 1 );
select json_object( 'a', 1, 'b', 'foo' );
-select json_object( 'a', 1, 'b', 'foo', 'c', cast( '{ "d": "wibble" }' as json ) );
-select json_object( 'a', true, 'b', false, 'c', cast( 'null' as json) );
+select json_object( 'a', 1, 'b', 'foo', 'c', json_compact( '{ "d": "wibble" }') );
+select json_object( 'a', true, 'b', false, 'c', json_compact( 'null') );
select json_valid( json_object( '"a"', 1 ) );
# long key
@@ -1707,29 +1707,29 @@ SELECT JSON_UNQUOTE
);
select json_type(case (null is null) when 1 then
- cast('null' as json) else
- cast('[1,2,3]' as json) end);
+ json_compact('null') else
+ json_compact('[1,2,3]') end);
select json_type(case (null is not null) when 1 then
- cast('null' as json) else
- cast('[1,2,3]' as json) end);
+ json_compact('null') else
+ json_compact('[1,2,3]') end);
select json_type( if(null is null,
- cast('null' as json),
- cast('[1,2,3]' as json)) );
+ json_compact('null'),
+ json_compact('[1,2,3]')) );
select json_type( if(null is not null,
- cast('null' as json),
- cast('[1,2,3]' as json)));
+ json_compact('null'),
+ json_compact('[1,2,3]')));
-select cast(json_extract(cast(concat('[', cast('["A",2]' as json), ']') as json),
+select cast(json_extract(json_compact(concat('[', json_compact('["A",2]'), ']')),
'$[0][1]') as char) = 2;
--echo # ----------------------------------------------------------------------
--echo # Test of aggregate function MAX, MIN.
--echo # ----------------------------------------------------------------------
-select max(cast('[1,2,3]' as json));
+select max(json_compact('[1,2,3]'));
--echo # ----------------------------------------------------------------------
--echo # Test of JSON_QUOTE, JSON_UNQUOTE
@@ -1781,26 +1781,26 @@ select json_unquote(123); # integer not allowed
select json_unquote('""'); # empty string
select char_length(json_unquote('""')); # verify empty string
select json_unquote('"" '); # unchanged: no final "
-select json_unquote(cast(json_quote('abc') as json)); # round trip
+select json_unquote(json_compact(json_quote('abc'))); # round trip
# No change in this JSON string: it is an object
-select cast('{"abc": "foo"}' as json);
-select json_unquote(cast('{"abc": "foo"}' as json));
+select json_compact('{"abc": "foo"}');
+select json_unquote(json_compact('{"abc": "foo"}'));
# This is a JSON string, so it is actually unquoted
-select json_extract(cast('{"abc": "foo"}' as json), '$.abc');
-select json_unquote(json_extract(cast('{"abc": "foo"}' as json), '$.abc'));
+select json_extract(json_compact('{"abc": "foo"}'), '$.abc');
+select json_unquote(json_extract(json_compact('{"abc": "foo"}'), '$.abc'));
# Bug fix: thse should be the same
select json_unquote('["a", "b", "c"]');
-select json_unquote(cast('["a", "b", "c"]' as json));
+select json_unquote(json_compact('["a", "b", "c"]'));
select charset(json_unquote('"abc"'));
select json_quote(convert(X'e68891' using utf8)); # chinese "I" (wo3)
select json_quote(convert(X'e68891' using utf8mb4)); # chinese "I" (wo3)
-select cast(json_quote(convert(X'e68891' using utf8)) as json);
+select json_compact(json_quote(convert(X'e68891' using utf8)));
select json_unquote(convert(X'e68891' using utf8)); # chinese "I" (wo3)
@@ -1809,12 +1809,12 @@ select json_unquote(json_unquote(json_unquote( # long round trip of it
json_quote(json_quote(json_quote('abc'))))));
# DATE/TIME will lose their quotes, too:
-select cast(cast('2015-01-15 23:24:25' as datetime) as json);
-select json_unquote(cast(cast('2015-01-15 23:24:25' as datetime) as json));
+select json_compact(cast('2015-01-15 23:24:25' as datetime));
+select json_unquote(json_compact(cast('2015-01-15 23:24:25' as datetime)));
# as well as opaque values:
-select cast(st_geomfromtext('point(1 1)') as json);
-select json_unquote(cast(st_geomfromtext('point(1 1)') as json));
+select json_compact(st_geomfromtext('point(1 1)'));
+select json_unquote(json_compact(st_geomfromtext('point(1 1)')));
# examples from the wl7909 spec
# returns the SQL string literal abc
@@ -1828,7 +1828,7 @@ SELECT JSON_UNQUOTE( 123 );
# returns the SQL string literal abc
SELECT JSON_UNQUOTE
-( CAST( CAST( '"abc"' AS JSON ) AS CHAR ) );
+( CAST( json_compact( '"abc"') AS CHAR ) );
# returns 1
SELECT JSON_UNQUOTE
@@ -1853,7 +1853,7 @@ SELECT JSON_QUOTE( 'abc' );
SELECT JSON_QUOTE( 123 );
# returns the JSON document consisting of the string scalar "123"
-SELECT CAST( JSON_QUOTE( '123' ) AS JSON );
+SELECT json_compact( JSON_QUOTE( '123' ));
--echo # ----------------------------------------------------------------------
--echo # Test of JSON_CONTAINS
@@ -1861,47 +1861,47 @@ SELECT CAST( JSON_QUOTE( '123' ) AS JSON );
--echo # should give NULL
select json_contains(NULL, NULL);
-select json_contains(cast('{"a": 1, "b": 2}' as json), NULL);
-select json_contains(NULL, cast('null' as json));
-select json_contains(cast('[1]' as json), cast('[1]' as json), NULL);
+select json_contains(json_compact('{"a": 1, "b": 2}'), NULL);
+select json_contains(NULL, json_compact('null'));
+select json_contains(json_compact('[1]'), json_compact('[1]'), NULL);
--echo # should give 0:
-select json_contains(cast(3.14 as json), cast(3 as json));
+select json_contains(json_compact(3.14), json_compact(3));
--echo # should give 0: not at top level
-select json_contains(cast('{"a": {"b": 7}}' as json), cast('{"b": 7}' as json));
+select json_contains(json_compact('{"a": {"b": 7}}'), json_compact('{"b": 7}'));
--echo # but path argument will fix it:
-select json_contains(cast('{"a": {"b": 7}}' as json), cast('{"b": 7}' as json), '$.a');
+select json_contains(json_compact('{"a": {"b": 7}}'), json_compact('{"b": 7}'), '$.a');
--echo # but arrays "introspect"
-select json_contains(cast('[1,[2.0, 3.0]]' as json), cast('[2.0]' as json));
-select json_contains(cast('[1, 2, [3, [4, 5]], 6, 7]' as json), cast('5' as json));
+select json_contains(json_compact('[1,[2.0, 3.0]]'), json_compact('[2.0]'));
+select json_contains(json_compact('[1, 2, [3, [4, 5]], 6, 7]'), json_compact('5'));
--echo # should give 0: just a key
-select json_contains(cast('{"a": 1, "b": 2}' as json), cast('"a"' as json));
+select json_contains(json_compact('{"a": 1, "b": 2}'), json_compact('"a"'));
--echo # should give 0: one candidate element doesn't match
-select json_contains(cast('[1]' as json), cast('[1,2]' as json));
+select json_contains(json_compact('[1]'), json_compact('[1,2]'));
--echo # should all give 1
-select json_contains(cast('null' as json), cast('null' as json));
+select json_contains(json_compact('null'), json_compact('null'));
--echo # simple object subset
-select json_contains(cast('{"a": 1, "b": 2}' as json), cast( '{"a": 1}' as json));
+select json_contains(json_compact('{"a": 1, "b": 2}'), json_compact( '{"a": 1}'));
--echo # simple vector subset
-select json_contains(cast('[1, 2, 3]' as json), cast('[1, 3]' as json));
+select json_contains(json_compact('[1, 2, 3]'), json_compact('[1, 3]'));
--echo # auto-wrap, should give 1
-select json_contains(cast('[1, 2, 3]' as json), cast(3 as json));
+select json_contains(json_compact('[1, 2, 3]'), json_compact(3));
--echo # ok even with nested cast off elements
-select json_contains(cast('{"person": {"id": 1, "country": "norway"}}' as json),
- cast('{"person": {"country": "norway"}}' as json));
+select json_contains(json_compact('{"person": {"id": 1, "country": "norway"}}'),
+ json_compact('{"person": {"country": "norway"}}'));
--echo # vector reordering and duplicates is ok
-select json_contains(cast('[1,3,5]' as json), cast('[5,3,1,5]' as json));
+select json_contains(json_compact('[1,3,5]'), json_compact('[5,3,1,5]'));
--echo # ok even with more elts in candidate than in doc
-select json_contains(cast('[{"b": 4, "a":7}]' as json), cast('[{"a":7},{"b":4}]' as json));
-select json_contains(cast('[{"b": 4, "a":7}, 5]' as json), cast('[5, {"a":7, "b":4}]' as json));
+select json_contains(json_compact('[{"b": 4, "a":7}]'), json_compact('[{"a":7},{"b":4}]'));
+select json_contains(json_compact('[{"b": 4, "a":7}, 5]'), json_compact('[5, {"a":7, "b":4}]'));
--echo # ok even with mixed number types that compare equal
-select json_contains(cast('[{"b": 4, "a":7}, 5.0]' as json), cast('[5, {"a":7.0E0, "b":4}]' as json));
+select json_contains(json_compact('[{"b": 4, "a":7}, 5.0]'), json_compact('[5, {"a":7.0E0, "b":4}]'));
# Bug discovered by Rick: used to give 1 (true).
select json_contains( '{"customer": "cust3"}', '{"customer": "cust1"}' );
@@ -1919,36 +1919,36 @@ SELECT JSON_CONTAINS('{"a":1}', '{"a":1,"b":2}');
# returns 1
SELECT JSON_CONTAINS
(
- CAST('[1, 4, 6]' AS JSON),
- CAST('[1, 6]' AS JSON)
+ json_compact('[1, 4, 6]'),
+ json_compact('[1, 6]')
);
# returns 1; even with nested cast off elements
SELECT JSON_CONTAINS
(
- CAST('{"person": {"id": 1, "country": "norway"}}' AS JSON),
- CAST('{"person": {"country": "norway"}}' AS JSON)
+ json_compact('{"person": {"id": 1, "country": "norway"}}'),
+ json_compact('{"person": {"country": "norway"}}')
);
# returns 1; reordering and duplicates are ok
SELECT JSON_CONTAINS
(
- CAST('[1,3,5]' AS JSON),
- CAST('[5,3,1,5]' AS JSON)
+ json_compact('[1,3,5]'),
+ json_compact('[5,3,1,5]')
);
# return 0; no type conversion is performed
SELECT JSON_CONTAINS
(
- CAST('[3.14]' AS JSON),
- CAST('[3]' AS JSON)
+ json_compact('[3.14]'),
+ json_compact('[3]')
);
# returns 1, due to auto-wrapping
SELECT JSON_CONTAINS
(
- CAST('[1, 2, 3]' AS JSON),
- CAST(3 AS JSON)
+ json_compact('[1, 2, 3]'),
+ json_compact(3)
);
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
@@ -1963,20 +1963,20 @@ SELECT JSON_CONTAINS('[1]', '[1]', '$', '$[0]');
--echo # Item_func_json_quote::fix_length_and_dec. Bug found by Knut.
--echo # Similar issue for JSON_UNQUOTE and JSON_TYPE.
--echo # ----------------------------------------------------------------------
-select json_object("a", ifnull(json_quote('test'), cast('null' as json)));
-select cast(concat('[', json_quote('ab'), ']') as json);
-select cast(concat('[', json_unquote('"12"'), ']') as json);
-select cast(concat('["', json_type(cast(1 as json)), '"]') as json);
+select json_object("a", ifnull(json_quote('test'), json_compact('null')));
+select json_compact(concat('[', json_quote('ab'), ']'));
+select json_compact(concat('[', json_unquote('"12"'), ']'));
+select json_compact(concat('["', json_type( json_compact(1)), '"]'));
--echo #
--echo # Bug#20912438: ITEM_TYPE_HOLDER::DISPLAY_LENGTH(ITEM*): ASSERTION `0' FAILED
--echo #
(SELECT JSON_KEYS('{ "key80": "2015-04-20 11:53:55"}')) UNION ALL
(SELECT JSON_KEYS('{ "key80": "2015-04-20 11:53:55" }') LIMIT 0);
-SELECT CAST(1 AS JSON) UNION ALL SELECT CAST(1 AS JSON);
+SELECT json_compact(1) UNION ALL SELECT json_compact(1);
# Exercise NULL handling and error handling in Item_copy_json::copy().
-SELECT COUNT(*), CAST(NULL AS JSON);
+SELECT COUNT(*), json_compact(NULL);
--echo error ER_INVALID_JSON_TEXT_IN_PARAM
SELECT COUNT(*), JSON_EXTRACT('not valid json!', '$');
@@ -2118,7 +2118,7 @@ execute json_stmt12 USING @mypath;
--echo #
select json_quote( json_type( json_object() ) );
-select json_quote( json_type( cast('{}' as json) ) );
+select json_quote( json_type( json_compact('{}') ) );
--echo #
--echo # Bug#21148020 OUTPUT FROM JSON_TYPE() IS TRUNCATED
@@ -2130,9 +2130,9 @@ CREATE VIEW v1 AS SELECT JSON_TYPE(JSON_OBJECT());
SELECT * FROM v1;
drop view v1;
-# SELECT JSON_TYPE(CAST(CAST('2015-05-25 11:23:55' AS DATETIME) AS JSON));
-# CREATE VIEW v2 AS SELECT JSON_TYPE(CAST(CAST('2015-05-25 11:23:55' AS
-# DATETIME) AS JSON));
+# SELECT JSON_TYPE(json_compact(CAST('2015-05-25 11:23:55' AS DATETIME)));
+# CREATE VIEW v2 AS SELECT JSON_TYPE(json_compact(CAST('2015-05-25 11:23:55' AS
+# DATETIME)));
# SELECT * FROM v2;
# drop view v2;
@@ -2284,5 +2284,5 @@ SELECT JSON_REPLACE('[[[1]]]', '$[0][0][0]', 100);
# a mix of NULLs and JSON values.
SELECT JSON_ARRAY(LEAST(NULL, NULL), GREATEST(NULL, NULL), LEAST(j1, NULL),
GREATEST(NULL, j2), LEAST(j1, j2), GREATEST(j1, j2)) AS j
-FROM (SELECT CAST('1' AS JSON) AS j1, CAST('2' AS JSON) AS j2) t;
+FROM (SELECT json_compact('1') AS j1, json_compact('2') AS j2) t;
diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test
index be56eb46d09..09e4f30c325 100644
--- a/mysql-test/t/func_json.test
+++ b/mysql-test/t/func_json.test
@@ -161,10 +161,10 @@ select json_unquote('abc');
select json_object("a", json_object("b", "abcd"));
select json_object("a", '{"b": "abcd"}');
-select json_object("a", cast('{"b": "abcd"}' as json));
+select json_object("a", json_compact('{"b": "abcd"}'));
-select cast(NULL AS JSON);
-select json_depth(cast(NULL as JSON));
+select json_compact(NULL);
+select json_depth(json_compact(NULL));
select json_depth('[[], {}]');
select json_depth('[[[1,2,3],"s"], {}, []]');
select json_depth('[10, {"a": 20}]');
diff --git a/sql/item.h b/sql/item.h
index 07f489a35a3..27fb716e0c9 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1095,6 +1095,8 @@ public:
Returns the val_str() value converted to the given character set.
*/
String *val_str(String *str, String *converter, CHARSET_INFO *to);
+
+ virtual String *val_json(String *str) { return val_str(str); }
/*
Return decimal representation of item with fixed point.
diff --git a/sql/item_create.cc b/sql/item_create.cc
index dee1db1ee2e..4730e187ebe 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -7228,9 +7228,6 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type,
res= new (thd->mem_root) Item_char_typecast(thd, a, len, real_cs);
break;
}
- case ITEM_CAST_JSON:
- res= new (thd->mem_root) Item_json_typecast(thd, a);
- break;
default:
{
DBUG_ASSERT(0);
diff --git a/sql/item_func.h b/sql/item_func.h
index 08b1421cb1d..1f8d1ddb67e 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -2221,7 +2221,7 @@ enum Cast_target
{
ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT,
ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME, ITEM_CAST_CHAR,
- ITEM_CAST_DECIMAL, ITEM_CAST_DOUBLE, ITEM_CAST_JSON
+ ITEM_CAST_DECIMAL, ITEM_CAST_DOUBLE
};
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc
index 59d49b81d4a..925a7e437f2 100644
--- a/sql/item_jsonfunc.cc
+++ b/sql/item_jsonfunc.cc
@@ -373,7 +373,7 @@ static int path_setup_nwc(json_path_t *p, CHARSET_INFO *i_cs,
longlong Item_func_json_valid::val_int()
{
- String *js= args[0]->val_str(&tmp_value);
+ String *js= args[0]->val_json(&tmp_value);
json_engine_t je;
if ((null_value= args[0]->null_value))
@@ -401,7 +401,7 @@ longlong Item_func_json_exists::val_int()
json_engine_t je;
uint array_counters[JSON_DEPTH_LIMIT];
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
if (!path.parsed)
{
@@ -454,7 +454,7 @@ void Item_func_json_value::fix_length_and_dec()
String *Item_func_json_value::val_str(String *str)
{
json_engine_t je;
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
int error= 0;
uint array_counters[JSON_DEPTH_LIMIT];
@@ -587,7 +587,7 @@ void Item_func_json_unquote::fix_length_and_dec()
String *Item_func_json_unquote::val_str(String *str)
{
- String *js= args[0]->val_str(&tmp_s);
+ String *js= args[0]->val_json(&tmp_s);
json_engine_t je;
int c_len;
@@ -712,7 +712,7 @@ static bool path_ok(const json_path_with_flags *paths_list, int n_paths,
String *Item_func_json_extract::val_str(String *str)
{
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
json_engine_t je, sav_je;
json_path_t p;
const uchar *value;
@@ -817,7 +817,7 @@ return_null:
longlong Item_func_json_extract::val_int()
{
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
uint n_arg;
uint array_counters[JSON_DEPTH_LIMIT];
@@ -1040,7 +1040,7 @@ static int check_contains(json_engine_t *js, json_engine_t *value)
longlong Item_func_json_contains::val_int()
{
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
json_engine_t je, ve;
int result;
@@ -1049,7 +1049,7 @@ longlong Item_func_json_contains::val_int()
if (!a2_parsed)
{
- val= args[1]->val_str(&tmp_val);
+ val= args[1]->val_json(&tmp_val);
a2_parsed= a2_constant;
}
@@ -1179,7 +1179,7 @@ static int parse_one_or_all(const Item_func *f, Item *ooa_arg,
#ifdef DUMMY
longlong Item_func_json_contains_path::val_int()
{
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
uint n_arg;
longlong result;
@@ -1247,7 +1247,7 @@ return_null:
longlong Item_func_json_contains_path::val_int()
{
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
uint n_arg;
longlong result;
@@ -1351,7 +1351,7 @@ static int append_json_value(String *str, Item *item, String *tmp_val)
return str->append(t_f, t_f_len);
}
{
- String *sv= item->val_str(tmp_val);
+ String *sv= item->val_json(tmp_val);
if (item->null_value)
goto append_null;
if (item->is_json_type())
@@ -1461,7 +1461,7 @@ void Item_func_json_array_append::fix_length_and_dec()
String *Item_func_json_array_append::val_str(String *str)
{
json_engine_t je;
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
uint n_arg, n_path, str_rest_len;
const uchar *ar_end;
@@ -1588,7 +1588,7 @@ return_null:
String *Item_func_json_array_insert::val_str(String *str)
{
json_engine_t je;
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
uint n_arg, n_path;
DBUG_ASSERT(fixed == 1);
@@ -1959,7 +1959,7 @@ String *Item_func_json_merge::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
json_engine_t je1, je2;
- String *js1= args[0]->val_str(&tmp_js1), *js2;
+ String *js1= args[0]->val_json(&tmp_js1), *js2;
uint n_arg;
if (args[0]->null_value)
@@ -1970,7 +1970,7 @@ String *Item_func_json_merge::val_str(String *str)
str->set_charset(js1->charset());
str->length(0);
- js2= args[n_arg]->val_str(&tmp_js2);
+ js2= args[n_arg]->val_json(&tmp_js2);
if (args[n_arg]->null_value)
goto null_return;
@@ -2028,7 +2028,7 @@ void Item_func_json_length::fix_length_and_dec()
longlong Item_func_json_length::val_int()
{
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
uint length= 0;
uint array_counters[JSON_DEPTH_LIMIT];
@@ -2105,7 +2105,7 @@ null_return:
longlong Item_func_json_depth::val_int()
{
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
uint depth= 0, c_depth= 0;
bool inc_depth= TRUE;
@@ -2164,7 +2164,7 @@ void Item_func_json_type::fix_length_and_dec()
String *Item_func_json_type::val_str(String *str)
{
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
const char *type;
@@ -2232,7 +2232,7 @@ void Item_func_json_insert::fix_length_and_dec()
String *Item_func_json_insert::val_str(String *str)
{
json_engine_t je;
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
uint n_arg, n_path;
json_string_t key_name;
@@ -2478,7 +2478,7 @@ void Item_func_json_remove::fix_length_and_dec()
String *Item_func_json_remove::val_str(String *str)
{
json_engine_t je;
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
uint n_arg, n_path;
json_string_t key_name;
@@ -2661,7 +2661,7 @@ void Item_func_json_keys::fix_length_and_dec()
String *Item_func_json_keys::val_str(String *str)
{
json_engine_t je;
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
uint n_keys= 0;
uint array_counters[JSON_DEPTH_LIMIT];
@@ -2837,7 +2837,7 @@ static int append_json_path(String *str, const json_path_t *p)
String *Item_func_json_search::val_str(String *str)
{
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
String *s_str= args[2]->val_str(&tmp_js);
json_engine_t je;
json_path_t p, sav_path;
@@ -2934,21 +2934,6 @@ null_return:
}
-void Item_json_typecast::fix_length_and_dec()
-{
- maybe_null= args[0]->maybe_null;
- max_length= args[0]->max_length;
-}
-
-
-String *Item_json_typecast::val_str(String *str)
-{
- String *vs= args[0]->val_str(str);
- null_value= args[0]->null_value;
- return vs;
-}
-
-
const char *Item_func_json_format::func_name() const
{
switch (fmt)
@@ -2976,7 +2961,7 @@ void Item_func_json_format::fix_length_and_dec()
String *Item_func_json_format::val_str(String *str)
{
- String *js= args[0]->val_str(&tmp_js);
+ String *js= args[0]->val_json(&tmp_js);
json_engine_t je;
int tab_size= 4;
@@ -3016,3 +3001,12 @@ String *Item_func_json_format::val_str(String *str)
}
+String *Item_func_json_format::val_json(String *str)
+{
+ String *js= args[0]->val_json(&tmp_js);
+ if ((null_value= args[0]->null_value))
+ return 0;
+ return js;
+}
+
+
diff --git a/sql/item_jsonfunc.h b/sql/item_jsonfunc.h
index 0eedfa18be1..535f1bf73a5 100644
--- a/sql/item_jsonfunc.h
+++ b/sql/item_jsonfunc.h
@@ -414,19 +414,6 @@ public:
};
-class Item_json_typecast: public Item_str_func
-{
-public:
- Item_json_typecast(THD *thd, Item *a): Item_str_func(thd, a) {}
- const char *func_name() const { return "cast_as_json"; }
- bool is_json_type() { return true; }
- void fix_length_and_dec();
- String *val_str(String *str);
- Item *get_copy(THD *thd, MEM_ROOT *mem_root)
- { return get_item_copy<Item_json_typecast>(thd, mem_root, this); }
-};
-
-
class Item_func_json_format: public Item_str_func
{
public:
@@ -449,6 +436,8 @@ public:
const char *func_name() const;
void fix_length_and_dec();
String *val_str(String *str);
+ String *val_json(String *str);
+ bool is_json_type() { return true; }
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_func_json_format>(thd, mem_root, this); }
};
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index ebf86d6066c..8939910fc29 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -7417,7 +7417,7 @@ ER_BINLOG_UNCOMPRESS_ERROR
ER_JSON_BAD_CHR
eng "Broken JSON string in argument %d to function '%s' at position %d"
ER_JSON_NOT_JSON_CHR
- eng "Character disallowd in JSON in argument %d to function '%s' at position %d"
+ eng "Character disallowed in JSON in argument %d to function '%s' at position %d"
ER_JSON_EOS
eng "Unexpected end of JSON text in argument %d to function '%s'"
ER_JSON_SYNTAX
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 14963c815a7..fe387ed80f2 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -10714,7 +10714,6 @@ cast_type:
}
| cast_type_numeric { $$= $1; Lex->charset= NULL; }
| cast_type_temporal { $$= $1; Lex->charset= NULL; }
- | JSON_SYM { $$.set(ITEM_CAST_JSON); }
;
cast_type_numeric: