@@ -1199,9 +1199,22 @@ dtof(PG_FUNCTION_ARGS)
11991199
12001200 result = (float4 ) num ;
12011201 if (unlikely (isinf (result )) && !isinf (num ))
1202- float_overflow_error ();
1202+ {
1203+ errsave (fcinfo -> context ,
1204+ errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
1205+ errmsg ("value out of range: overflow" ));
1206+
1207+ PG_RETURN_NULL ();
1208+ }
1209+
12031210 if (unlikely (result == 0.0f ) && num != 0.0 )
1204- float_underflow_error ();
1211+ {
1212+ errsave (fcinfo -> context ,
1213+ errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
1214+ errmsg ("value out of range: underflow" ));
1215+
1216+ PG_RETURN_NULL ();
1217+ }
12051218
12061219 PG_RETURN_FLOAT4 (result );
12071220}
@@ -1224,10 +1237,14 @@ dtoi4(PG_FUNCTION_ARGS)
12241237
12251238 /* Range check */
12261239 if (unlikely (isnan (num ) || !FLOAT8_FITS_IN_INT32 (num )))
1227- ereport (ERROR ,
1240+ {
1241+ errsave (fcinfo -> context ,
12281242 (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
12291243 errmsg ("integer out of range" )));
12301244
1245+ PG_RETURN_NULL ();
1246+ }
1247+
12311248 PG_RETURN_INT32 ((int32 ) num );
12321249}
12331250
@@ -1249,10 +1266,14 @@ dtoi2(PG_FUNCTION_ARGS)
12491266
12501267 /* Range check */
12511268 if (unlikely (isnan (num ) || !FLOAT8_FITS_IN_INT16 (num )))
1252- ereport (ERROR ,
1269+ {
1270+ errsave (fcinfo -> context ,
12531271 (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
12541272 errmsg ("smallint out of range" )));
12551273
1274+ PG_RETURN_NULL ();
1275+ }
1276+
12561277 PG_RETURN_INT16 ((int16 ) num );
12571278}
12581279
0 commit comments