summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2009-09-11 19:17:04 +0000
committerTom Lane2009-09-11 19:17:04 +0000
commitf9c08b9e06f40703da3bed3e3d21d98941c4818e (patch)
treee2ca4ca2fc373f0dd0def6a134df33f97d134fc9
parent167501570c74390dfb7a5dd71e260ab3d4fd9904 (diff)
Increase the maximum value of extra_float_digits to 3, and have pg_dump
use that value when the backend is new enough to allow it. This responds to bug report from Keh-Cheng Chu pointing out that although 2 extra digits should be sufficient to dump and restore float8 exactly, it is possible to need 3 extra digits for float4 values.
-rw-r--r--doc/src/sgml/config.sgml2
-rw-r--r--src/backend/utils/adt/float.c4
-rw-r--r--src/backend/utils/adt/geo_ops.c4
-rw-r--r--src/backend/utils/misc/guc.c2
-rw-r--r--src/backend/utils/misc/postgresql.conf.sample2
-rw-r--r--src/bin/pg_dump/pg_dump.c4
6 files changed, 10 insertions, 8 deletions
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 220befa2de..54dfad403e 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -4291,7 +4291,7 @@ SET XML OPTION { DOCUMENT | CONTENT };
floating-point values, including <type>float4</>, <type>float8</>,
and geometric data types. The parameter value is added to the
standard number of digits (<literal>FLT_DIG</> or <literal>DBL_DIG</>
- as appropriate). The value can be set as high as 2, to include
+ as appropriate). The value can be set as high as 3, to include
partially-significant digits; this is especially useful for dumping
float data that needs to be restored exactly. Or it can be set
negative to suppress unwanted digits.
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index f5d5266d97..848c668753 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -334,7 +334,7 @@ float4out(PG_FUNCTION_ARGS)
if (ndig < 1)
ndig = 1;
- sprintf(ascii, "%.*g", ndig, num);
+ snprintf(ascii, MAXFLOATWIDTH + 1, "%.*g", ndig, num);
}
}
@@ -523,7 +523,7 @@ float8out(PG_FUNCTION_ARGS)
if (ndig < 1)
ndig = 1;
- sprintf(ascii, "%.*g", ndig, num);
+ snprintf(ascii, MAXDOUBLEWIDTH + 1, "%.*g", ndig, num);
}
}
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index 16e2b7fadb..e9e6b35b0a 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -85,8 +85,8 @@ static Point* lseg_interpt_internal(LSEG *l1, LSEG *l2);
#define RDELIM_C '>'
/* Maximum number of characters printed by pair_encode() */
-/* ...+2+7 : 2 accounts for extra_float_digits max value */
-#define P_MAXLEN (2*(DBL_DIG+2+7)+1)
+/* ...+3+7 : 3 accounts for extra_float_digits max value */
+#define P_MAXLEN (2*(DBL_DIG+3+7)+1)
/*
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 63bb329492..2224d5683d 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1684,7 +1684,7 @@ static struct config_int ConfigureNamesInt[] =
"(FLT_DIG or DBL_DIG as appropriate).")
},
&extra_float_digits,
- 0, -15, 2, NULL, NULL
+ 0, -15, 3, NULL, NULL
},
{
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 4a361391f2..b10775cc2d 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -445,7 +445,7 @@
# India
# You can create your own file in
# share/timezonesets/.
-#extra_float_digits = 0 # min -15, max 2
+#extra_float_digits = 0 # min -15, max 3
#client_encoding = sql_ascii # actually, defaults to database
# encoding
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index f4fd818a86..64e328c486 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -595,7 +595,9 @@ main(int argc, char **argv)
* If supported, set extra_float_digits so that we can dump float data
* exactly (given correctly implemented float I/O code, anyway)
*/
- if (g_fout->remoteVersion >= 70400)
+ if (g_fout->remoteVersion >= 80500)
+ do_sql_command(g_conn, "SET extra_float_digits TO 3");
+ else if (g_fout->remoteVersion >= 70400)
do_sql_command(g_conn, "SET extra_float_digits TO 2");
/*