Bug #12765 CURRENT_DATE function can not be used as a DEFAULT value for a column
Submitted: 23 Aug 2005 22:54 Modified: 24 Aug 2005 11:05
Reporter: Andrija Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S4 (Feature request)
Version:last OS:Any (any)
Assigned to: CPU Architecture:Any

[23 Aug 2005 22:54] Andrija
Description:
I am porting my applications from mssql to mysql (actually enabling them to work on both databases) as I try to move at least some of my customers to mysql.
but I have a huge problem: rewrite all of sql queries which insert data into tables with date columns to enable mysql or ignore mysql.
Why: because you will not allow current_date to be set for datetime as default value (what is the big difference if timestamp can have current date as default value). And no, I don't want to update timestamp every time row is updated.
Damn, how do you intend to get new paying customers if you will not allow such important functionality? Do not bother replying. Just fix this unbelieveable lack of functionality.

How to repeat:
CREATE TABLE doesnotwork (dt datetime DEFAULT CURRENT_DATE)

Suggested fix:
Just fix this unbelieveable lack of functionality.
[24 Aug 2005 11:05] Valeriy Kravchuk
This limitation is described in the manual (http://dev.mysql.com/doc/mysql/en/create-table.html):

"The DEFAULT clause specifies 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 a TIMESTAMP column as of MySQL 4.1.2."

So, you can either use TIMESTAMP datatype, or if you really use "last" (5.0.x) version, you can try to add trigger on INSERT (see http://dev.mysql.com/doc/mysql/en/using-triggers.html for details).