8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.256 2005/12/27 18:10:48 momjian Exp $
11
+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.257 2005/12/28 03:25:32 momjian Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -244,7 +244,7 @@ static Datum CopyReadBinaryAttribute(CopyState cstate,
244
244
bool * isnull );
245
245
static void CopyAttributeOutText (CopyState cstate , char * server_string );
246
246
static void CopyAttributeOutCSV (CopyState cstate , char * server_string ,
247
- bool use_quote );
247
+ bool use_quote , bool single_attr );
248
248
static List * CopyGetAttnums (Relation rel , List * attnamelist );
249
249
static char * limit_printout_length (const char * str );
250
250
@@ -1284,7 +1284,8 @@ CopyTo(CopyState cstate)
1284
1284
1285
1285
colname = NameStr (attr [attnum - 1 ]-> attname );
1286
1286
1287
- CopyAttributeOutCSV (cstate , colname , false);
1287
+ CopyAttributeOutCSV (cstate , colname , false,
1288
+ list_length (cstate -> attnumlist ) == 1 );
1288
1289
}
1289
1290
1290
1291
CopySendEndOfRow (cstate );
@@ -1359,7 +1360,8 @@ CopyTo(CopyState cstate)
1359
1360
value ));
1360
1361
if (cstate -> csv_mode )
1361
1362
CopyAttributeOutCSV (cstate , string ,
1362
- force_quote [attnum - 1 ]);
1363
+ force_quote [attnum - 1 ],
1364
+ list_length (cstate -> attnumlist ) == 1 );
1363
1365
else
1364
1366
CopyAttributeOutText (cstate , string );
1365
1367
}
@@ -2968,7 +2970,7 @@ CopyAttributeOutText(CopyState cstate, char *server_string)
2968
2970
*/
2969
2971
static void
2970
2972
CopyAttributeOutCSV (CopyState cstate , char * server_string ,
2971
- bool use_quote )
2973
+ bool use_quote , bool single_attr )
2972
2974
{
2973
2975
char * string ;
2974
2976
char c ;
@@ -2993,17 +2995,27 @@ CopyAttributeOutCSV(CopyState cstate, char *server_string,
2993
2995
*/
2994
2996
if (!use_quote )
2995
2997
{
2996
- for (tstring = string ; (c = * tstring ) != '\0' ; tstring += mblen )
2997
- {
2998
- if (c == delimc || c == quotec || c == '\n' || c == '\r' )
2998
+ /*
2999
+ * Because '\.' can be a data value, quote it if it appears
3000
+ * alone on a line so it is not interpreted as the end-of-data
3001
+ * marker.
3002
+ */
3003
+ if (single_attr && strcmp (string , "\\." ) == 0 )
3004
+ use_quote = true;
3005
+ else
3006
+ {
3007
+ for (tstring = string ; (c = * tstring ) != '\0' ; tstring += mblen )
2999
3008
{
3000
- use_quote = true;
3001
- break ;
3009
+ if (c == delimc || c == quotec || c == '\n' || c == '\r' )
3010
+ {
3011
+ use_quote = true;
3012
+ break ;
3013
+ }
3014
+ if (cstate -> encoding_embeds_ascii && IS_HIGHBIT_SET (c ))
3015
+ mblen = pg_encoding_mblen (cstate -> client_encoding , tstring );
3016
+ else
3017
+ mblen = 1 ;
3002
3018
}
3003
- if (cstate -> encoding_embeds_ascii && IS_HIGHBIT_SET (c ))
3004
- mblen = pg_encoding_mblen (cstate -> client_encoding , tstring );
3005
- else
3006
- mblen = 1 ;
3007
3019
}
3008
3020
}
3009
3021
0 commit comments