So I have table A which contains a column Z with default value set to string "diverse". The queries come in from a php script which takes the data from a jqueryAJAX post request.
I would like to have my DB set the respective field of column Z to default value if the query received an empty string for insertion into/update of this column.
I really would like to accomplish this using mysql functionality, without using any more custom coded php logic. I already read about using WHEN/THEN logic here: Set default value if empty string is passed MySQL and here MySQL update CASE WHEN/THEN/ELSE
but these don't explain how I permanently configure a table/column in a way that it exposes this "default" behavior not just on receiving a NULL value, but also on receiving an empty string.
Besides: If I set a column to NOT NULL and also add a default value for the column, would the query just fail if I tried to insert a/update to a NULL value, or would the DB instead flip to the default value?
MySQLcolumn is set to 'diverse' as default value and duringINSERT/UPDATEuser wants to use the blank/empty value then the engine has to work that way. There is no valid reason on why you do not want to remove or set default value 'diverse' atPHPside. That's the easiest way to solve your problem.