A function to check if a column allows NULL Is there a way to write an insert/update query that checks if a column allows NULLs: If it does set the column to NULL, and '' (empty string) otherwise?

I would be something like:

UPDATE mytable 
SET field = IF(A_FUNCTION_TO_CHECK_IF_ALLOWS_NULL(), NULL, '');
You can query the INFORMATION_SCHEMA:

http://dev.mysql.com/doc/refman/5.0/en/columns-table.html

In the INFORMATION_SCHEMA.COLUMNS table there is a IS_NULLABLE column.

You could turn it into a function, I imagine, but I would probably put this logic in an outer part.