aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-06-09 15:52:38 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-06-09 15:52:38 +0000
commitab4f1947f3a2a135e7bb01bf06010c54ab5118f8 (patch)
tree1811e6788049485c401cff39e32a6d357ebc30cd /src
parent02c31e885d76b422ebf76ec06a5e9c5fff0975d8 (diff)
downloadpostgresql-ab4f1947f3a2a135e7bb01bf06010c54ab5118f8.tar.gz
postgresql-ab4f1947f3a2a135e7bb01bf06010c54ab5118f8.zip
Allow numeric_fac() to be interrupted, since it can take quite a while for
large inputs. Also cause it to error out immediately if the result will overflow, instead of grinding through a lot of calculation first. Per gripe from Jim Nasby.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/numeric.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 35b0221b85d..71a2e491868 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -14,7 +14,7 @@
* Copyright (c) 1998-2006, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.96 2006/10/04 00:29:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.96.2.1 2007/06/09 15:52:38 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -28,6 +28,7 @@
#include "catalog/pg_type.h"
#include "libpq/pqformat.h"
+#include "miscadmin.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/int8.h"
@@ -1416,6 +1417,11 @@ numeric_fac(PG_FUNCTION_ARGS)
res = make_result(&const_one);
PG_RETURN_NUMERIC(res);
}
+ /* Fail immediately if the result would overflow */
+ if (num > 32177)
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("value overflows numeric format")));
init_var(&fact);
init_var(&result);
@@ -1424,6 +1430,9 @@ numeric_fac(PG_FUNCTION_ARGS)
for (num = num - 1; num > 1; num--)
{
+ /* this loop can take awhile, so allow it to be interrupted */
+ CHECK_FOR_INTERRUPTS();
+
int8_to_numericvar(num, &fact);
mul_var(&result, &fact, &result, 0);