3

Update: Newline is working if I insert the same line by python driver script.

session.execute("INSERT INTO ctable" + " (cid, cstring) VALUES (%s, %s)", ('2', 'row1\nrow2'))

Still don't understand why the CQLSH command doesn't work.

Original Question: I am trying to insert a very long string into Cassandra by CQLSH command, and add a '\n' to split the string into two lines when display.

I tried

insert into ctable (cid, cstring ) values('2', 'row1\nrow2');
insert into ctable (cid, cstring ) values('2', 'row1\\nrow2');
insert into ctable (cid, cstring ) values('2', 'row1\r\nrow2');

None of above statements worked, all \n had been treated as a regular chracter. Can anyone help?

Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125

3 Answers3

4

Short answer: cqlsh does not handle escape characters in strings in any way. If you want to insert non-printable characters like newline \n, use cassandra drivers for your language. For a long answer, see discussion for issue CASSANDRA-8790

shutty
  • 3,298
  • 16
  • 27
3

Well you can do it directly in CQLSH if you actually press enter while typing the string. instead of entering the characters '\n' just press enter. CQLSH should show 3 dots indicating its adding content on the new line.

I know its too late to reply but leaving the answer here for someone like me who searches this question in the future.

FocusBlast
  • 31
  • 1
0

You can try this SQL, just use enter:

insert into ctable (cid, cstring ) values('2', 'row1
row2');

Sumrise
  • 71
  • 7