Reputation: 1777
I make a simple table with id and date with default value CURRENT_TIMESTAMP and i am curious how to set date CURRENT_TIMESTAMP + 1 year. For example if NOW() is 2018-01-23 13:57:22 i want as default value to be 2019-01-23 13:57:22. I can made this with trigger or with code before insert new line but is there other shortcut?
For example: How can i set as default value DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 1 YEAR)
Same problem with this: https://bugs.mysql.com/bug.php?id=56835
Upvotes: 0
Views: 2815
Reputation: 1777
It cant be manual.
The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for TIMESTAMP and DATETIME columns.
So the only way right now is with trigger or manually before insert new line in table.
Upvotes: 2