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.
-
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
-
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;