Synopsis:
USE <KEYSPACE>;
A USE statement consists of the USE keyword, followed by a valid keyspace name. Its purpose is to assign the per-connection, current working keyspace. All subsequent keyspace-specific actions will be performed in the context of the supplied value.
Synopsis:
SELECT [FIRST N] [REVERSED] <SELECT EXPR> FROM <COLUMN FAMILY> [USING <CONSISTENCY>]
[WHERE <CLAUSE>] [LIMIT N];
A SELECT is used to read one or more records from a Cassandra column family. It returns a result-set of rows, where each row consists of a key and a collection of columns corresponding to the query.
SELECT [FIRST N] [REVERSED] name1, name2, name3 FROM ...
SELECT [FIRST N] [REVERSED] name1..nameN FROM ...
The SELECT expression determines which columns will appear in the results and takes the form of either a comma separated list of names, or a range. The range notation consists of a start and end column name separated by two periods (..). The set of columns returned for a range is start and end inclusive.
The FIRST option accepts an integer argument and can be used to apply a limit to the number of columns returned per row. When this limit is left unset it defaults to 10,000 columns.
The REVERSED option causes the sort order of the results to be reversed.
It is worth noting that unlike the projection in a SQL SELECT, there is no guarantee that the results will contain all of the columns specified. This is because Cassandra is schema-less and there are no guarantees that a given column exists.
SELECT ... FROM <COLUMN FAMILY> ...
The FROM clause is used to specify the Cassandra column family applicable to a SELECT query.
SELECT ... [USING <CONSISTENCY>] ...
Following the column family clause is an optional consistency level specification.
SELECT ... WHERE KEY = keyname AND name1 = value1
SELECT ... WHERE KEY >= startkey and KEY =< endkey AND name1 = value1
The WHERE clause provides for filtering the rows that appear in results. The clause can filter on a key name, or range of keys, and in the case of indexed columns, on column values. Key filters are specified using the KEY keyword, a relational operator, (one of =, >, >=, <, and <=), and a term value. When terms appear on both sides of a relational operator it is assumed the filter applies to an indexed column. With column index filters, the term on the left of the operator is the name, the term on the right is the value to filter on.
Note: The greater-than and less-than operators (> and <) result in key ranges that are inclusive of the terms. There is no supported notion of “strictly” greater-than or less-than; these operators are merely supported as aliases to >= and <=.
SELECT ... WHERE <CLAUSE> [LIMIT N] ...
Limiting the number of rows returned can be achieved by adding the LIMIT option to a SELECT expression. LIMIT defaults to 10,000 when left unset.
Synopsis:
UPDATE <COLUMN FAMILY> [USING CONSISTENCY.<CL>]
SET name1 = value1, name2 = value2 WHERE KEY = keyname;
An UPDATE is used to write one or more columns to a record in a Cassandra column family. No results are returned.
UPDATE <COLUMN FAMILY> ...
Statements begin with the UPDATE keyword followed by a Cassandra column family name.
UPDATE ... [USING <CONSISTENCY>] ...
Following the column family identifier is an optional consistency level specification.
UPDATE ... SET name1 = value1, name2 = value2 WHERE KEY = keyname;
Rows are created or updated by supplying column names and values in term assignment format. Multiple columns can be set by separating the name/value pairs using commas. Each update statement requires exactly one key to be specified using a WHERE clause and the KEY keyword.
Additionally, it is also possible to send multiple UPDATES to a node at once using a batch syntax:
BEGIN BATCH [USING <CONSISTENCY>]
UPDATE CF1 SET name1 = value1, name2 = value2 WHERE KEY = keyname1;
UPDATE CF1 SET name3 = value3 WHERE KEY = keyname2;
UPDATE CF2 SET name4 = value4, name5 = value5 WHERE KEY = keyname3;
APPLY BATCH
When batching UPDATEs, a single consistency level is used for the entire batch, it appears after the BEGIN BATCH statement, and uses the standard consistency level specification. Batch UPDATEs default to CONSISTENCY.ONE when left unspecified.
NOTE: While there are no isolation guarantees, UPDATE queries are atomic within a give record.
Synopsis:
DELETE [COLUMNS] FROM <COLUMN FAMILY> [USING <CONSISTENCY>] WHERE KEY = keyname1
DELETE [COLUMNS] FROM <COLUMN FAMILY> [USING <CONSISTENCY>] WHERE KEY IN (keyname1, keyname2);
A DELETE is used to perform the removal of one or more columns from one or more rows.
DELETE [COLUMNS] ...
Following the DELETE keyword is an optional comma-delimited list of column name terms. When no column names are specified, the remove applies to the entire row(s) matched by the WHERE clause
DELETE ... FROM <COLUMN FAMILY> ...
The column family name follows the list of column names.
UPDATE ... [USING <CONSISTENCY>] ...
Following the column family identifier is an optional consistency level specification.
UPDATE ... WHERE KEY = keyname1
UPDATE ... WHERE KEY IN (keyname1, keyname2)
The WHERE clause is used to determine which row(s) a DELETE applies to. The first form allows the specification of a single keyname using the KEY keyword and the = operator. The second form allows a list of keyname terms to be specified using the IN notation and a parenthesized list of comma-delimited keyname terms.
Synopsis:
TRUNCATE <COLUMN FAMILY>
Accepts a single argument for the column family name, and permanently removes all data from said column family.
... USING <CONSISTENCY> ...
Consistency level specifications are made up the keyword USING, followed by a consistency level identifier. Valid consistency levels are as follows:
CONSISTENCY.ZEROCONSISTENCY.ONE (default)CONSISTENCY.QUORUMCONSISTENCY.ALLCONSISTENCY.DCQUORUMCONSISTENCY.DCQUORUMSYNCWhere possible, the type of terms are inferred; the following term types are supported:
String literals are any value enclosed in double-quotes, (`"`). String literals are treated as raw bytes; no interpolation is performed.
Integers are any term consisting soley of unquoted numericals, longs are any otherwise valid integer term followed by an upper case “L”, (e.g. 100L). It is an error to specify an integer term that will not fit in 4 bytes unsigned, or a long that will not fit in 8 bytes unsigned.