I have a trigger that should convert empty strings to null
for a tinyint(1)
boolean column:
CREATE TRIGGER convertToNull
BEFORE INSERT ON MyTable
FOR EACH ROW
SET new.myBoolean = nullif(new.myBoolean, '');
The problem is, it also converts 0
to null
.
I checked with:
mysql> select nullif(0, '');
+---------------+
| nullif(0, '') |
+---------------+
| NULL |
+---------------+
1 row in set (0.00 sec)
How to make nullif
stricter, such that ONLY empty strings will be converted to null
?