Handle NULL fields in WRITE_INDEX_ARRAY
authorPeter Eisentraut <[email protected]>
Wed, 27 Apr 2022 07:15:09 +0000 (09:15 +0200)
committerPeter Eisentraut <[email protected]>
Wed, 27 Apr 2022 07:15:09 +0000 (09:15 +0200)
Unlike existing WRITE_*_ARRAY macros, WRITE_INDEX_ARRAY needs to
handle the case that the field is NULL.  We already have the
convention to print NULL fields as "<>", so we do that here as well.
There is currently no corresponding read function for this, so reading
this back in is not implemented, but it could be if needed.

Reported-by: Richard Guo <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAMbWs4-LN%3DbF8f9eU2R94dJtF54DfDvBq%2BovqHnOQqbinYDrUw%40mail.gmail.com

src/backend/nodes/outfuncs.c

index 6a02f81ad5c48bcd966face1157622b1ce7d3e38..b1f2de8b28de2458ac2b4f7b07141de488479c71 100644 (file)
@@ -124,11 +124,18 @@ static void outChar(StringInfo str, char c);
            appendStringInfo(str, " %u", node->fldname[i]); \
    } while(0)
 
+/*
+ * This macro supports the case that the field is NULL.  For the other array
+ * macros, that is currently not needed.
+ */
 #define WRITE_INDEX_ARRAY(fldname, len) \
    do { \
        appendStringInfoString(str, " :" CppAsString(fldname) " "); \
-       for (int i = 0; i < len; i++) \
-           appendStringInfo(str, " %u", node->fldname[i]); \
+       if (node->fldname) \
+           for (int i = 0; i < len; i++) \
+               appendStringInfo(str, " %u", node->fldname[i]); \
+       else \
+           appendStringInfoString(str, "<>"); \
    } while(0)
 
 #define WRITE_INT_ARRAY(fldname, len) \