Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e3a5ac2

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
Little fix for round() function
Jan
1 parent 9f65dfe commit e3a5ac2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/backend/utils/adt/numeric.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* 1998 Jan Wieck
77
*
8-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.5 1999/01/03 05:30:47 momjian Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.6 1999/01/04 11:20:33 wieck Exp $
99
*
1010
* ----------
1111
*/
@@ -523,6 +523,7 @@ Numeric
523523
numeric_round(Numeric num, int32 scale)
524524
{
525525
int32 typmod;
526+
int precision;
526527

527528
/* ----------
528529
* Handle NULL
@@ -553,7 +554,9 @@ numeric_round(Numeric num, int32 scale)
553554
* Let numeric() and in turn apply_typmod() do the job
554555
* ----------
555556
*/
556-
typmod = (((num->n_weight + scale + 1) << 16) | scale) + VARHDRSZ;
557+
precision = MAX(0, num->n_weight) + scale;
558+
precision = MIN(precision, NUMERIC_MAX_PRECISION);
559+
typmod = (((precision + 2) << 16) | scale) + VARHDRSZ;
557560
return numeric(num, typmod);
558561
}
559562

0 commit comments

Comments
 (0)