Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: 5.1.67, 5.2.14, 5.3.12, 5.5.36, 10.0.8
-
Fix Version/s: None
-
Component/s: None
-
Labels:
Description
I spoke about this in the list moths ago, but I forgot to file a bug.
Try the following code:
DROP TABLE IF EXISTS t; CREATE TABLE t (a INT DEFAULT 999) ENGINE = InnoDB; DELIMITER || CREATE TRIGGER t_bi BEFORE INSERT ON t FOR EACH ROW BEGIN SET NEW.a = DEFAULT; END; || DELIMITER ; INSERT INTO t VALUES (0); SELECT * FROM t;
I get no errors, but t.a is NULL (which would be ok if a.t had no default value).
Since I'm not sure about the syntax, I tried DEFAULT(a) and DEFAULT(t.a), but in both cases I got an error. I have no idea if the errors are expected or not, but as far as I understand the syntax in the example should work.
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Hi Federico,
I think it is more about BEFORE than about TRIGGER:
So, it might have something to do with not having the information in a before trigger, although I haven't found anything about it in the documentation.
Since it's an upstream issue, as you know, normally we would refile it for MySQL and see what they say. However, this syntax has been removed in MySQL 5.6 and further, you cannot use there DEFAULT anymore.
It was apparently done by this change:
The worklog itself is not public, so it's hard to understand why it was done, maybe the problem you described was one of the reasons.
So, undoubtedly, MySQL won't do anything about it in 5.5.
I suppose eventually this change will make it to 10.x as well, so I'm not sure fixing it there, even if it's possible, is worth the trouble.
Do you agree, or do you want a further analysis?