pgsql: Sync behavior of var_samp and stddev_samp for single NaN inputs.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Sync behavior of var_samp and stddev_samp for single NaN inputs.
Date: 2020-06-13 18:01:53
Message-ID: E1jkATZ-0002Y3-25@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2020-06-14 03:43:38 pgsql: Replace superuser check by ACLs for replication origin functions
Previous Message Tom Lane 2020-06-13 17:43:58 pgsql: Fix behavior of float aggregates for single Inf or NaN inputs.