日期赋值
MySQL日期字段的类型支持字符串赋值。
create table test (a datetime);
insert into test values('2014-02-02 00:00:00');
insert into test select '2014-02-02 00:00:01' ;
insert into test select cast('2014-02-02 00:00:02' as char);
update test set a = cast('2014-02-02 00:00:03' as char);
LightDB兼容
为了方便用户迁移,LightDB在23.4也兼容只用字符串赋值。
lightdb@mysql=# create table test (a datetime);
CREATE TABLE
lightdb@mysql=# insert into test values('2014-02-02 00:00:00');
INSERT 0 1
lightdb@mysql=# insert into test select '2014-02-02 00:00:01' ;
INSERT 0 1
lightdb@mysql=# insert into test select cast('2014-02-02 00:00:02' as char);
INSERT 0 1
lightdb@mysql=# select * from test;
a
---------------------
2014-02-02 00:00:00
2014-02-02 00:00:01
2014-02-02 00:00:02
(3 rows)
lightdb@mysql=# update test set a = cast('2014-02-02 00:00:03' as char);
UPDATE 3
lightdb@mysql=# select * from test;
a
---------------------
2014-02-02 00:00:03
2014-02-02 00:00:03
2014-02-02 00:00:03
(3 rows)