pgsql: Sync behavior of var_samp and stddev_samp for single NaN inputs. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Sync behavior of var_samp and stddev_samp for single NaN inputs.
Date
Msg-id E1jkATZ-0002Y3-25@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Sync behavior of var_samp and stddev_samp for single NaN inputs.

var_samp(numeric) and stddev_samp(numeric) disagreed with their float
cousins about what to do for a single non-null input value that is NaN.
The float versions return NULL on the grounds that the calculation is
only defined for more than one non-null input, which seems like the
right answer.  But the numeric versions returned NaN, as a result of
dealing with edge cases in the wrong order.  Fix that.  The patch
also gets rid of an insignificant memory leak in such cases.

This inconsistency is of long standing, but on the whole it seems best
not to back-patch the change into stable branches; nobody's complained
and it's such an obscure point that nobody's likely to complain.
(Note that v13 and v12 now contain test cases that will notice if we
accidentally back-patch this behavior change in future.)

Report and patch by me; thanks to Dean Rasheed for review.

Discussion: https://postgr.es/m/353062.1591898766@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/23cbeda50b94c817bed4f7d2127ee09c4e8c8b86

Modified Files
--------------
src/backend/utils/adt/numeric.c          | 35 ++++++++++++++++----------------
src/test/regress/expected/aggregates.out |  4 ++--
2 files changed, 19 insertions(+), 20 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix behavior of float aggregates for single Inf or NaN inputs.
Next
From: Michael Paquier
Date:
Subject: pgsql: Replace superuser check by ACLs for replication origin functions