gpt4 book ai didi

mysql - 在 mysql8 中,为什么 DATE DEFAULT CURRENT_DATE 需要在 CURRENT_DATE 周围加括号?

转载 作者:行者123 更新时间:2023-12-01 23:11:24 24 4
gpt4 key购买 nike

从 mysql8 开始,这是合法的:

CREATE TABLE t (d DATETIME DEFAULT CURRENT_TIMESTAMP);

这是合法的:

CREATE TABLE t (d DATE DEFAULT (CURRENT_DATE));

那么为什么这是非法的?

CREATE TABLE t (d DATE DEFAULT CURRENT_DATE);

导致

Error in query (1064): Syntax error near 'CURRENT_DATE)' at line 1

最佳答案

引用this for more information .

这很可能是您在问题中所指的内容:

The default value specified in a DEFAULT clause can be a literalconstant or an expression. With one exception, enclose expressiondefault values within parentheses to distinguish them from literalconstant default values.

[...]

The exception is that, for TIMESTAMP and DATETIME columns, you canspecify the CURRENT_TIMESTAMP function as the default, withoutenclosing parentheses.

关于mysql - 在 mysql8 中,为什么 DATE DEFAULT CURRENT_DATE 需要在 CURRENT_DATE 周围加括号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69880064/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com