Bug #908 Timestamp set to current time despite explicit set in update

Submitted: 24 Jul 2003 7:24 Modified: 24 Jul 2003 10:53
Reporter: Jacco van Schaik Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.0.3-beta OS:Linux (Red Hat Linux release 7.3)
Assigned to: CPU Architecture:Any

[24 Jul 2003 7:24] Jacco van Schaik
Description:
I'm using an update with a join to change some fields in a table. This table has two timestamp fields but I don't want those to change, so I'm using the
"foo.time = foo.time" trick in the update query. However, MySQL still changes the first timestamp of every changed row to the current time.

How to repeat:
DROP TABLE IF EXISTS Widgets;
CREATE TABLE Widgets (
  widget_id INT NOT NULL,
  t_begin TIMESTAMP NOT NULL,
  t_end   TIMESTAMP NOT NULL,
  some_data VARCHAR(10),
  UNIQUE INDEX (widget_id),
  INDEX (t_begin),
  INDEX (t_end)
);

DROP TABLE IF EXISTS Gadgets;
CREATE TABLE Gadgets (
  time TIMESTAMP NOT NULL,
  widget_id INT NOT NULL,
  INDEX (time)
);

INSERT INTO Widgets VALUES
    ( 1, '20030724000000', '20030724235959', "" ),
    ( 2, '20030724000000', '20030724235959', "" ),
    ( 3, '20030724000000', '20030724235959', "" ),
    ( 4, '20030724000000', '20030724235959', "" );

INSERT INTO Gadgets VALUES
    ( '20030724110000', 1 ),
    ( '20030724120000', 2 ),
    ( '20030724130000', 3 ),
    ( '20030724140000', 4 );

UPDATE Widgets, Gadgets
SET Widgets.t_begin = Widgets.t_begin,
    Widgets.some_data = 'YES!'
WHERE Widgets.widget_id = Gadgets.widget_id
AND   Gadgets.time between '20030724120000' and '20030724130000';

Now

SELECT * FROM Widgets;

... produces:

+-----------+----------------+----------------+-----------+
| widget_id | t_begin        | t_end          | some_data |
+-----------+----------------+----------------+-----------+
|         1 | 20030724000000 | 20030724235959 |           |
|         2 | 20030724142059 | 20030724235959 | YES!      |
|         3 | 20030724142059 | 20030724235959 | YES!      |
|         4 | 20030724000000 | 20030724235959 |           |
+-----------+----------------+----------------+-----------+
4 rows in set (0.00 sec)

... where I would have expected:

+-----------+----------------+----------------+-----------+
| widget_id | t_begin        | t_end          | some_data |
+-----------+----------------+----------------+-----------+
|         1 | 20030724000000 | 20030724235959 |           |
|         2 | 20030724000000 | 20030724235959 | YES!      |
|         3 | 20030724000000 | 20030724235959 | YES!      |
|         4 | 20030724000000 | 20030724235959 |           |
+-----------+----------------+----------------+-----------+
4 rows in set (0.00 sec)
[24 Jul 2003 10:53] Indrek Siitan
4.0.3 is a beta version and many bugs have been fixed since -
the current version in the 4.0 tree is 4.0.14.

I have tested this with both 4.0.14 and 4.1.0 and neither of them
exposed this behaviour, so this must have been fixed meanwhile.

Please upgrade.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.