Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit af25bc0

Browse files
committed
Provide an extra-float-digits setting for pg_dump / pg_dumpall
Changes made by commit 02ddd49 mean that dumps made against pre version 12 instances are no longer comparable with those made against version 12 or later instances. This makes cross-version upgrade testing fail in the buildfarm. Experimentation has shown that the error is cured if the dumps are made when extra_float_digits is set to 0. Hence this patch allows for it to be explicitly set rather than relying on pg_dump's builtin default (3 in almost all cases). This feature might have other uses, but should not normally be used. Discussion: https://postgr.es/m/c76f7051-8fd3-ec10-7579-1f8842305b85@2ndQuadrant.com
1 parent 8e6ab9f commit af25bc0

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

doc/src/sgml/ref/pg_dump.sgml

+11
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,17 @@ PostgreSQL documentation
745745
</listitem>
746746
</varlistentry>
747747

748+
<varlistentry>
749+
<term><option>--extra-float-digits=<replaceable class="parameter">ndigits</replaceable></option></term>
750+
<listitem>
751+
<para>
752+
Use the specified value of extra_float_digits when dumping
753+
floating-point data, instead of the maximum available precision.
754+
Routine dumps made for backup purposes should not use this option.
755+
</para>
756+
</listitem>
757+
</varlistentry>
758+
748759
<varlistentry>
749760
<term><option>--if-exists</option></term>
750761
<listitem>

doc/src/sgml/ref/pg_dumpall.sgml

+11
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,17 @@ PostgreSQL documentation
300300
</listitem>
301301
</varlistentry>
302302

303+
<varlistentry>
304+
<term><option>--extra-float-digits=<replaceable class="parameter">ndigits</replaceable></option></term>
305+
<listitem>
306+
<para>
307+
Use the specified value of extra_float_digits when dumping
308+
floating-point data, instead of the maximum available precision.
309+
Routine dumps made for backup purposes should not use this option.
310+
</para>
311+
</listitem>
312+
</varlistentry>
313+
303314
<varlistentry>
304315
<term><option>--if-exists</option></term>
305316
<listitem>

src/bin/pg_dump/pg_dump.c

+28-3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ char g_comment_end[10];
134134

135135
static const CatalogId nilCatalogId = {0, 0};
136136

137+
/* override for standard extra_float_digits setting */
138+
static bool have_extra_float_digits = false;
139+
static int extra_float_digits;
140+
137141
/*
138142
* Macro for producing quoted, schema-qualified name of a dumpable object.
139143
*/
@@ -357,6 +361,7 @@ main(int argc, char **argv)
357361
{"disable-triggers", no_argument, &dopt.disable_triggers, 1},
358362
{"enable-row-security", no_argument, &dopt.enable_row_security, 1},
359363
{"exclude-table-data", required_argument, NULL, 4},
364+
{"extra-float-digits", required_argument, NULL, 8},
360365
{"if-exists", no_argument, &dopt.if_exists, 1},
361366
{"inserts", no_argument, &dopt.dump_inserts, 1},
362367
{"lock-wait-timeout", required_argument, NULL, 2},
@@ -557,6 +562,16 @@ main(int argc, char **argv)
557562
dosync = false;
558563
break;
559564

565+
case 8:
566+
have_extra_float_digits = true;
567+
extra_float_digits = atoi(optarg);
568+
if (extra_float_digits < -15 || extra_float_digits > 3)
569+
{
570+
write_msg(NULL, "extra_float_digits must be in range -15..3\n");
571+
exit_nicely(1);
572+
}
573+
break;
574+
560575
default:
561576
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
562577
exit_nicely(1);
@@ -965,6 +980,7 @@ help(const char *progname)
965980
printf(_(" --enable-row-security enable row security (dump only content user has\n"
966981
" access to)\n"));
967982
printf(_(" --exclude-table-data=TABLE do NOT dump data for the named table(s)\n"));
983+
printf(_(" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
968984
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
969985
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
970986
printf(_(" --load-via-partition-root load partitions via the root table\n"));
@@ -1059,10 +1075,19 @@ setup_connection(Archive *AH, const char *dumpencoding,
10591075
ExecuteSqlStatement(AH, "SET INTERVALSTYLE = POSTGRES");
10601076

10611077
/*
1062-
* Set extra_float_digits so that we can dump float data exactly (given
1063-
* correctly implemented float I/O code, anyway)
1078+
* Use an explicitly specified extra_float_digits if it has been
1079+
* provided. Otherwise, set extra_float_digits so that we can dump float
1080+
* data exactly (given correctly implemented float I/O code, anyway).
10641081
*/
1065-
if (AH->remoteVersion >= 90000)
1082+
if (have_extra_float_digits)
1083+
{
1084+
PQExpBuffer q = createPQExpBuffer();
1085+
appendPQExpBuffer(q, "SET extra_float_digits TO %d",
1086+
extra_float_digits);
1087+
ExecuteSqlStatement(AH, q->data);
1088+
destroyPQExpBuffer(q);
1089+
}
1090+
else if (AH->remoteVersion >= 90000)
10661091
ExecuteSqlStatement(AH, "SET extra_float_digits TO 3");
10671092
else
10681093
ExecuteSqlStatement(AH, "SET extra_float_digits TO 2");

src/bin/pg_dump/pg_dumpall.c

+7
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ main(int argc, char *argv[])
123123
{"column-inserts", no_argument, &column_inserts, 1},
124124
{"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
125125
{"disable-triggers", no_argument, &disable_triggers, 1},
126+
{"extra-float-digits", required_argument, NULL, 5},
126127
{"if-exists", no_argument, &if_exists, 1},
127128
{"inserts", no_argument, &inserts, 1},
128129
{"lock-wait-timeout", required_argument, NULL, 2},
@@ -318,6 +319,11 @@ main(int argc, char *argv[])
318319
appendPQExpBufferStr(pgdumpopts, " --no-sync");
319320
break;
320321

322+
case 5:
323+
appendPQExpBufferStr(pgdumpopts, " --extra-float-digits ");
324+
appendShellString(pgdumpopts, optarg);
325+
break;
326+
321327
default:
322328
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
323329
exit_nicely(1);
@@ -614,6 +620,7 @@ help(void)
614620
printf(_(" --column-inserts dump data as INSERT commands with column names\n"));
615621
printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
616622
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
623+
printf(_(" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
617624
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
618625
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
619626
printf(_(" --load-via-partition-root load partitions via the root table\n"));

0 commit comments

Comments
 (0)