The table T has this field
+---------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+-------------------+-----------------------------+
| updated | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+---------------+--------------+------+-----+-------------------+-----------------------------+
In MySQL 5.7, doing an update of a record and setting updated=null
was automatically setting updated
to the current date-time
UPDATE T SET ...,updated=null WHERE k=123
==>
+---------------------+
| updated |
+---------------------+
| 2022-01-05 22:52:05 |
+---------------------+
But doing the same in MySQL 8.0, gives
+---------------------+
| updated |
+---------------------+
| 0000-00-00 00:00:00 |
+---------------------+
How can I fix that, is this a MySQL bug, or a new setting (or a change in behavior)?
updated=NOW
, or because it has aon update CURRENT_TIMESTAMP
, you can just omit it from theUPDATE
SQL, and it will get the current timestamp. Its a change in behaviour that was outside specification, is your bug for using it that way :-)explicit_defaults_for_timestamp
would get the NULL behavior back, but that option is also deprecated... (and since it's not part of my settings, 5.7 should also not have worked like that...)updated=null
on the UPDATE in the first place, when the column is defined withON UPDATE CURRENT_TIMESTAMP
?