aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/formatting.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-07-22 19:19:44 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-07-22 19:19:44 -0400
commita57d312a7706321d850faa048a562a0c0c01b835 (patch)
treea70d8fb04fb1ab59b7cc76072e59dd2be02e1021 /src/backend/utils/adt/formatting.c
parent9e108984fb35d8f9e2c2bffa10c0034f9161e802 (diff)
downloadpostgresql-a57d312a7706321d850faa048a562a0c0c01b835.tar.gz
postgresql-a57d312a7706321d850faa048a562a0c0c01b835.zip
Support infinity and -infinity in the numeric data type.
Add infinities that behave the same as they do in the floating-point data types. Aside from any intrinsic usefulness these may have, this closes an important gap in our ability to convert floating values to numeric and/or replace float-based APIs with numeric. The new values are represented by bit patterns that were formerly not used (although old code probably would take them for NaNs). So there shouldn't be any pg_upgrade hazard. Patch by me, reviewed by Dean Rasheed and Andrew Gierth Discussion: https://postgr.es/m/606717.1591924582@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/adt/formatting.c')
-rw-r--r--src/backend/utils/adt/formatting.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 16768b28c30..66264381366 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -6129,9 +6129,12 @@ numeric_to_char(PG_FUNCTION_ARGS)
/*
* numeric_out_sci() does not emit a sign for positive numbers. We
* need to add a space in this case so that positive and negative
- * numbers are aligned. We also have to do the right thing for NaN.
+ * numbers are aligned. Also must check for NaN/infinity cases, which
+ * we handle the same way as in float8_to_char.
*/
- if (strcmp(orgnum, "NaN") == 0)
+ if (strcmp(orgnum, "NaN") == 0 ||
+ strcmp(orgnum, "Infinity") == 0 ||
+ strcmp(orgnum, "-Infinity") == 0)
{
/*
* Allow 6 characters for the leading sign, the decimal point,
@@ -6346,7 +6349,7 @@ int8_to_char(PG_FUNCTION_ARGS)
/*
* numeric_out_sci() does not emit a sign for positive numbers. We
* need to add a space in this case so that positive and negative
- * numbers are aligned. We don't have to worry about NaN here.
+ * numbers are aligned. We don't have to worry about NaN/inf here.
*/
if (*orgnum != '-')
{