Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 建表 Date 类型的列,默认当前日期怎样实现
Datetime columns can be set to the current time, how can the Date column have its default value set to the current date?
create table TimeTest (
InsertDateTime Datetime default current_timestamp,
InsertDate Date default current_date
);
It can’t be implemented. MySQL only implemented it in version 8.0.13 and later. TiDB 6.5 is still compatible with MySQL 5.7. Try implementing it in the application or upgrade TiDB to 8.1 to see if it works.
MySQL 8.0.25-230102 is not supported.
Starting from version 8.0.13, it is supported. You need to enclose CURRENT_DATE in parentheses:
CREATE TABLE t1 (d DATE DEFAULT (CURRENT_DATE));
Learned something new again.
Based on the SQL you provided, the table was created successfully, and the default values are correct.
So, you’re saying that the DateTime type works, but the Date type doesn’t, right?
Compatibility issues, it is recommended to upgrade the TiDB version.
It seems that it requires a new version to support it.
Support for the new version
Senior, what did you use for deployment? Was it deployed with Ti-Operator? With this version, after my deployment, PD often fails to establish the cluster and then exits. Therefore, it can’t start.
I used tiup for deployment.