diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-06-09 15:52:47 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-06-09 15:52:47 +0000 |
commit | 09bb3620872389ee1e759296d160f123726910ec (patch) | |
tree | 3d198abbeacfe1b72ed735a3c06dab3202a51b73 | |
parent | bac7d7b53b6e0a82c61421550cb1960358862850 (diff) | |
download | postgresql-09bb3620872389ee1e759296d160f123726910ec.tar.gz postgresql-09bb3620872389ee1e759296d160f123726910ec.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.
-rw-r--r-- | src/backend/utils/adt/numeric.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index 1a4dc1bf802..edeb26d4b51 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -14,7 +14,7 @@ * Copyright (c) 1998-2005, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.86.2.1 2005/11/22 18:23:21 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.86.2.2 2007/06/09 15:52:47 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,6 +29,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" @@ -1414,6 +1415,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); @@ -1422,6 +1428,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); |