From b9d6038d7048ddb837aa1d286fb8f5ca0e9b3a83 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 7 Feb 2024 12:28:55 +0900 Subject: [PATCH] Simplify signature of CopyAttributeOutCSV() in copyto.c This has come up in 2889fd23be56, reverted later on, and is still useful on its own to reduce a bit the differences between the code paths dedicated to CSV and text. Discussion: https://postgr.es/m/ZcCKwAeFrlOqPBuN@paquier.xyz --- src/backend/commands/copyto.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c index d3dc3fc854..bd4710a79b 100644 --- a/src/backend/commands/copyto.c +++ b/src/backend/commands/copyto.c @@ -119,7 +119,7 @@ static void ClosePipeToProgram(CopyToState cstate); static void CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot); static void CopyAttributeOutText(CopyToState cstate, const char *string); static void CopyAttributeOutCSV(CopyToState cstate, const char *string, - bool use_quote, bool single_attr); + bool use_quote); /* Low-level communications functions */ static void SendCopyBegin(CopyToState cstate); @@ -837,8 +837,7 @@ DoCopyTo(CopyToState cstate) colname = NameStr(TupleDescAttr(tupDesc, attnum - 1)->attname); if (cstate->opts.csv_mode) - CopyAttributeOutCSV(cstate, colname, false, - list_length(cstate->attnumlist) == 1); + CopyAttributeOutCSV(cstate, colname, false); else CopyAttributeOutText(cstate, colname); } @@ -952,8 +951,7 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot) value); if (cstate->opts.csv_mode) CopyAttributeOutCSV(cstate, string, - cstate->opts.force_quote_flags[attnum - 1], - list_length(cstate->attnumlist) == 1); + cstate->opts.force_quote_flags[attnum - 1]); else CopyAttributeOutText(cstate, string); } @@ -1139,7 +1137,7 @@ CopyAttributeOutText(CopyToState cstate, const char *string) */ static void CopyAttributeOutCSV(CopyToState cstate, const char *string, - bool use_quote, bool single_attr) + bool use_quote) { const char *ptr; const char *start; @@ -1147,6 +1145,7 @@ CopyAttributeOutCSV(CopyToState cstate, const char *string, char delimc = cstate->opts.delim[0]; char quotec = cstate->opts.quote[0]; char escapec = cstate->opts.escape[0]; + bool single_attr = (list_length(cstate->attnumlist) == 1); /* force quoting if it matches null_print (before conversion!) */ if (!use_quote && strcmp(string, cstate->opts.null_print) == 0)