MySQL: carriage-return in query breaks my import I use simple echo &quot;select * from tab&quot; | mysql --batch --quick --skip-column-names .... &gt; /tmp/file from mysql to get data.
Then, import to postgres using \copy tab FROM /tmp/file DELIMITER E'\t' QUOTE E'\b' NULL AS '\N' CSV.
for the most part it works well up until a carriage-return value comes in a text field.
Something like(partial string):
id      error
122859  Error invoking external process   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current^M\n                                 Dload  Upload   Total   Spent    Left  Speed^M\n^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0^M\ncurl: (35) Unknown SSL protocol error in connection to file.fm:443 ^M\n&lt;br&gt;The error occurred on line 26 in file.

When ^M comes it breaks my import, I was initially thinking this is import issue, but clearly it is the export (mysql) side.
I saw this solution but I'm thinking if there is a more elegant solution that doesn't requires me to rewrite all my export queries. Also, replacing \r\n to \n doesn't solve all the problems in this output example.
If CR or CRLF is the line terminator, so state.  Don't assume LF is smart enough to include CR.