aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/numeric.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2020-06-18 08:41:31 +0200
committerPeter Eisentraut <peter@eisentraut.org>2020-06-18 08:41:31 +0200
commit0a40563eadc67472d6fd50dabf7002afa25c3330 (patch)
treeebc2b5a11f9a49201f8a11230b96e986d6d46b15 /src/backend/utils/adt/numeric.c
parent9d402c73ade412bdeb9064c81fc4ed071c4e93f8 (diff)
downloadpostgresql-0a40563eadc67472d6fd50dabf7002afa25c3330.tar.gz
postgresql-0a40563eadc67472d6fd50dabf7002afa25c3330.zip
Disallow factorial of negative numbers
The previous implementation returned 1 for all negative numbers, which is not sensible under any definition. Discussion: https://www.postgresql.org/message-id/flat/6ce1df0e-86a3-e544-743a-f357ff663f68%402ndquadrant.com
Diffstat (limited to 'src/backend/utils/adt/numeric.c')
-rw-r--r--src/backend/utils/adt/numeric.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index eea42398541..5f23f2afac8 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -2946,6 +2946,10 @@ numeric_fac(PG_FUNCTION_ARGS)
NumericVar fact;
NumericVar result;
+ if (num < 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("factorial of a negative number is undefined")));
if (num <= 1)
{
res = make_result(&const_one);