Bug #12 CASE ... ; and NULLs
Description:
When CASE ... WHEN ... END; is used and under some condition it evaluates as NULL all consequent values also become NULL if result is used in
GROUP BY
INSERT ... SELECT
CREATE ... SELECT
while result is Ok otherwise
How to repeat:
create table a (b int);
insert into a values (1), (2), (3);
select b, case b when 2 then NULL else b end as c from a;
+------+------+
| b | c |
+------+------+
| 1 | 1 |
| 2 | NULL |
| 3 | 3 |
+------+------+
Now the BUG:
mysql> select b, case b when 2 then NULL else b end as c from a group by b;
+------+------+
| b | c |
+------+------+
| 1 | 1 |
| 2 | NULL |
| 3 | NULL |
+------+------+
create table d select b, case b when 2 then NULL else b end as c from a;
select * from d;
+------+------+
| b | c |
+------+------+
| 1 | 1 |
| 2 | NULL |
| 3 | NULL |
+------+------+
insert into d select b, case b when 2 then NULL else b end as c from a;
select * from d;
+------+------+
| b | c |
+------+------+
| 1 | 1 |
| 2 | NULL |
| 3 | NULL |
| 1 | 1 |
| 2 | NULL |
| 3 | NULL |
+------+------+
I simplified original report which contained:
SELECT ... MAX(CASE ...) ... GROUP BY ...;
result was wrong because as above shows that after frst NULL CASE evaluates as NULL so
MAX(List_of_NULLs) -> NULL
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.049 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.