Apache Cassandra 1.1 Documentation

CQL Lexical Structure

This document corresponds to an earlier product version. Make sure you are using the version that corresponds to your version.

Latest Cassandra documentation | Earlier Cassandra documentation

CQL input consists of statements. Like SQL, statements change data, look up data, store data, or change the way data is stored. Statements end in a semicolon (;).

For example, the following is valid CQL syntax:

SELECT * FROM MyColumnFamily;

UPDATE MyColumnFamily
  SET SomeColumn = 'SomeValue'
  WHERE columnName = B70DE1D0-9908-4AE3-BE34-5573E5B09F14;

This is a sequence of two CQL statements. This example shows one statement per line, although a statement can usefully be split across lines as well.

CQL Case-Sensitivity

In CQL 3, identifiers, such as keyspace and table names, are case-insensitive unless enclosed in double quotation marks. You can force the case by using double quotation marks. For example:

CREATE TABLE test (
  Foo int PRIMARY KEY,
  "Bar" int
)

The following table shows partial queries that work and do not work to return results from the test table:

Queries that Work Queries that Don't Work
SELECT foo FROM ... SELECT "Foo" FROM ...
SELECT Foo FROM ... SELECT "BAR" FROM ...
SELECT FOO FROM ... SELECT bar FROM ...
SELECT "foo" FROM ...  
SELECT "Bar" FROM ...  

SELECT "foo" FROM ... works because internally, Cassandra stores foo in lowercase.

CQL keywords are case-insensitive. For example, the keywords SELECT and select are equivalent, although this document shows keywords in uppercase.

Keywords and Identifiers

Column names that contain characters that CQL cannot parse need to be enclosed in double quotation marks in CQL3. In CQL2, single quotation marks were used.

Valid expressions consist of these kinds of values:

  • identifier: A letter followed by any sequence of letters, digits, or the underscore.
  • string literal: Characters enclosed in single quotation marks. To use a single quotation mark itself in a string literal, escape it using a single quotation mark. For example, ''.
  • integer: An optional minus sign, -, followed by one or more digits.
  • uuid: 32 hex digits, 0-9 or a-f, which are case-insensitive, separated by dashes, -, after the 8th, 12th, 16th, and 20th digits. For example: 01234567-0123-0123-0123-0123456789ab
  • float: A series of one or more decimal digits, followed by a period, ., and one or more decimal digits. There is no provision for exponential, e, notation, no optional + sign, and the forms .42 and 42. are unacceptable. Use leading or trailing zeros before and after decimal points. For example, 0.42 and 42.0.
  • whitespace: Separates terms and used inside string literals, but otherwise CQL ignores whitespace.