Increase the maximum value of extra_float_digits to 3, and have pg_dump
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 11 Sep 2009 19:17:04 +0000 (19:17 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 11 Sep 2009 19:17:04 +0000 (19:17 +0000)
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.

doc/src/sgml/config.sgml
src/backend/utils/adt/float.c
src/backend/utils/adt/geo_ops.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample
src/bin/pg_dump/pg_dump.c

index 220befa2ded05d1685ee1c0a415ad9fcd0edf7ab..54dfad403e8f5df19ec90fbef5407fa2e4c928db 100644 (file)
@@ -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.
index f5d5266d9737fa4b89b10f8d93cb28df14170a77..848c668753f4c2d3eda343e151e51f91960f0b04 100644 (file)
@@ -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);
                        }
        }
 
index 16e2b7fadb5cb0c70d1252127173dd5bb3e02a52..e9e6b35b0a44f09db70baea1f7b8d044d02d05be 100644 (file)
@@ -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)
 
 
 /*
index 63bb32949274f30e573d9676427e7a9d70a44171..2224d5683d53f97fd55b84275eeb6935d36301f2 100644 (file)
@@ -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
        },
 
        {
index 4a361391f2c7b6c33e07cb2a864326d9a933ae16..b10775cc2df8de67966a7cfb29e83368e9639a90 100644 (file)
                                        #   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
 
index f4fd818a8675f95defe61f7efc78a1cc5cc9cbd0..64e328c486d7317e67647631d5568efa12d0bf9c 100644 (file)
@@ -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");
 
        /*