Importing data from a CSV file

In a production database, inserting columns and column values programmatically is more practical than using cqlsh, but often, testing queries using the cqlsh SQL-like shell is very convenient. A comma-delimited file, or CSV file, is useful if several records need inserting. While not strictly an INSERT command, it is a common method for inserting data.

  1. Locate your CSV file and check options to use.

    category|points|id|lastname
    GC|1269|220844bf-4860-49d6-9a4b-6b5d3a79cbae|SMITH
    One-day-races|367|220844bf-4860-49d6-9a4b-6b5d3a79cbbd|ALBERT
    GC|1324|220844bf-4860-49d6-9a4b-6b5d3a79cbab|DOE
  2. To insert the data in the CSV file, use the COPY command:

    COPY cycling.cyclist_category FROM '../CSV/cyclist_category.csv'
    WITH DELIMITER = '|'
      AND HEADER = TRUE;

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com