Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite17e40f

Browse files
committed
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 willoverflow, instead of grinding through a lot of calculation first.Per gripe from Jim Nasby.
1 parenta4d5872 commite17e40f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

‎src/backend/utils/adt/numeric.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 1998-2007, PostgreSQL Global Development Group
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.103 2007/06/05 21:31:06 tgl Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.104 2007/06/09 15:52:30 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -29,6 +29,7 @@
2929
#include"access/hash.h"
3030
#include"catalog/pg_type.h"
3131
#include"libpq/pqformat.h"
32+
#include"miscadmin.h"
3233
#include"utils/array.h"
3334
#include"utils/builtins.h"
3435
#include"utils/int8.h"
@@ -1560,6 +1561,11 @@ numeric_fac(PG_FUNCTION_ARGS)
15601561
res=make_result(&const_one);
15611562
PG_RETURN_NUMERIC(res);
15621563
}
1564+
/* Fail immediately if the result would overflow */
1565+
if (num>32177)
1566+
ereport(ERROR,
1567+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1568+
errmsg("value overflows numeric format")));
15631569

15641570
init_var(&fact);
15651571
init_var(&result);
@@ -1568,6 +1574,9 @@ numeric_fac(PG_FUNCTION_ARGS)
15681574

15691575
for (num=num-1;num>1;num--)
15701576
{
1577+
/* this loop can take awhile, so allow it to be interrupted */
1578+
CHECK_FOR_INTERRUPTS();
1579+
15711580
int8_to_numericvar(num,&fact);
15721581

15731582
mul_var(&result,&fact,&result,0);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp