1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

stddev() and variance() should return NULL when there is just one input

value, per recent discussion on pgsql-general.
This commit is contained in:
Tom Lane
2003-04-21 00:22:24 +00:00
parent f9ba0a7fe5
commit 1dc3a62ec7
2 changed files with 18 additions and 34 deletions
src/backend/utils/adt

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.84 2003/03/11 21:01:33 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.85 2003/04/21 00:22:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1649,12 +1649,9 @@ float8_variance(PG_FUNCTION_ARGS)
sumX = transvalues[1];
sumX2 = transvalues[2];
/* We define VARIANCE of no values to be NULL, of 1 value to be 0 */
if (N == 0.0)
PG_RETURN_NULL();
/* Sample variance is undefined when N is 0 or 1, so return NULL */
if (N <= 1.0)
PG_RETURN_FLOAT8(0.0);
PG_RETURN_NULL();
numerator = N * sumX2 - sumX * sumX;
@ -1680,12 +1677,9 @@ float8_stddev(PG_FUNCTION_ARGS)
sumX = transvalues[1];
sumX2 = transvalues[2];
/* We define STDDEV of no values to be NULL, of 1 value to be 0 */
if (N == 0.0)
PG_RETURN_NULL();
/* Sample stddev is undefined when N is 0 or 1, so return NULL */
if (N <= 1.0)
PG_RETURN_FLOAT8(0.0);
PG_RETURN_NULL();
numerator = N * sumX2 - sumX * sumX;