Bug #3435 STDDEV|VARIANCE(constant) returns constant if no rows
Submitted: 10 Apr 2004 11:26 Modified: 5 May 2004 13:11
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.2-alpha-debug OS:Linux (SuSE 8.2/Win XP)
Assigned to: Ramil Kalimullin CPU Architecture:Any

[10 Apr 2004 11:26] Peter Gulutzan
Description:
Description: STDDEV() and VARIANCE() should return NULL if there are no rows. For 
example, with an empty set t, "SELECT STDDEV(column1) FROM t" returns NULL. But 
"SELECT STDDEV(constant) FROM t" doesn't return NULL.  
 
STDDEV and VARIANCE should be treated like standard functions. 
 

How to repeat:
mysql> create table t (s1 int); 
Query OK, 0 rows affected (0.31 sec) 
 
mysql> select stddev(s1),variance(s1) from t; 
+------------+--------------+ 
| stddev(s1) | variance(s1) | 
+------------+--------------+ 
|       NULL |         NULL | 
+------------+--------------+ 
1 row in set (0.00 sec) 
 
mysql> select stddev(5),variance(5) from t; 
+-----------+-------------+ 
| stddev(5) | variance(5) | 
+-----------+-------------+ 
|    0.0000 |      0.0000 | 
+-----------+-------------+ 
1 row in set (0.00 sec)
[5 May 2004 13:11] Ramil Kalimullin
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html