JSON support

更新时间:
复制 MD 格式

Lindorm Cassandra Query Language (CQL) supports JSON in SELECT and INSERT statements. JSON support doesn't change the core API — you still define a schema for your database. It simply gives you a way to read and write column data as JSON.

SELECT JSON

Add the JSON keyword to a SELECT statement to return each row as a JSON-encoded map. The rest of the SELECT behavior stays the same.

The map keys match 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

Add the JSON keyword to an INSERT statement to insert a JSON-encoded map as a row. The JSON map format must match what SELECT JSON returns for the same table.

Wrap case-sensitive column names 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 omitted from the JSON map are set to NULL. This rule also applies when the default value NULL is explicitly specified, which means that all existing values of the unspecified columns are removed.

JSON encoding of CQL data types

The following table shows how Lindorm CQL maps CQL data types to and from JSON. It describes the data types accepted in INSERT JSON statements and fromJson() functions, and the data types returned for SELECT JSON statements and toJson() functions.

CQL typeAccepted JSON inputReturned JSON formatNotes
asciistringstringUses \u JSON escape sequences
bigintinteger, stringintegerString must be a valid 64-bit integer
blobstringstringString must be 0x followed by an even number of hexadecimal digits
booleanboolean, stringbooleanValid string values: "true" and "false"
datestringstringFormat: YYYY-MM-DD (UTC)
decimalinteger, float, stringfloatMay exceed 32-bit or 64-bit IEEE-754 floating-point precision
doubleinteger, float, stringfloatString must be a valid integer or floating-point number
floatinteger, float, stringfloatString must be a valid integer or floating-point number
inetstringstringIPv4 or IPv6 address
intinteger, stringintegerString must be a valid 32-bit integer
smallintinteger, stringintegerString must be a valid 16-bit integer
textstringstringUses \u JSON escape sequences
timestringstringFormat: HH-MM-SS[.fffffffff]
timestampinteger, stringstringString format: YYYY-MM-DD HH:MM:SS.SSS
timeuuidstringstringMust be a Type 1 UUID
tinyintinteger, stringintegerString must be a valid 8-bit integer
uuidstringstringStandard UUID format
varintinteger, stringintegerVariable-length integer. Integer overflow may occur when a 32-bit or 64-bit integer is passed to a client-side decoder