2

One of the column of my table contains string with '\n'.

postgres=# select * from stringtest ;

 id |    inputstr

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

  1 | Name : NOC\r   +

    | \r             +

    | Detail : Detail

(1 row)

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

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

1       Name : NOC\r\n\r\nDetail : Detail

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

Expected output :

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

1       Name : NOC\r
        \r
        Detail : Detail

How to achieve this ??

  • Not really, but the purpose of COPY default format is to be interpreted as input by another COPY, not to be generically reusable. Maybe the CSV format would be closer to your pupose. – Daniel Vérité Mar 1 '16 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.