Hi Jerry,
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.
from http://dev.mysql.com/doc/refman/5.1/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. See Section 10.3.1.1, “TIMESTAMP
Properties”.
###
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.
http://dev.mysql.com/doc/refman/5.1/en/create-trigger.html
I know it's a workaround but it will keep the default value management
out of your application and inside the database.
--
Shawn Green
MySQL Principal Technical Support Engineer
Oracle USA, Inc.
Office: Blountville, TN