A DATETIME or TIMESTAMP value can include a trailing fractional seconds part in up to microseconds (6 digits) precision. In particular, any fractional part in a value inserted into a DATETIME or TIMESTAMP column is stored rather than discarded. With the fractional part included, the format for these values is 'YYYY-MM-DD hh:mm:ss[.fraction]', the range for DATETIME values is '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999',
CREATE TABLE `dt_test` (
`trade_date` datetime NOT NULL,
PRIMARY KEY (`trade_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
mysql> insert into dt_test select '2022-01-01 00:00:00.000000';
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> insert into dt_test select '2022-01-01 00:00:00.120000';
ERROR 1062 (23000): Duplicate entry '2022-01-01 00:00:00' for key 'dt_test.PRIMARY'
I thought 2022-01-01 00:00:00.000000 is different with 2022-01-01 00:00:00.120000, so both should insert successfully. But actually only could insert one? What is the reason?