everyone
I wanna add a column start_date whose default value is current date(), so I use following commands:
alter table validation add column start_date date default CURDATE()
but it didn’t work and told me it has syntax error.
While using such following command works well:
alter table validation add column start_date date default 0
Any suggestion is appreciated.
From the online documentation (my bold):
That’s why
default 0works (a constant) butdefault curdate()doesn’t (a function).You have (at least) a couple of possibilities to work around this.
The first is to use a timestamp column instead of a date column, and set its default to
CURRENT_TIMESTAMP. Unfortunately, that means you’ll have to turn that back into a date when extracting it.The second is to use triggers to set the column value, rather than from a default value. For example, use an insert trigger to set the relevant column to the current date.