In Postgres, how to preserve newline character in COPY TO command?
<p>One of the column of my table contains string with '\n'.</p>

<pre><code>postgres=# select * from stringtest ;

 id |    inputstr

----+-----------------

  1 | Name : NOC\r   +

    | \r             +

    | Detail : Detail

(1 row)
</code></pre>

<p>But when I retrieve same table with COPY TO, new line character is getting escaped</p>

<pre><code>postgres=# COPY (select * from stringtest) TO STDOUT WITH DELIMITER E'\t' ;

1       Name : NOC\r\n\r\nDetail : Detail
</code></pre>

<p>How can I make COPY TO command to replace '\n' with new line ??</p>

<p>Expected output :</p>

<pre><code>postgres=# COPY (select * from stringtest) TO STDOUT WITH DELIMITER E'\t' ;

1       Name : NOC\r
        \r
        Detail : Detail
</code></pre>

<p>How to achieve this ??</p>