Home > database >  make default value for a field to be current_timestamp some interval
make default value for a field to be current_timestamp some interval

Time:06-03

i wanna make the default value of a field to be 30 days more than whatever the current timestamp is i tried a lot of stuff with dateadd() and addtime() but it always gave me an syntax error

create table test (Id serial,name varchar(10),Date timestamp default dateadd(day,30,cuurent_timestamp));

this might give a rough idea of what i'm trying to achieve.

CodePudding user response:

dateadd is an SQL server function; mysql has date_add with different syntax.

To use a complex expression for a default value requires mysql 8 or mariadb 10.2 . And in mysql, the entire expression must be parenthesized.

You want:

default (date_add(current_timestamp, interval 30 day))
  • Related