Wednesday 5 February 2020

Cassandra: Export query result to a csv file


Using ‘CAPTURE’ command, you can export data to a csv file.

Example
CAPTURE '/Users/krishna/Documents/employee.csv';
Once you ran above capture command, then query output is stored to '/Users/krishna/Documents/employee.csv'.

cqlsh> SELECT * FROM cassandratutorial.employee;

 id | age | firstname | lastname
----+-----+-----------+----------
  1 |  30 |   Krishna |   Gurram
  2 |  31 |       Ram |   Gurram
  4 |  45 |    Chitra |    Rajan
  3 |  45 |     Vijay |   Ponnam

(4 rows)
cqlsh> 
cqlsh> CAPTURE '/Users/krishna/Documents/employee.csv';
Now capturing query output to '/Users/krishna/Documents/employee.csv'.
cqlsh> 
cqlsh> SELECT * FROM cassandratutorial.employee;


Open ‘/Users/krishna/Documents/employee.csv’ file, you can see below content.


Previous                                                    Next                                                    Home

No comments:

Post a Comment