diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-04-27 09:15:09 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-04-27 09:15:09 +0200 |
commit | 9ddf251f94090cebf1bd8fc18396cb8a4b580d04 (patch) | |
tree | f800569010ea6064953208a4fd192126ba31953c | |
parent | 06cafd6f577ba251ac10d4f009fc3be424705a37 (diff) | |
download | postgresql-9ddf251f94090cebf1bd8fc18396cb8a4b580d04.tar.gz postgresql-9ddf251f94090cebf1bd8fc18396cb8a4b580d04.zip |
Handle NULL fields in WRITE_INDEX_ARRAY
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 <guofenglinux@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/CAMbWs4-LN%3DbF8f9eU2R94dJtF54DfDvBq%2BovqHnOQqbinYDrUw%40mail.gmail.com
-rw-r--r-- | src/backend/nodes/outfuncs.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 6a02f81ad5c..b1f2de8b28d 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -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) \ |