cassandracqlshcassandra-cli

How to insert a newline(\n) inside a String(text) into Cassandra by CQLSH command?


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?


Solution

  • 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