Primitive data types

The terms “simple”, “primitive”, and “elementary” data types are used synonymously.

Numeric types

TypeDescriptionNotes
BoolBoolean value.
Int8A signed integer.
Acceptable values: from -27 to 27–1.
Not supported for table columns
Int16A signed integer.
Acceptable values: from –215 to 215–1.
Not supported for table columns
Int32A signed integer.
Acceptable values: from –231 to 231–1.
Int64A signed integer.
Acceptable values: from –263 to 263–1.
Uint8An unsigned integer.
Acceptable values: from 0 to 28–1.
Uint16An unsigned integer.
Acceptable values: from 0 to 216–1.
Not supported for table columns
Uint32An unsigned integer.
Acceptable values: from 0 to 232–1.
Uint64An unsigned integer.
Acceptable values: from 0 to 264–1.
FloatA real number with variable precision, 4 bytes in size.Can’t be used in the primary key
DoubleA real number with variable precision, 8 bytes in size.Can’t be used in the primary key
DecimalA real number with the specified precision, up to 35 decimal digitsWhen used in table columns, precision is fixed: Decimal (22,9).
Can’t be used in the primary key

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. |

String types

TypeDescriptionNotes
StringA string that can contain any binary data
Utf8Text encoded in UTF-8
JsonJSON represented as textDoesn’t support matching, can’t be used in the primary key
JsonDocumentJSON in an indexed binary representationDoesn’t support matching, can’t be used in the primary key
YsonYSON in a textual or binary representation.Doesn’t support matching, can’t be used in the primary key
UuidUniversally unique identifier UUIDNot 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 JsonDocument queries can be up to several times more efficient depending on the type of load.

Due to the added redundancy, JsonDocument is less effective in storage. The additional storage overhead depends on the specific content, but is 20-30% of the original volume on average. Saving data in JsonDocument format requires additional conversion from the textual representation, which makes writing it less efficient. However, for most read-intensive scenarios that involve processing data from JSON, this data type is preferred and recommended.

Warning

To store numbers (JSON Number) in JsonDocument, as well as for arithmetic operations on them in the JSON API, the Double type is used. Precision might be lost when non-standard representations of numbers are used in the source JSON document.

Date and time

TypeDescriptionNotes
DateDate, precision to the dayRange of values for all time types except Interval: From 00:00 01.01.1970 to 00:00 01.01.2106. Internal Date representation: Unsigned 16-bit integer
DatetimeDate/time, precision to the secondInternal representation: Unsigned 32-bit integer
TimestampDate/time, precision to the microsecondInternal representation: Unsigned 64-bit integer
IntervalTime interval (signed), precision to microsecondsValue range: From -136 years to +136 years. Internal representation: Signed 64-bit integer. Can’t be used in the primary key
TzDateDate with time zone label, precision to the dayNot supported in table columns
TzDateTimeDate/time with time zone label, precision to the secondNot supported in table columns
TzTimestampDate/time with time zone label, precision to the microsecondNot supported in table columns

Supporting types with a time zone label

Time zone label for the TzDate, TzDatetime, TzTimestamp types is an attribute that is used:

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:

  1. select --these expressions are always true for any timezones: the timezone doesn't affect the point in time.
  2. AddTimezone(CurrentUtcDate(), "Europe/Moscow") ==
  3. AddTimezone(CurrentUtcDate(), "America/New_York"),
  4. AddTimezone(CurrentUtcDatetime(), "Europe/Moscow") ==
  5. AddTimezone(CurrentUtcDatetime(), "America/New_York");

Simple - 图1

Keep in mind that when converting between TzDate and TzDatetime, or TzTimestamp the date’s midnight doesn’t follow the local time zone, but midnight in UTC for the date in UTC.

Casting between data types

Explicit casting

Explicit casting using CAST:

Casting to numeric types

TypeBoolIntUintFloatDoubleDecimal
BoolYes1Yes1Yes1Yes1No
INTYes2Yes3YesYesYes
UintYes2YesYesYesYes
FloatYes2YesYesYesNo
DoubleYes2YesYesYesNo
DecimalNoYesYesYesYes
StringYesYesYesYesYesYes
Utf8YesYesYesYesYesYes
JsonNoNoNoNoNoNo
YsonYes4Yes4Yes4Yes4Yes4Yes4
UuidNoNoNoNoNoNo
DateNoYesYesYesYesNo
DatetimeNoYesYesYesYesNo
TimestampNoYesYesYesYesNo
IntervalNoYesYesYesYesNo

1 True is converted to 1 and False to 0.
2 Any value other than 0 is converted to True, 0 is converted to False.
3 Possible only in the case of a non-negative value.
4 Using the built-in function Yson::ConvertTo.

Converting to date and time data types

TypeDateDatetimeTimestampInterval
BoolNoNoNoNo
INTYesYesYesYes
UintYesYesYesYes
FloatNoNoNoNo
DoubleNoNoNoNo
DecimalNoNoNoNo
StringYesYesYesYes
Utf8YesYesYesYes
JsonNoNoNoNo
YsonNoNoNoNo
UuidNoNoNoNo
DateYesYesNo
DatetimeYesYesNo
TimestampYesYesNo
IntervalNoNoNo

Conversion to other data types

TypeStringUtf8JsonYsonUuid
BoolYesNoNoNoNo
INTYesNoNoNoNo
UintYesNoNoNoNo
FloatYesNoNoNoNo
DoubleYesNoNoNoNo
DecimalYesNoNoNoNo
StringYesYesYesYes
Utf8YesNoNoNo
JsonYesYesNoNo
YsonYes4NoNoNoNo
UuidYesYesNoNo
DateYesYesNoNoNo
DatetimeYesYesNoNoNo
TimestampYesYesNoNoNo
IntervalYesYesNoNoNo

4 Using the built-in function Yson::ConvertTo.

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

Implicit casting

Implicit type casting that occurs in basic operations ( +-*/) between different data types. The table cells specify the operation result type, if the operation is possible:

Numeric types

TypeIntUintFloatDouble
INTINTFloatDouble
UintINTFloatDouble
FloatFloatFloatDouble
DoubleDoubleDoubleDouble

Date and time types

TypeDateDatetimeTimestampIntervalTzDateTzDatetimeTzTimestamp
DateDate
DatetimeDatetime
TimestampTimestamp
IntervalDateDatetimeTimestampTzDateTzDatetimeTzTimestamp
TzDateTzDate
TzDatetimeTzDatetime
TzTimestampTzTimestamp