mariadb “date”dataType列,插入空值,同时插入0到1之间的值..例如0.08,0.99等

wlwcrazw  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(87)
CREATE TABLE `datesissue` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `dates` date DEFAULT NULL,
  `user` varchar(64) COLLATE utf8mb3_bin NOT NULL,
  `modified_user` varchar(64) COLLATE utf8mb3_bin NOT NULL,
  `created_date` datetime NOT NULL DEFAULT current_timestamp(),
  `modified_date` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `system_data_source` varchar(512) COLLATE utf8mb3_bin DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin


insert into datesissue (dates,user, modified_user) values(0.08,"abc","xyz")

update datesissue set dates = 0.00020596473883443116 where id = 1

字符串
我希望数据库抛出一个错误,
不正确的日期值:对于列datesissue . dates在第1行

bjg7j2ky

bjg7j2ky1#

MariaDB默认保留向后兼容性,这意味着接受无效日期。
如果您将SQL_MODE设置为包含NO_ZERO_DATE(以及NO_ZERO_IN_DATE),则会发生更符合预期的错误行为:

MariaDB [test]> set statement sql_mode=concat(@@sql_mode, ",NO_ZERO_DATE,NO_ZERO_IN_DATE") for update datesissue set dates =
0.20596473883443116;
ERROR 1292 (22007): Incorrect date value: '0.20596473883443116' for column `test`.`datesissue`.`dates` at row 1

字符串

相关问题