Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in mysql8 why does DATE DEFAULT CURRENT_DATE need parentheses around CURRENT_DATE?

as of mysql8, this is legal:

CREATE TABLE t (d DATETIME DEFAULT CURRENT_TIMESTAMP);

and this is legal:

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

so why is this illegal?

CREATE TABLE t (d DATE DEFAULT CURRENT_DATE);

resulting in a

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

like image 462
hanshenrik Avatar asked Nov 18 '25 04:11

hanshenrik


1 Answers

Refer to this for more information.

This is most likely, what you were referring to in your question:

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

[...]

The exception is that, for TIMESTAMP and DATETIME columns, you can specify the CURRENT_TIMESTAMP function as the default, without enclosing parentheses.

like image 144
Tilen Avatar answered Nov 20 '25 17:11

Tilen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!