Was this page helpful?
Caution
You're viewing documentation for a previous version of ScyllaDB Open Source. Switch to the latest stable version.
Added in version 2.3.
Scylla introduces JSON support to SELECT and INSERT statements. This support does not fundamentally alter the CQL API (for example, the schema is still enforced). It simply provides a convenient way to work with JSON documents.
With SELECT
statements, the JSON
keyword can be used to return each row as a single JSON
encoded map. The
remainder of the SELECT
statement behavior is the same.
The result map keys are the same as the column names in a normal result set. For example, a statement like SELECT JSON
a, ttl(b) FROM ...
would result in a map with keys "a"
and "ttl(b)"
. However, this is one notable exception:
for symmetry with INSERT JSON
behavior, case-sensitive column names with upper-case letters will be surrounded with
double-quotes. For example, SELECT JSON myColumn FROM ...
would result in a map key "\"myColumn\""
(note the
escaped quotes).
The map values will JSON
-encoded representations (as described below) of the result set values.
With INSERT
statements, the new JSON
keyword can be used to enable inserting a JSON
encoded map as a single
row. The format of the JSON
map should generally match that returned by a SELECT JSON
statement on the same
table. In particular, case-sensitive column names should be surrounded by double-quotes. For example, to insert into a
table with two columns named “myKey” and “value”, you would do the following:
INSERT INTO mytable JSON '{ "\"myKey\"": 0, "value": 0}'
By default (or if DEFAULT NULL
is explicitly used), a column omitted from the JSON
map will be set to NULL
,
meaning that any pre-existing value for that column will be removed (resulting in a tombstone being created).
Alternatively, if the DEFAULT UNSET
directive is used after the value, omitted column values will be left unset,
meaning that pre-existing values for those columns will be preserved.
Where possible, Scylla will represent and accept data types in their native JSON
representation. Scylla will
also accept string representations matching the CQL literal format for all single-field types. For example, floats,
ints, UUIDs, and dates can be represented by CQL literal strings. However, compound types, such as collections, tuples,
and user-defined types, must be represented by native JSON
collections (maps and lists) or a JSON-encoded string
representation of the collection.
The following table describes the encodings that Scylla will accept in INSERT JSON
values (and fromJson()
arguments) as well as the format Scylla will use when returning data for SELECT JSON
statements (and
fromJson()
):
Type |
Formats accepted |
Return format |
Notes |
---|---|---|---|
|
string |
string |
Uses JSON’s |
|
integer, string |
integer |
String must be valid 64 bit integer |
|
string |
string |
String should be 0x followed by an even number of hex digits |
|
boolean, string |
boolean |
String must be “true” or “false” |
|
string |
string |
Date in format |
|
integer, float, string |
float |
May exceed 32 or 64-bit IEEE-754 floating point precision in client-side decoder |
|
integer, float, string |
float |
String must be valid integer or float |
|
integer, float, string |
float |
String must be valid integer or float |
|
string |
string |
IPv4 or IPv6 address |
|
integer, string |
integer |
String must be valid 32 bit integer |
|
list, string |
list |
Uses JSON’s native list representation |
|
map, string |
map |
Uses JSON’s native map representation |
|
integer, string |
integer |
String must be valid 16 bit integer |
|
list, string |
list |
Uses JSON’s native list representation |
|
string |
string |
Uses JSON’s |
|
string |
string |
Time of day in format |
|
integer, string |
string |
A timestamp. Strings constant allows to input timestamps
as dates. Datestamps with format |
|
string |
string |
Type 1 UUID. See |
|
integer, string |
integer |
String must be valid 8 bit integer |
|
list, string |
list |
Uses JSON’s native list representation |
|
map, string |
map |
Uses JSON’s native map representation with field names as keys |
|
string |
string |
See |
|
string |
string |
Uses JSON’s |
|
integer, string |
integer |
Variable length; may overflow 32 or 64 bit integers in client-side decoder |
The fromJson()
function may be used similarly to INSERT JSON
, but for a single column value. It may only be used
in the VALUES
clause of an INSERT
statement or as one of the column values in an UPDATE
, DELETE
, or
SELECT
statement. For example, it cannot be used in the selection clause of a SELECT
statement.
The toJson()
function may be used similarly to SELECT JSON
, but for a single column value. It may only be used
in the selection clause of a SELECT
statement.
Copyright
© 2016, The Apache Software Foundation.
Apache®, Apache Cassandra®, Cassandra®, the Apache feather logo and the Apache Cassandra® Eye logo are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.
Was this page helpful?