Bug #12 CASE ... ; and NULLs

Submitted: 11 Dec 2002 17:42 Modified: 26 Nov 2003 12:14
Reporter: Alexander Keremidarski Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:3.23.53 OS:Any (any)
Assigned to: CPU Architecture:Any

[11 Dec 2002 17:42] Alexander Keremidarski
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
[27 Dec 2002 20:45] MySQL Developer
Fixed in 3.23.55

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.