Bug: ON UPDATE CURRENT_TIMESTAMP is missing after table creation

[expired user #8605]'s profile image [expired user #8605] posted 9 years ago in Feature discussion Permalink
Reproduction on build 9.1.0.4888:
CREATE TABLE `test` (
`field` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

Now open the table and view the "CREATE code" tab. The ON UPDATE CURRENT_TIMESTAMP part is missing. However, a DEFAULT of CURRENT_TIMESTAMP is shown correctly.

The ON UPDATE clause is not implicitly set by MySQL, so the CREATE code is invalid.
ansgar's profile image ansgar posted 9 years ago Permalink
Problem is HeidiSQL expecting some "DEFAULT CURRENT_TIMESTAMP ...", where MySQL silently modified your original code to this one:

CREATE TABLE `test` (
`field` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=latin1


The right way would be HeidiSQL displays it this way:
1 attachment(s):
  • update-current-timestamp
[expired user #8605]'s profile image [expired user #8605] posted 9 years ago Permalink
If I use your example CREATE SQL, I still get the wrong default value (CURRENT_TIMESTAMP instead of '0000-00-00 00:00:00'):



So we agree this is a bug, right? :)
[expired user #8605]'s profile image [expired user #8605] posted 9 years ago Permalink
To explain a bit more:

* MySQL interprets the first DEFAULT CURRENT_TIMESTAMP column implicitly as a ON UPDATE CURRENT_TIMESTAMP column.
* The default value for a column is separate from the ON UPDATE clause.

So when interpreting the SHOW CREATE TABLE output, you can actually trust the DEFAULT and ON UPDATE values as separate, valid values. The ON UPDATE value in HeidiSQL should never be dependent on the DEFAULT value!
ansgar's profile image ansgar posted 9 years ago Permalink
Yes, of course, we agree about a bug heresmileI was explaining the bug cause more to myself, so I can reproduce and fix it.
Code modification/commit from ansgar.becker, 9 years ago, revision 9.1.0.4893
Support columns with a string literal as default value plus an ON UPDATE CURRENT_TIMESTAMP clause. See http://www.heidisql.com/forum.php?t=17323
ansgar's profile image ansgar posted 9 years ago Permalink
Should be fixed in r4893

Please login to leave a reply, or register at first.