Search code examples
cassandracassandra-clicqlsh

How to select data from a table and insert into another table?


I want to select specific fields of a table in cassandra and insert them into another table. I do this in sql server like this:

INSERT INTO Users(name,family)
SELECT name,family FROM Users

How to to this in cassandra-cli or cqlsh?


Solution

  • COPY keyspace.columnfamily1 (column1, column2,...) TO 'temp.csv';
    COPY keyspace.columnfamily2 (column1, column2,...) FROM 'temp.csv';
    

    here give your keyspace(schema-name) and instead of columnfamilyname1 use the table to which you want to copy and in columnfamily2 give the tablename in which you want to copy..

    And yes this is solution for CQL,however I have never tried in with CLI.