【TiDB 使用环境】生产环境
【TiDB 版本】v7.1.5
【操作系统】centos 7.9
【遇到的问题:问题现象及影响】
部分情况下,时间精度不希望四舍五入,希望直接将多余的小数截断,在 mysql 8.0 中有特性支持
https://dev.mysql.com/doc/refman/8.0/en/fractional-seconds.html
但是 tidb 和 mysql 5.7 的行为一致,会默认四舍五入,且没有找到修改的方法,或者有什么其他的函数,可以实现类似的效果
甚至我想到了,向下取整
mysql> select cast('2020-01-01 01:01:01.1115' as DATETIME(3));
+-------------------------------------------------+
| cast('2020-01-01 01:01:01.1115' as DATETIME(3)) |
+-------------------------------------------------+
| 2020-01-01 01:01:01.112 |
+-------------------------------------------------+
1 row in set (0.01 sec)
mysql> select from_unixtime(floor(unix_timestamp('2020-01-01 01:01:01.1115')*1000)/1000);
+----------------------------------------------------------------------------+
| from_unixtime(floor(unix_timestamp('2020-01-01 01:01:01.1115')*1000)/1000) |
+----------------------------------------------------------------------------+
| 2020-01-01 01:01:01.1110 |
+----------------------------------------------------------------------------+