Tutorial: Inserting and loading data into an Amazon Keyspaces table - Amazon Keyspaces (for Apache Cassandra)

Tutorial: Inserting and loading data into an Amazon Keyspaces table

To create data in your employees_tbl table, use the INSERT statement to add a single row.

  1. Before you can write data to your Amazon Keyspaces table using cqlsh, you must set the write consistency for the current cqlsh session to LOCAL_QUORUM. For more information about supported consistency levels, see Write consistency levels. Note that this step is not required if you are using the CQL editor in the AWS Management Console.

    CONSISTENCY LOCAL_QUORUM;
  2. To insert a single record, run the following command in the CQL editor.

    INSERT INTO "myGSGKeyspace".employees_tbl (id, name, project, region, division, role, pay_scale, vacation_hrs, manager_id) VALUES ('012-34-5678','Russ','NightFlight','US','Engineering','IC',3,12.5, '234-56-7890') ;
  3. Verify that the data was correctly added to your table by running the following command.

    SELECT * FROM "myGSGKeyspace".employees_tbl ;
To insert multiple records from a file using cqlsh
  1. Download the sample data file (employees.csv) contained in the following archive file sampledata.zip. This CSV (comma-separated values) file contains the following data. Remember the path that you save the file to.

    
                     Screenshot of CSV file with output of preceding SELECT
                        statement
  2. Open a command shell and enter the following:

    cqlsh

  3. At the cqlsh prompt (cqlsh>), specify a keyspace.

    USE "myGSGKeyspace" ;
  4. Set write consistency to LOCAL_QUORUM. For more information about supported consistency levels, see Write consistency levels.

    CONSISTENCY LOCAL_QUORUM;
  5. At the keyspace prompt (cqlsh:keyspace_name>), run the following query.

    COPY employees_tbl (id,name,project,region,division,role,pay_scale,vacation_hrs,manager_id) FROM 'path-to-the-csv-file/employees.csv' WITH delimiter=',' AND header=TRUE ;
  6. Verify that the data was correctly added to your table by running the following query.

    SELECT * FROM employees_tbl ;