Обсуждение: Use carriage return with copy in PostgreSQL
I am trying to do a COPY from psql, but I need to use the carriage return, I understand that for LINUX servers by default it is used \n and in windows it is \r, this I am trying to do on a server with CentOS 7 and postgreSQL-11, the little test I'm doing is the following:
postgres=# COPY (SELECT C1 FROM (VALUES ('TEST one\r\n' ), ('TEST two\r\n'),('TEST Three \r \n')) AS t (C1)) TO '/home/postgres/demo.out';
And the result is the following:
TEST one\\r\\n
TEST two\\r\\n
TEST Three \\r \\n
In my opinion, this result or output of the copy process is wrong, or if it is the opposite, I hope you can help me, thank you!
postgres=# COPY (SELECT C1 FROM (VALUES ('TEST one\r\n' ), ('TEST two\r\n'),('TEST Three \r \n')) AS t (C1)) TO '/home/postgres/demo.out';
And the result is the following:
TEST one\\r\\n
TEST two\\r\\n
TEST Three \\r \\n
In my opinion, this result or output of the copy process is wrong, or if it is the opposite, I hope you can help me, thank you!
On Friday, May 14, 2021, Sergio Alonso <seralonso1014@gmail.com> wrote:
('TEST one\r\n' )
TEST one\\r\\n
This has nothing to do with the copy command. You are mis-informed on how to write string literals, in particular expecting ‘\r’ to be escaped when in fact in a simple string literal the only special character is the single quote.
You need to review 4.1.1.2 (https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS) if you need to write string literals that contain backslash escapes.
David J.