Primitive data types
DyNumber
| A binary representation of a real number with an accuracy of up to 38 digits.
Acceptable values: positive numbers from 1×10-130 up to 1×10126–1, negative numbers from -1×10126–1 to -1×10-130, and 0.
Compatible with the Number
type in AWS DynamoDB. It’s not recommended for ydb-native applications. |
Type | Description | Notes |
---|---|---|
String | A string that can contain any binary data | |
Utf8 | Text encoded in | |
Json | JSON represented as text | Doesn’t support matching, can’t be used in the primary key |
JsonDocument | in an indexed binary representation | Doesn’t support matching, can’t be used in the primary key |
Yson | YSON in a textual or binary representation. | Doesn’t support matching, can’t be used in the primary key |
Uuid | Universally unique identifier | Not supported for table columns |
Cell size restrictions
The maximum value size for a non-key column cell with any string data type is 8 MB.
Unlike the JSON
data type that stores the original text representation passed by the user, JsonDocument
uses an indexed binary representation. An important difference from the point of view of semantics is that JsonDocument
doesn’t preserve formatting, the order of keys in objects, or their duplicates.
Thanks to the indexed view, JsonDocument
lets you bypass the document model using JsonPath
without the need to parse the full content. This helps efficiently perform operations from the JSON API, reducing delays and cost of user queries. Execution of queries can be up to several times more efficient depending on the type of load.
Warning
To store numbers (JSON Number) in JsonDocument
, as well as for arithmetic operations on them in the , the Double type is used. Precision might be lost when non-standard representations of numbers are used in the source JSON document.
Time zone label for the TzDate
, TzDatetime
, TzTimestamp
types is an attribute that is used:
- In , a timezone component is added to
Resource<TM>
.
The point in time for these types is stored in UTC, and the timezone label doesn’t participate in any other calculations in any way. For example:
Casting between data types
Explicit casting using :
Casting to numeric types
Type | Bool | Int | Uint | Float | Double | Decimal |
---|---|---|---|---|---|---|
Bool | — | Yes1 | Yes1 | Yes1 | Yes1 | No |
INT | Yes2 | — | Yes3 | Yes | Yes | Yes |
Uint | Yes2 | Yes | — | Yes | Yes | Yes |
Float | Yes2 | Yes | Yes | — | Yes | No |
Double | Yes2 | Yes | Yes | Yes | — | No |
Decimal | No | Yes | Yes | Yes | Yes | — |
String | Yes | Yes | Yes | Yes | Yes | Yes |
Utf8 | Yes | Yes | Yes | Yes | Yes | Yes |
Json | No | No | No | No | No | No |
Yson | Yes4 | Yes4 | Yes4 | Yes4 | Yes4 | Yes4 |
Uuid | No | No | No | No | No | No |
Date | No | Yes | Yes | Yes | Yes | No |
Datetime | No | Yes | Yes | Yes | Yes | No |
Timestamp | No | Yes | Yes | Yes | Yes | No |
Interval | No | Yes | Yes | Yes | Yes | No |
1 True
is converted to 1
and False
to 0
.
2 Any value other than 0
is converted to , 0
is converted to False
.
3 Possible only in the case of a non-negative value.
4 Using the built-in function .
Conversion to other data types
Type | String | Utf8 | Json | Yson | Uuid |
---|---|---|---|---|---|
Bool | Yes | No | No | No | No |
INT | Yes | No | No | No | No |
Uint | Yes | No | No | No | No |
Float | Yes | No | No | No | No |
Double | Yes | No | No | No | No |
Decimal | Yes | No | No | No | No |
String | — | Yes | Yes | Yes | Yes |
Utf8 | Yes | — | No | No | No |
Json | Yes | Yes | — | No | No |
Yson | Yes4 | No | No | No | No |
Uuid | Yes | Yes | No | No | — |
Date | Yes | Yes | No | No | No |
Datetime | Yes | Yes | No | No | No |
Timestamp | Yes | Yes | No | No | No |
Interval | Yes | Yes | No | No | No |
4 Using the built-in function .
Examples
SELECT
CAST(“12345” AS Double), — 12345.0
CAST(1.2345 AS Uint8), — 1
CAST(12345 AS String), — “12345”
CAST(“1.2345” AS Decimal(5, 2)), — 1.23
CAST(“xyz” AS Uint64) IS NULL, — true, because it failed
CAST(-1 AS Uint16) IS NULL, — true, a negative integer cast to an unsigned integer
CAST([-1, 0, 1] AS List<Uint8?>), — [null, 0, 1]
--The item type is optional: the failed item is cast to null.
CAST([“3.14”, “bad”, “42”] AS List), — [3.14, 42]
--The item type is not optional: the failed item has been deleted.
CAST(255 AS Uint8), — 255
CAST(256 AS Uint8) IS NULL — true, out of range
Date and time types
Type | Date | Datetime | Timestamp | Interval | TzDate | TzDatetime | TzTimestamp |
---|---|---|---|---|---|---|---|
Date | — | — | — | Date | — | — | — |
Datetime | — | — | — | Datetime | — | — | — |
Timestamp | — | — | — | Timestamp | — | — | — |
Interval | Date | Datetime | Timestamp | — | TzDate | TzDatetime | TzTimestamp |
TzDate | — | — | — | TzDate | — | — | — |
TzDatetime | — | — | — | — | — | — | |
TzTimestamp | — | — | — | TzTimestamp | — | — | — |