|
17 | 17 | #include <ctype.h>
|
18 | 18 |
|
19 | 19 | #include "access/attnum.h"
|
| 20 | +#include "common/shortest_dec.h" |
20 | 21 | #include "lib/stringinfo.h"
|
21 | 22 | #include "miscadmin.h"
|
22 | 23 | #include "nodes/bitmapset.h"
|
|
25 | 26 | #include "utils/datum.h"
|
26 | 27 |
|
27 | 28 | static void outChar(StringInfo str, char c);
|
| 29 | +static void outDouble(StringInfo str, double d); |
28 | 30 |
|
29 | 31 |
|
30 | 32 | /*
|
@@ -69,9 +71,10 @@ static void outChar(StringInfo str, char c);
|
69 | 71 | appendStringInfo(str, " :" CppAsString(fldname) " %d", \
|
70 | 72 | (int) node->fldname)
|
71 | 73 |
|
72 |
| -/* Write a float field --- caller must give format to define precision */ |
73 |
| -#define WRITE_FLOAT_FIELD(fldname,format) \ |
74 |
| - appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname) |
| 74 | +/* Write a float field (actually, they're double) */ |
| 75 | +#define WRITE_FLOAT_FIELD(fldname) \ |
| 76 | + (appendStringInfo(str, " :" CppAsString(fldname) " "), \ |
| 77 | + outDouble(str, node->fldname)) |
75 | 78 |
|
76 | 79 | /* Write a boolean field */
|
77 | 80 | #define WRITE_BOOL_FIELD(fldname) \
|
@@ -198,6 +201,18 @@ outChar(StringInfo str, char c)
|
198 | 201 | outToken(str, in);
|
199 | 202 | }
|
200 | 203 |
|
| 204 | +/* |
| 205 | + * Convert a double value, attempting to ensure the value is preserved exactly. |
| 206 | + */ |
| 207 | +static void |
| 208 | +outDouble(StringInfo str, double d) |
| 209 | +{ |
| 210 | + char buf[DOUBLE_SHORTEST_DECIMAL_LEN]; |
| 211 | + |
| 212 | + double_to_shortest_decimal_buf(d, buf); |
| 213 | + appendStringInfoString(str, buf); |
| 214 | +} |
| 215 | + |
201 | 216 | /*
|
202 | 217 | * common implementation for scalar-array-writing functions
|
203 | 218 | *
|
@@ -525,7 +540,7 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
|
525 | 540 | break;
|
526 | 541 | case RTE_NAMEDTUPLESTORE:
|
527 | 542 | WRITE_STRING_FIELD(enrname);
|
528 |
| - WRITE_FLOAT_FIELD(enrtuples, "%.0f"); |
| 543 | + WRITE_FLOAT_FIELD(enrtuples); |
529 | 544 | WRITE_OID_FIELD(relid);
|
530 | 545 | WRITE_NODE_FIELD(coltypes);
|
531 | 546 | WRITE_NODE_FIELD(coltypmods);
|
|
0 commit comments