Fix stddev_pop(numeric) and var_pop(numeric), which were incorrectly producing

the same outputs as stddev_samp() and var_samp() respectively.
This commit is contained in:
Tom Lane 2007-07-09 16:13:57 +00:00
parent 9e09e3b15e
commit 6244c2dfff
2 changed files with 7 additions and 4 deletions

View File

@ -14,7 +14,7 @@
* Copyright (c) 1998-2007, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.105 2007/06/15 20:56:50 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.106 2007/07/09 16:13:57 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -2435,7 +2435,10 @@ numeric_stddev_internal(ArrayType *transarray,
}
else
{
mul_var(&vN, &vNminus1, &vNminus1, 0); /* N * (N - 1) */
if (sample)
mul_var(&vN, &vNminus1, &vNminus1, 0); /* N * (N - 1) */
else
mul_var(&vN, &vN, &vNminus1, 0); /* N * N */
rscale = select_div_scale(&vsumX2, &vNminus1);
div_var(&vsumX2, &vNminus1, &vsumX, rscale, true); /* variance */
if (!variance)

View File

@ -102,7 +102,7 @@ SELECT var_samp(b) FROM aggtest;
SELECT stddev_pop(b::numeric) FROM aggtest;
stddev_pop
------------------
151.389361431288
131.107032862199
(1 row)
SELECT stddev_samp(b::numeric) FROM aggtest;
@ -114,7 +114,7 @@ SELECT stddev_samp(b::numeric) FROM aggtest;
SELECT var_pop(b::numeric) FROM aggtest;
var_pop
--------------------
22918.738754573025
17189.054065929769
(1 row)
SELECT var_samp(b::numeric) FROM aggtest;