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 | 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 |
---|---|
|
Represents an ASCII character string. |
|
Represents a UTF-8 encoded string. |
|
Represents a UTF-8 encoded string ( |
Numeric types
Data type | Description |
---|---|
|
Represents a 64-bit signed long. |
|
Represents a 64-bit signed integer counter. For more information, see Counters. |
|
Represents a variable-precision decimal. |
|
Represents a 64-bit IEEE 754 floating point. |
|
Represents a 32-bit IEEE 754 floating point. |
|
Represents a 32-bit signed int. |
|
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 theprimary key
of a table. -
In a table that contains one or more columns of type
counter
, all columns in that table must be of typecounter
.
In cases where a counter update fails (for example, because of 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 |
---|---|
|
Represents arbitrary bytes. |
Boolean type
Data type | Description |
---|---|
|
Represents true or false . |
Time-related types
Data type | Description |
---|---|
|
64-bit signed integer representing the date and time since epoch (January 1 1970 at 00:00:00 GMT) in milliseconds. |
|
Represents a version 1 UUID |
Collection types
Data type | Description |
---|---|
|
Represents an ordered collection of literal elements. |
|
Represents an unordered collection of key-value pairs. |
|
Represents an unordered collection of one or more literal elements. |
|
Represents a bounded group of literal elements. |
Other types
Data type | Description |
---|---|
|
A string representing an IP address, in either IPv4 or IPv6 format. |
JSON encoding of Amazon Keyspaces data types
Amazon Keyspaces offers the same JSON data type mappings as Apache Cassandra.
The following table describes the data types Amazon Keyspaces accepts in INSERT JSON
statements and the data types Amazon Keyspaces uses when
returning data with the SELECT JSON
statement.
For single-field data types such as float
, int
, UUID
, and date
, you also can
insert data as a string
.
For compound data types and collections, such as tuple
, map
, and list
, you can also insert
data as JSON or as an encoded JSON string
.
JSON data type | Data types accepted in INSERT JSON statements |
Data types returned in SELECT JSON statements |
Notes |
---|---|---|---|
|
string |
string |
Uses JSON character escape |
|
integer, string |
integer |
String must be a valid 64-bit integer. |
|
string |
string |
String should begin with |
|
boolean, string |
boolean |
String must be either |
|
string |
string |
Date in format |
|
integer, float, string |
float |
Can exceed 32-bit or 64-bit IEEE-754 floating point precision in client-side decoder. |
|
integer, float, string |
float |
String must be a valid integer or float. |
|
integer, float, string |
float |
String must be a valid integer or float. |
|
string |
string |
IPv4 or IPv6 address. |
|
integer, string |
integer |
String must be a valid 32-bit integer. |
|
list, string |
list |
Uses the native JSON list representation. |
|
map, string |
map |
Uses the native JSON map representation. |
|
integer, string |
integer |
String must be a valid 16-bit integer. |
|
list, string |
list |
Uses the native JSON list representation. |
|
string |
string |
Uses JSON character escape |
|
string |
string |
Time of day in format |
|
integer, string |
string |
A timestamp. String constants allow you to store timestamps as dates. Date stamps with format
|
|
string |
string |
Type 1 UUID. See constants for the UUID format. |
|
integer, string |
integer |
String must be a valid 8-bit integer. |
|
list, string |
list |
Uses the native JSON list representation. |
|
string |
string |
See constants for the UUID format. |
|
string |
string |
Uses JSON character escape |
|
integer, string |
integer |
Variable length; might overflow 32-bit or 64-bit integers in client-side decoder. |