在工作中遇到了json列,不清楚如何写SQL,查询了下相关的文档之后总结下,根据json列的值进行区分,列值指的是 json_type(json列)的结果
1、列值为NULL
create table t1(c1 int primary key, c2 json);
insert into t1 values(4, NULL);
select * from t1;
insert into t1 values(5, null);
select * from t1;
drop table t1;
2、列值为 time/date/datetime
create table t3(c1 varchar(30) not null, j json);
insert into t3 values ('time' ,cast(cast('10:10:10' as time) as json)), ('date' ,cast(cast('2010-10-10' as date) as json));
select j, json_type(j), j from t3;
insert into t3 values ('time' ,cast(cast('23:24:25' as time) as json));
select j, json_type(j), j from t3;
insert into t3 values ('date' ,cast(cast('2015-01-15' as date) as json));
select j, json_type(j), j from t3;
insert into t3 values ('datetime' ,cast(cast('2015-01-15 23:24:25' as datetime) as json));
select c1, j, json_type(j), j from t3;
3、列值为 signed/unsigned
create table t5(c1 varchar(30) not null, j json


3324

被折叠的 条评论
为什么被折叠?



