Bug #8093 GROUP BY can alter some values of a grouped by column
Submitted: 22 Jan 2005 20:08 Modified: 24 Jan 2005 17:19
Reporter: paul van den berg Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S3 (Non-critical)
Version:4.1.8 OS:Any (*)
Assigned to: Sergey Petrunya CPU Architecture:Any

[22 Jan 2005 20:08] paul van den berg
Description:
create table t (c char(1) not null);

insert into t values (''),('0'),('1');

select if(c regexp '[0-9]{1}',c,-1) as i from t;
+----+
| i  |
+----+
| -1 |
| 0  |
| 1  |
+----+

select if(c regexp '[0-9]{1}',c,-1) as i from t group by c;
+---+
| i |
+---+
| - |
| 0 |
| 1 |
+---+

select if(c regexp '[0-9]{1}',c,-1) as i from t group by i;
+---+
| i |
+---+
| - |
| 0 |
| 1 |
+---+

How to repeat:
See description

Suggested fix:
not a fix, but a workaround:

select if(c regexp '[0-9]{1}',c,'-1') as i from t group by i;
[23 Jan 2005 12:53] Aleksey Kishkin
tested on windows and linux 4.1 and 5.0
[24 Jan 2005 13:35] paul van den berg
Section 12.2 of the manual states:

IF(expr1,expr2,expr3)
Expression 	                   Return Value
expr2 or expr3 returns a string 	string
expr2 or expr3 returns an integer 	integer

What happens if expr2 returns a string  and expr3 returns an integer?
Mysqlserver gets confused, and the documentation is self-contradicting..
[24 Jan 2005 14:12] Aleksey Kishkin
Thank you for your bug report. This issue has already been fixed
in the latest released version of that product, which you can download at 
http://www.mysql.com/downloads/

Additional info:

tested on 4.1.9-ga - works properly, shows '-1', so, this bug doesn't exist in latest release.