MySQL default value Gotcha!! No functions allowed!!

MySQL default value Gotcha!! No functions allowed!!

Posted by Luis Majano
Mar 20, 2007 00:00:00 UTC
I just came upon this issue today and it was bothering the creepers out of me. I could not put a function as a default value on a column on a MySQL table, a function call like : NOW() or UUID()

Noooo!!! MySQL Do not like it one bit. So I had to revert to the docs and there it was:

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.


So please take note on this issue if you just spend 20 minutes like me, trying to figure it out.

Hope this helps.


Josh Highland

I came across the problem a while back. Its one of the only things I don't really like about MySQL.

Luis Majano

I agree,

Having default fields pointing to internal function is in my mind, something necessary. I hope MySQL future versions change this behavior.

Site Updates

Entry Comments


Entries Search