Lindorm Cassandra Query Language (CQL) supports JSON in SELECT and INSERT statements. However, JSON support does not fundamentally change the way that you use the Lindorm CQL API. For example, you must define a schema for your database. JSON support only provides a method to work with JSON documents. Lindorm CQL can be used to write or display the data of multiple columns in the JSON format.
SELECT JSON
You can specify the JSON keyword in a SELECT statement. In this case, the SELECT statement returns the data of each row as a JSON-encoded map. The remainder of the behavior for the SELECT statement remains unchanged.
The result map keys are the same as the column names in a regular result set. For
example, you can execute the SELECT JSON a, b FROM ...
statement to generate a map that contains the a
and b
keys.
INSERT JSON
You can specify the JSON keyword in an INSERT statement. In this case, the INSERT
statement is used to insert a JSON-encoded map as a row. In most cases, the format
of the JSON map must match the format of the result set that is returned by a SELECT
JSON statement executed on the same table. Take note that column names that are case-sensitive
must be enclosed in double quotation marks ("). For example, you can execute the following
statement to insert a map into a table that contains the key
and value
columns:
INSERT INTO persioninfo JSON '{ "c1": "key", "c2": "value"}'
By default, columns that are unspecified in a JSON map are set to NULL. This rule also applies when the default value NULL is explicitly specified. This means that all existing values of the unspecified columns are removed.
JSON Encoding of CQL Data Types
In some cases, Lindorm CQL represents and accepts data types in the native JSON format. Lindorm CQL also accepts string representations that match the literal format of Lindorm CQL for all single-field types. For example, float values, integers, UUIDs, and dates can be represented by Lindorm CQL literal strings.
JSON data type | Accepted data type | Returned data type | Description |
---|---|---|---|
ascii | string | string | The string for which the \u JSON escaping character is used.
|
bigint | integer, string | integer | The string must be a valid 64-bit integer. |
blob | string | string | The string must be an even number of hexadecimal digits that are prefixed with 0x. |
boolean | boolean, string | boolean | Valid values: true and false .
|
date | string | string | The string that contains a date in the YYYY-MM-DD format. The date is displayed in UTC.
|
decimal | integer, float, string | float | The precision may exceed that of a 32-bit or 64-bit IEEE-754 floating point number. |
double | integer, float, string | float | The string must be a valid integer or a floating-point number. |
float | integer, float, string | float | The string must be a valid integer or a floating-point number. |
inet | string | string | The IPv4 or IPv6 address. |
int | integer, string | integer | The string must be a 32-bit integer. |
smallint | integer, string | integer | The string must be a 16-bit integer. |
text | string | string | The string for which the \u JSON escaping character is used.
|
time | string | string | The string that contains a time in the HH-MM-SS[.fffffffff] format.
|
timestamp | integer, string | string | The timestamp. The string can contain a timestamp in the YYYY-MM-DD HH:MM:SS.SSS format.
|
timeuuid | string | string | The Type 1 UUID. |
tinyint | integer, string | integer | The string must be a valid 8-bit integer. |
uuid | string | string | The string in the UUID format. |
varint | integer, string | integer | The integer whose length is variable. An integer overflow may occur when a 32-bit or 64-bit integer is transferred to a client-side decoder. |