I have a table I’m trying to add a unique index to. Problem is, the way the script is set up that inserts data, there will be on occasion, some empty strings instead of NULL.
So, aside from changing the script (which I foresee being necessary unless someone saves me!)…. is there any setting in mysql that can automatically use NULL value if an empty string is passed through to the unique key?
If you can’t fix the import script then you should be able to use a trigger to patch things up before INSERTs or UPDATEs get to the table. Something like this should do the trick:
newhere refers to what the row will look like after the INSERT or UPDATE completes so you can look for the garbage values and fix them. Then, since these are BEFORE triggers, your patched rows will go into the database. You would, of course, have to change the table (your_table) and column (string) names to suit your situation.