datetime default expression

hahaone's profile image hahaone posted 2 weeks ago in General Permalink

Modifying table-generating errors in sql .When saved, it becomes now()

ALTER TABLE ta CHANGE COLUMN updated updated DATETIME NOT NULL DEFAULT (CURRENT_TIMESTAMP) COMMENT '更新时间' FIRST;

It should be normal not to include parentheses ALTER TABLE ta CHANGE COLUMN updated updated DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间' FIRST;

hahaone's profile image hahaone posted 2 weeks ago Permalink

step1

1 attachment(s):
  • 1
hahaone's profile image hahaone posted 2 weeks ago Permalink

step2

1 attachment(s):
  • 2
hahaone's profile image hahaone posted 2 weeks ago Permalink

step3

1 attachment(s):
  • 3
ansgar's profile image ansgar posted 2 weeks ago Permalink

That is done by the server, silently converts CURRENT_TIMESTAMP to now(), an alias of CURRENT_TIMESTAMP, and should not cause any error.

Do you get any error? If you just like to keep that CURRENT_TIMESTAMP than please refer to the MySQL docs.

hahaone's profile image hahaone posted 2 weeks ago Permalink

That is done by the server, silently converts CURRENT_TIMESTAMP to now(), an alias of CURRENT_TIMESTAMP, and should not cause any error.

Do you get any error? If you just like to keep that CURRENT_TIMESTAMP than please refer to the MySQL docs.

It shouldn‘t be a problem with the mysql server. My colleague modified it to display CURRENT_TIMESTAMP by default, the same as the heidisql version. If now() exports the table-building sql to the mysql5.6 server, it will report an error.

ansgar's profile image ansgar posted 2 weeks ago Permalink

Yes the exports on a MySQL 8 server are not guaranteed to be compatible to older versions. But that's the same with mysqldump I suppose. You could try out if mysqldump makes the export more compatible to MySQL 5.x

MySQL 8.0 introduced support for expression-based default values for columns, where wrapping expressions (like functions) in parentheses is required to distinguish them from literal constants.

Only CURRENT_TIMESTAMP may omit parentheses, but HeidiSQL does not handle that single exception.

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