@@ -54,14 +54,6 @@ typedef enum CopyDest
54
54
COPY_CALLBACK , /* to callback function */
55
55
} CopyDest ;
56
56
57
- /*
58
- * Per-format callback to send output representation of one attribute for
59
- * a `string`. `use_quote` tracks if quotes are required in the output
60
- * representation.
61
- */
62
- typedef void (* CopyAttributeOut ) (CopyToState cstate , const char * string ,
63
- bool use_quote );
64
-
65
57
/*
66
58
* This struct contains all the state variables used throughout a COPY TO
67
59
* operation.
@@ -105,7 +97,6 @@ typedef struct CopyToStateData
105
97
MemoryContext copycontext ; /* per-copy execution context */
106
98
107
99
FmgrInfo * out_functions ; /* lookup info for output functions */
108
- CopyAttributeOut copy_attribute_out ; /* output representation callback */
109
100
MemoryContext rowcontext ; /* per-row evaluation context */
110
101
uint64 bytes_processed ; /* number of bytes processed so far */
111
102
} CopyToStateData ;
@@ -126,12 +117,9 @@ static const char BinarySignature[11] = "PGCOPY\n\377\r\n\0";
126
117
static void EndCopy (CopyToState cstate );
127
118
static void ClosePipeToProgram (CopyToState cstate );
128
119
static void CopyOneRowTo (CopyToState cstate , TupleTableSlot * slot );
129
-
130
- /* Callbacks for copy_attribute_out */
131
- static void CopyAttributeOutText (CopyToState cstate , const char * string ,
132
- bool use_quote );
120
+ static void CopyAttributeOutText (CopyToState cstate , const char * string );
133
121
static void CopyAttributeOutCSV (CopyToState cstate , const char * string ,
134
- bool use_quote );
122
+ bool use_quote , bool single_attr );
135
123
136
124
/* Low-level communications functions */
137
125
static void SendCopyBegin (CopyToState cstate );
@@ -445,15 +433,6 @@ BeginCopyTo(ParseState *pstate,
445
433
/* Extract options from the statement node tree */
446
434
ProcessCopyOptions (pstate , & cstate -> opts , false /* is_from */ , options );
447
435
448
- /* Set output representation callback */
449
- if (!cstate -> opts .binary )
450
- {
451
- if (cstate -> opts .csv_mode )
452
- cstate -> copy_attribute_out = CopyAttributeOutCSV ;
453
- else
454
- cstate -> copy_attribute_out = CopyAttributeOutText ;
455
- }
456
-
457
436
/* Process the source/target relation or query */
458
437
if (rel )
459
438
{
@@ -857,8 +836,11 @@ DoCopyTo(CopyToState cstate)
857
836
858
837
colname = NameStr (TupleDescAttr (tupDesc , attnum - 1 )-> attname );
859
838
860
- /* Ignore quotes */
861
- cstate -> copy_attribute_out (cstate , colname , false);
839
+ if (cstate -> opts .csv_mode )
840
+ CopyAttributeOutCSV (cstate , colname , false,
841
+ list_length (cstate -> attnumlist ) == 1 );
842
+ else
843
+ CopyAttributeOutText (cstate , colname );
862
844
}
863
845
864
846
CopySendEndOfRow (cstate );
@@ -968,9 +950,12 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
968
950
{
969
951
string = OutputFunctionCall (& out_functions [attnum - 1 ],
970
952
value );
971
-
972
- cstate -> copy_attribute_out (cstate , string ,
973
- cstate -> opts .force_quote_flags [attnum - 1 ]);
953
+ if (cstate -> opts .csv_mode )
954
+ CopyAttributeOutCSV (cstate , string ,
955
+ cstate -> opts .force_quote_flags [attnum - 1 ],
956
+ list_length (cstate -> attnumlist ) == 1 );
957
+ else
958
+ CopyAttributeOutText (cstate , string );
974
959
}
975
960
else
976
961
{
@@ -1000,8 +985,7 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
1000
985
} while (0)
1001
986
1002
987
static void
1003
- CopyAttributeOutText (CopyToState cstate , const char * string ,
1004
- bool use_quote )
988
+ CopyAttributeOutText (CopyToState cstate , const char * string )
1005
989
{
1006
990
const char * ptr ;
1007
991
const char * start ;
@@ -1155,15 +1139,14 @@ CopyAttributeOutText(CopyToState cstate, const char *string,
1155
1139
*/
1156
1140
static void
1157
1141
CopyAttributeOutCSV (CopyToState cstate , const char * string ,
1158
- bool use_quote )
1142
+ bool use_quote , bool single_attr )
1159
1143
{
1160
1144
const char * ptr ;
1161
1145
const char * start ;
1162
1146
char c ;
1163
1147
char delimc = cstate -> opts .delim [0 ];
1164
1148
char quotec = cstate -> opts .quote [0 ];
1165
1149
char escapec = cstate -> opts .escape [0 ];
1166
- bool single_attr = (list_length (cstate -> attnumlist ) == 1 );
1167
1150
1168
1151
/* force quoting if it matches null_print (before conversion!) */
1169
1152
if (!use_quote && strcmp (string , cstate -> opts .null_print ) == 0 )
0 commit comments