88 *
99 *
1010 * 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 $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -244,7 +244,7 @@ static Datum CopyReadBinaryAttribute(CopyState cstate,
244244bool * isnull );
245245static void CopyAttributeOutText (CopyState cstate ,char * server_string );
246246static void CopyAttributeOutCSV (CopyState cstate ,char * server_string ,
247- bool use_quote );
247+ bool use_quote , bool single_attr );
248248static List * CopyGetAttnums (Relation rel ,List * attnamelist );
249249static char * limit_printout_length (const char * str );
250250
@@ -1284,7 +1284,8 @@ CopyTo(CopyState cstate)
12841284
12851285colname = NameStr (attr [attnum - 1 ]-> attname );
12861286
1287- CopyAttributeOutCSV (cstate ,colname , false);
1287+ CopyAttributeOutCSV (cstate ,colname , false,
1288+ list_length (cstate -> attnumlist )== 1 );
12881289}
12891290
12901291CopySendEndOfRow (cstate );
@@ -1359,7 +1360,8 @@ CopyTo(CopyState cstate)
13591360value ));
13601361if (cstate -> csv_mode )
13611362CopyAttributeOutCSV (cstate ,string ,
1362- force_quote [attnum - 1 ]);
1363+ force_quote [attnum - 1 ],
1364+ list_length (cstate -> attnumlist )== 1 );
13631365else
13641366CopyAttributeOutText (cstate ,string );
13651367}
@@ -2968,7 +2970,7 @@ CopyAttributeOutText(CopyState cstate, char *server_string)
29682970 */
29692971static void
29702972CopyAttributeOutCSV (CopyState cstate ,char * server_string ,
2971- bool use_quote )
2973+ bool use_quote , bool single_attr )
29722974{
29732975char * string ;
29742976char c ;
@@ -2993,17 +2995,27 @@ CopyAttributeOutCSV(CopyState cstate, char *server_string,
29932995 */
29942996if (!use_quote )
29952997{
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 )
29993008{
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 ;
30023018}
3003- if (cstate -> encoding_embeds_ascii && IS_HIGHBIT_SET (c ))
3004- mblen = pg_encoding_mblen (cstate -> client_encoding ,tstring );
3005- else
3006- mblen = 1 ;
30073019}
30083020}
30093021