Skip to content

Commit

Permalink
MDEV-13313 JSON type alias is insufficiently compatible
Browse files Browse the repository at this point in the history
make JSON an alias for LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin

(same collation that item_jsonfunc.cc is using internally)
  • Loading branch information
vuvova committed Aug 14, 2017
1 parent 04b288a commit d07daa3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
14 changes: 8 additions & 6 deletions mysql-test/r/type_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ create or replace table t1(a json);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` text DEFAULT NULL
`a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) 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;
Table Create Table
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
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;
Table Create Table
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
insert t1 values ('[]');
insert t1 values ('a');
Expand All @@ -24,7 +26,7 @@ create or replace table t1(a json default(json_object('now', now())));
show create table t1;
Table Create Table
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
insert t1 values ();
select * from t1;
Expand Down
7 changes: 5 additions & 2 deletions mysql-test/t/type_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
create or replace table t1(a json);
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;

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;
insert t1 values ('[]');
--error ER_CONSTRAINT_FAILED
Expand Down
7 changes: 5 additions & 2 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -6478,8 +6478,11 @@ field_type:
{ $$.set(MYSQL_TYPE_SET); }
| LONG_SYM opt_binary
{ $$.set(MYSQL_TYPE_MEDIUM_BLOB); }
| JSON_SYM opt_binary
{ $$.set(MYSQL_TYPE_BLOB); }
| JSON_SYM
{
Lex->charset= &my_charset_utf8mb4_bin;
$$.set(MYSQL_TYPE_LONG_BLOB);
}
;

spatial_type:
Expand Down

0 comments on commit d07daa3

Please sign in to comment.