Bug #62225 | Update with unique column of type TIMESTAMP | ||
---|---|---|---|
Submitted: | 22 Aug 2011 9:28 | Modified: | 22 Aug 2011 10:36 |
Reporter: | Dirk Schäfer | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Errors | Severity: | S2 (Serious) |
Version: | 5.1.53 | OS: | Windows (7) |
Assigned to: | CPU Architecture: | Any |
[22 Aug 2011 9:28]
Dirk Schäfer
[22 Aug 2011 9:31]
Dirk Schäfer
Forget the ' in set Status='0'. It was just a try.
[22 Aug 2011 9:36]
Dirk Schäfer
I tried: update `test`.`values` set Status=0 where Date = '1999-07-01 00:00:00' This deletes the line with date 1999-07-01 and adds the line 2011-08-22 11:26:00, 100, 0 So update deletes the line and inserts a new one with the actual local time.
[22 Aug 2011 10:36]
Valeriy Kravchuk
This is how your table is created: mysql> show create table `values`\G *************************** 1. row *************************** Table: values Create Table: CREATE TABLE `values` ( `Date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAM P, `Value` float DEFAULT NULL, `Status` int(11) DEFAULT NULL, UNIQUE KEY `Date` (`Date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 1 row in set (0.03 sec) Note ON UPDATE CURRENT_TIMESTAMP clause, that is the reason for the attempt to set same current timestamp value for the (UNIQUE) column in several rows for your first case. Why this clause is added? Because it is a documented feature of TIMESTAMP daa type. Read http://dev.mysql.com/doc/refman/5.1/en/timestamp.html: "In a CREATE TABLE statement, the first TIMESTAMP column can be declared in any of the following ways: With both DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses, the column has the current timestamp for its default value, and is automatically updated. With neither DEFAULT nor ON UPDATE clauses, it is the same as DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP. ..."