diff options
Diffstat (limited to 'src/backend/nodes/outfuncs.c')
-rw-r--r-- | src/backend/nodes/outfuncs.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index c55375e7f91..3337b77ae6d 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -25,6 +25,9 @@ #include "nodes/pg_list.h" #include "utils/datum.h" +/* State flag that determines how nodeToStringInternal() should treat location fields */ +static bool write_location_fields = false; + static void outChar(StringInfo str, char c); static void outDouble(StringInfo str, double d); @@ -88,7 +91,7 @@ static void outDouble(StringInfo str, double d); /* Write a parse location field (actually same as INT case) */ #define WRITE_LOCATION_FIELD(fldname) \ - appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname) + appendStringInfo(str, " :" CppAsString(fldname) " %d", write_location_fields ? node->fldname : -1) /* Write a Node field */ #define WRITE_NODE_FIELD(fldname) \ @@ -757,19 +760,47 @@ outNode(StringInfo str, const void *obj) /* * nodeToString - * returns the ascii representation of the Node as a palloc'd string + * + * write_loc_fields determines whether location fields are output with their + * actual value rather than -1. The actual value can be useful for debugging, + * but for most uses, the actual value is not useful, since the original query + * string is no longer available. */ -char * -nodeToString(const void *obj) +static char * +nodeToStringInternal(const void *obj, bool write_loc_fields) { StringInfoData str; + bool save_write_location_fields; + + save_write_location_fields = write_location_fields; + write_location_fields = write_loc_fields; /* see stringinfo.h for an explanation of this maneuver */ initStringInfo(&str); outNode(&str, obj); + + write_location_fields = save_write_location_fields; + return str.data; } /* + * Externally visible entry points + */ +char * +nodeToString(const void *obj) +{ + return nodeToStringInternal(obj, false); +} + +char * +nodeToStringWithLocations(const void *obj) +{ + return nodeToStringInternal(obj, true); +} + + +/* * bmsToString - * returns the ascii representation of the Bitmapset as a palloc'd string */ |