From bb885dd1a1bc4fc40d724461a838b6724226bc15 Mon Sep 17 00:00:00 2001
From: Jan Wieck <JanWieck@Yahoo.com>
Date: Mon, 10 May 1999 18:17:44 +0000
Subject: [PATCH] Check for NUMERIC overflow a second time after rounding

Jan
---
 src/backend/utils/adt/numeric.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index e00e2186847..b1a86986ac0 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -5,7 +5,7 @@
  *
  *	1998 Jan Wieck
  *
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.12 1999/05/04 15:50:24 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.13 1999/05/10 18:17:44 wieck Exp $
  *
  * ----------
  */
@@ -2399,6 +2399,19 @@ apply_typmod(NumericVar *var, int32 typmod)
 		var->ndigits = MAX(0, MIN(i, var->ndigits));
 	}
 
+	/* ----------
+	 * Check for overflow again - rounding could have raised the
+	 * weight.
+	 * ----------
+	 */
+	if (var->weight >= maxweight)
+	{
+		free_allvars();
+		elog(ERROR, "overflow on numeric "
+        "ABS(value) >= 10^%d for field with precision %d scale %d",
+							var->weight, precision, scale);
+	}
+
 	var->rscale = scale;
 	var->dscale = scale;
 }
-- 
GitLab