1

I am trying to insert a row with a string column that contains new line character. The create table statement and insert query are given below.

create table stringtest(id int, inputstr character varying(200));

insert into stringtest values(1,'Name : NOC\r\n\r\nDetail : Detail');

The insert query is executed properly. However when the same row is fetched(when the postgres is in linux), the value of inputstr is not displayed with new line instead it is displayed as

 id |                     inputstr
----+---------------------------------------------------
  1 | Name : NOC\r\n\r\nDetail : Detail

While if we do the same in the windows, we get the resultset as desired as provided below

ngnms=# select * from stringtest;
 id |          inputstr
----+----------------------------
  1 | Site Name : NOC\r         +
    | \r                        +
    | Device Detail : agentdname
(1 row)

what should be done to get the result as desired with the new line instead of escape characters

Point to be added is if the same row is inserted using copy, the new line is preserved properly

2
  • This might help. Commented Oct 31, 2013 at 5:06
  • I have fixed it by including E before the string with line feed as below insert into stringtest values(1,E'Name : NOC\r\n\r\nDetail : Detail'); Commented Oct 31, 2013 at 6:08

1 Answer 1

5

I have fixed it by including E before the string with line feed as below

insert into stringtest values(1,E'Name : NOC\r\n\r\nDetail : Detail');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.