Cassandra Query Language (CQL) Elements in Amazon Keyspaces - Amazon Keyspaces (for Apache Cassandra)

Cassandra Query Language (CQL) Elements in Amazon Keyspaces

Learn about the Cassandra Query Language (CQL) elements that are supported by Amazon Keyspaces, including identifiers, constants, terms, and data types.

Identifiers

Identifiers (or names) are used to identify tables, columns, and other objects. An identifier can be quoted or not quoted. The following applies.

identifier ::= unquoted_identifier | quoted_identifier unquoted_identifier ::= re('[a-zA-Z][a-zA-Z0-9_]*') quoted_identifier ::= '"' (any character where " can appear if doubled)+ '"'

Constants

The following constants are defined.

constant ::= string | integer | float | boolean | uuid | blob | NULL string ::= '\'' (any character where ' can appear if doubled)+ '\'' '$$' (any character other than '$$') '$$' integer ::= re('-?[0-9]+') float ::= re('-?[0-9]+(\.[0-9]*)?([eE][+-]?[0-9+])?') | NAN | INFINITY boolean ::= TRUE | FALSE uuid ::= hex{8}-hex{4}-hex{4}-hex{4}-hex{12} hex ::= re("[0-9a-fA-F]") blob ::= '0' ('x' | 'X') hex+

Terms

A term denotes the kind of values that are supported. Terms are defined by the following.

term ::= constant | literal | function_call | arithmetic_operation | type_hint | bind_marker literal ::= collection_literal | udt_literal | tuple_literal function_call ::= identifier '(' [ term (',' term)* ] ')' arithmetic_operation ::= '-' term | term ('+' | '-' | '*' | '/' | '%') term

Data Types

Amazon Keyspaces supports the following data types:

String Types

Data Type Description

ascii

Represents an ASCII character string.

text

Represents a UTF-8 encoded string.

varchar

Represents a UTF-8 encoded string (varchar is an alias for text).

Numeric Types

Data Type Description

bigint

Represents a 64-bit signed long.

counter

Represents a 64-bit signed integer counter. For more information, see Counters.

decimal

Represents a variable-precision decimal.

double

Represents a 64-bit IEEE 754 floating point.

float

Represents a 32-bit IEEE 754 floating point.

int

Represents a 32-bit signed int.

varint

Represents an integer of arbitrary precision.

Counters

A counter column contains a 64-bit signed integer. The counter value is incremented or decremented using the UPDATE statement, and it cannot be set directly. This makes counter columns useful for tracking counts. For example, you can use counters to track the number of entries in a log file or the number of times a post has been viewed on a social network. The following restrictions apply to counter columns:

  • A column of type counter cannot be part of the primary key of a table.

  • In a table that contains one or more columns of type counter, all columns in that table must be of type counter.

In cases where a counter update fails, for example, due to timeouts or loss of connection with Amazon Keyspaces, the client doesn't know whether the counter value was updated. If the update is retried, the update to the counter value might get applied a second time.

Blob Type

Data Type Description

blob

Represents arbitrary bytes.

Boolean Type

Data Type Description

boolean

Represents true or false.

Time-Related Types

Data Type Description

timestamp

Represents a timestamp.

timeuuid

Represents a version 1 UUID.

Collection Types

Data Type Description

list

Represents an ordered collection of literal elements.

map

Represents an unordered collection of key-value pairs.

set

Represents an unordered collection of one or more literal elements.

tuple

Represents a bounded group of literal elements.

Other Types

Data Type Description

inet

A string representing an IP address, in either IPv4 or IPv6 format.