Commit d07daa31 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-13313 JSON type alias is insufficiently compatible

make JSON an alias for LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin

(same collation that item_jsonfunc.cc is using internally)
parent 04b288ae
...@@ -2,19 +2,21 @@ create or replace table t1(a json); ...@@ -2,19 +2,21 @@ create or replace table t1(a json);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` text DEFAULT NULL `a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
create or replace table t1(a json character set utf8 default '{a:1}'); create or replace table t1(a json character set utf8);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'character set utf8)' at line 1
create or replace table t1(a json default '{a:1}');
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` text CHARACTER SET utf8 DEFAULT '{a:1}' `a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '{a:1}'
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
create or replace table t1(a json binary not null check (json_valid(a))); create or replace table t1(a json not null check (json_valid(a)));
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` text CHARACTER SET latin1 COLLATE latin1_bin NOT NULL CHECK (json_valid(`a`)) `a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`a`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert t1 values ('[]'); insert t1 values ('[]');
insert t1 values ('a'); insert t1 values ('a');
...@@ -24,7 +26,7 @@ create or replace table t1(a json default(json_object('now', now()))); ...@@ -24,7 +26,7 @@ create or replace table t1(a json default(json_object('now', now())));
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` text DEFAULT json_object('now',current_timestamp()) `a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT json_object('now',current_timestamp())
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert t1 values (); insert t1 values ();
select * from t1; select * from t1;
......
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
create or replace table t1(a json); create or replace table t1(a json);
show create table t1; show create table t1;
create or replace table t1(a json character set utf8 default '{a:1}'); --error ER_PARSE_ERROR
create or replace table t1(a json character set utf8);
create or replace table t1(a json default '{a:1}');
show create table t1; show create table t1;
create or replace table t1(a json binary not null check (json_valid(a))); create or replace table t1(a json not null check (json_valid(a)));
show create table t1; show create table t1;
insert t1 values ('[]'); insert t1 values ('[]');
--error ER_CONSTRAINT_FAILED --error ER_CONSTRAINT_FAILED
......
...@@ -6478,8 +6478,11 @@ field_type: ...@@ -6478,8 +6478,11 @@ field_type:
{ $$.set(MYSQL_TYPE_SET); } { $$.set(MYSQL_TYPE_SET); }
| LONG_SYM opt_binary | LONG_SYM opt_binary
{ $$.set(MYSQL_TYPE_MEDIUM_BLOB); } { $$.set(MYSQL_TYPE_MEDIUM_BLOB); }
| JSON_SYM opt_binary | JSON_SYM
{ $$.set(MYSQL_TYPE_BLOB); } {
Lex->charset= &my_charset_utf8mb4_bin;
$$.set(MYSQL_TYPE_LONG_BLOB);
}
; ;
spatial_type: spatial_type:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment