unexpected data loaded into database when used COPY FROM - Mailing list pgsql-hackers

From jianggq@fujitsu.com
Subject unexpected data loaded into database when used COPY FROM
Date
Msg-id OS0PR01MB5972BD2A88058A716D9FBAE9AA1A9@OS0PR01MB5972.jpnprd01.prod.outlook.com
Whole thread Raw
Responses Re: unexpected data loaded into database when used COPY FROM  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi 

When I used COPY FROM command on windows, I found that If the line data ends with a backslash and carriage
return/newlines(\r\n),COPYFROM mishandle the line .
 
As a result, there were unexpected data loaded into database.

The following case can reproduce this issue.
----------------------------------------------------------------------------
Data file:
lines ending with carriage return/newlines(\r\n)
  ----- test.txt ------
  AAA\   ★there is only one Backslash characters (\) in the line end.
  BBB
  -------------------

Data loading:
#CREATE TABLE copytest( a TEXT);
#COPY copytest FROM '/test.txt';

Data in database:
# SELECT * FROM copytest;
   a
-------
 aaa\r  ★\r is loaded unexpectedly
 bbb
(2 rows)
--------------------------------------------------------------------------

In this case , is it better to throw an error to user than to load the unexpected data to database?

Regards,

pgsql-hackers by date:

Previous
From: Jakub Wartak
Date:
Subject: RE: Cosmic ray hits integerset
Next
From: Tatsuo Ishii
Date:
Subject: Re: [HACKERS] WIP aPatch: Pgbench Serialization and deadlock errors