Bug #115269 | "INSERT SET column=column" inserts zero date | ||
---|---|---|---|
Submitted: | 10 Jun 12:53 | Modified: | 10 Jun 13:33 |
Reporter: | Guilhem Bichot | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[10 Jun 12:53]
Guilhem Bichot
[10 Jun 13:33]
MySQL Verification Team
Bonjour mom cher ami, Guilhem, We have repeated the behaviour with both 8.0 and 8.4. They are the same and your report is correct. This is a bug in DML, indeed. Thank you for your contribution.
[11 Jun 7:02]
Roy Lyseng
Hi Guilhem, I think I will consider this not a bug, although it is indeed weird behavior. Consider this: CREATE TABLE t0(a INTEGER NOT NULL, b INTEGER NOT NULL); INSERT INTO t0 SET a=555, b=a; SELECT * FROM t0; DROP TABLE t0; We first insert a value in t0.a, then use the same value as a default value for t0.b. But if t0.a had not been assigned a value yet, we resort to the implicit default value for the column which is zero. This is kind of in compliance with the documentation chapter "Data Type Default Values", by using implicit default values, although one could consider to disallow this practice when strict mode is enabled. Unfortunately, the implicit default value for a DATE column is the generally invalid value "0000-00-00". Inserting this value is indeed an error. It would thus be a change in behavior to analyze for as yet not assigned column default values and reject them.
[11 Jun 10:14]
Roy Lyseng
As for many other things in MySQL, this is beyond the SQL standard. This is how the feature is documented: An expression expr can refer to any column that was set earlier in a value list. For example, you can do this because the value for col2 refers to col1, which has previously been assigned: INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2); But notice that this rule is actually violated here, as the column to be assigned references itself, and thus has not been given a value. So, yes, I do agree this is a bug.