On 12/17/2010 09:34, Jerry Schwartz wrote:
>> -----Original Message-----
>> From: Jo�o C�ndido de Souza Neto [mailto:joao@stripped]
>> Sent: Friday, December 17, 2010 6:11 AM
>> To: mysql@stripped
>> Subject: Re: Access to MySQL
>> What about this?
>> date_format(now(), "%Y/%m/%d")
> [JS] I don't think you can use anything but a constant as a default value.
You are correct with one exception that was already mentioned earlier:
the TIMESTAMP storage type.
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. See Section 10.3.1.1, “TIMESTAMP
However, nothing says you can't use a function or other computation in a
TRIGGER to set the default value to an empty column of a new row to
whatever you wanted it to be.
I know it's a workaround but it will keep the default value management
out of your application and inside the database.
MySQL Principal Technical Support Engineer
Oracle USA, Inc.
Office: Blountville, TN