how to use ascii character for quote in COPY in cqlsh

cassandra cql3 cqlsh csv sqlbulkcopy

Question

I am uploading data from a a big .csv file into Cassandra using copy in cqlsh. I am using cassandra 1.2 and CQL 3.0. However since " is part of my data I have to use some other character for uploading my data, I need to use any extended ASCII characters. I tried various approaches but fails.

The following works, but need to use an extended ascii characters for my purpose..

copy (<columnnames>) from <filename> where deleimiter='|' and quote = '"';
copy (<columnnames>) from <filename> where deleimiter='|' and quote = '~';

When I give quote='ß', I get the error below:

:"quotechar" must be an 1-character string

Pls advice on how I can use an extended ASCII character for quote parameter..

Thanks in advance

Popular Answer

I had a similar problem, and inspected the source code of cqlsh (it's a python script). In my case, I was generating the csv with python, so it was a matter of finding the right python csv parameters.

Here's the key information from cqlsh:

    csv_dialect_defaults = dict(delimiter=',', doublequote=False,
                            escapechar='\\', quotechar='"')

So if you are lucky enough to generate your .csv file from python, it's just a matter of using the csv module with:

    writer = csv.writer(open("output.csv", 'w'), **csv_dialect_defaults)

Hope this helps, even if you are not using python.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why