Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Database
  • Getting started
    • Overview
    • Create databases
    • Examples of YQL queries
    • Examples of operations in the YDB CLI
    • Launch a test app
    • Document API
    • Developing in NodeJS through the Document API
  • Step-by-step instructions
    • Database management
    • How to connect to a database
    • Table management
    • Reading and writing data
    • Working with secondary indexes
  • Working with the SDK
  • Concepts
    • Overview
    • Data model and schema
    • Serverless and Dedicated operation modes
    • Data types
    • Transactions
    • Secondary indexes
    • Time to Live (TTL)
    • Terms and definitions
    • Quotas and limits
  • Access management
  • Pricing policy
    • Overview
    • Serverless mode
    • Dedicated mode
  • Recommendations
    • Schema design
    • Partitioning tables
    • Secondary indexes
    • Paginated output
    • Loading large data volumes
    • Using timeouts
  • YDB API and API reference
    • Database limits
    • Handling errors in the API
  • Amazon DynamoDB-compatible HTTP API
    • API reference
      • All methods
      • Actions
        • BatchGetItem
        • BatchWriteItem
        • CreateTable
        • DeleteItem
        • DeleteTable
        • DescribeTable
        • GetItem
        • ListTables
        • PutItem
        • Query
        • Scan
        • TransactGetItems
        • TransactWriteItems
        • UpdateItem
      • Common errors
  • YQL reference guide
    • Overview
    • Data types
      • Simple
      • Optional
      • Containers
      • Special
    • Syntax
      • Unsupported statements
      • For text representation of data types
      • Expressions
      • CREATE TABLE
      • DROP TABLE
      • INSERT INTO
      • UPSERT INTO
      • REPLACE INTO
      • UPDATE
      • DELETE
      • SELECT
      • GROUP BY
      • JOIN
      • FLATTEN
      • ACTION
      • DISCARD
      • PRAGMA
      • DECLARE
      • OVER, PARTITION BY, and WINDOW
    • Built-in functions
      • Basic
      • Aggregate
      • Window
      • For lists
      • For dictionaries
      • For JSON
      • For structures
      • For types
    • Preset user-defined functions
      • HyperScan
      • Pcre
      • Pire
      • Re2
      • String
      • Unicode
      • Datetime
      • Url
      • Ip
      • Digest
      • Math
      • Histogram
    • For text representation of data types
  • YQL tutorial
    • Overview
    • Creating a table
    • Adding data to a table
    • Selecting data from all columns
    • Selecting data from specific columns
    • Sorting and filtering
    • Data aggregation
    • Additional selection criteria
    • Joining tables by JOIN
    • Data insert and update by REPLACE
    • Data insert and update by UPSERT
    • Data insert by INSERT
    • Data update by UPDATE
    • Deleting data
    • Adding and deleting columns
    • Deleting a table
  • Maintenance
    • Backups
  • Diagnostics
    • System views
  • Questions and answers
    • General questions
    • Errors
    • YQL
    • All questions on the same page
  • Public materials
  1. Concepts
  2. Data types

Data types

  • Supported data types
  • Numeric data types
  • String data types
  • Date and time
  • Optional values (types that allow NULL)
  • Containers

This section describes the data types that YDB supports.

Supported data types

YDB uses YQL data types. Some YQL types have limited support: they can only be used in calculations, but can't function as column types or be used in the primary key. All columns, including key columns, may contain a special NULL value.

Значения NULL в ячейках первичного ключа

Although it's possible to have composite primary key values in which some field values store NULL, we strongly recommend that you never do that and never store NULL in a primary key.

Tables 1,2, and 3 show possible ways to use YQL data types in YDB.

Numeric data types

Table 1. Possible ways to use numeric YQL data types in YDB

Type Explanation Used
in queries
and YQL calculations
Used
as the
column
data type
Used in
primary
keys
Supports the
comparison
option
Bool standard Boolean type, true or false Yes Yes Yes Yes
Int8 Signed integer, from -27 to 27 − 1 Yes No No Yes
Int16 Signed integer, from -215 to 215 − 1 Yes No No Yes
Int32 Signed integer, from -231 to 231 − 1 Yes Yes Yes Yes
Int64 Signed integer, from -263 to 263 − 1 Yes Yes Yes Yes
Uint8 Unsigned integer, from 0 to 28 − 1 Yes Yes Yes Yes
Uint16 Unsigned integer, from 0 to 216 − 1 Yes No No Yes
Uint32 Unsigned integer, from 0 to 232 − 1 Yes Yes Yes Yes
Uint64 Unsigned integer, from 0 to 264 − 1 Yes Yes Yes Yes
Float Real 4-byte number Yes Yes No Yes
Double Real 8-byte number Yes Yes No Yes
Decimal Fixed precision number, currently Decimal(22,9) is supported — 13 integer digits, 9 fractional digits Yes Yes No Yes
DyNumber A binary representation of a floating-point number that preserves order Yes Yes Yes Yes

String data types

Table 2. Possible ways to use YQL string data types in YDB

Type Explanation Used
in queries
and YQL calculations
Used
as the
column
data type
Used in
primary
keys
Supports the
comparison
option
String An arbitrary sequence of bytes Yes Yes Yes Yes
Utf8 Text encoded in UTF-8 Yes Yes Yes Yes
Json Valid JSON represented as text Yes Yes No No
JsonDocument Valid JSON in an indexed binary representation Yes Yes No No
Uuid A universally unique identifier UUID Yes No No Yes

Ограничения на размер

The maximum value size in a cell with any string data type is about 4 MB.

Отличия Json и JsonDocument

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 the 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. Moreover, saving data in JsonDocument format requires additional conversion from text, which makes writing it somewhat less efficient. However, for most read-intensive scenarios that involve processing data from JSON, the new data type is preferred and recommended.

Date and time

Table 3. Possible ways to use date and time YQL data types in YDB

Type Explanation Used
in queries
and YQL calculations
Used
as the
column
data type
Used in
primary
keys
Supports the
comparison
option
Date Precision to the day Yes Yes Yes Yes
Datetime Precision to the second Yes Yes Yes Yes
Timestamp Precision to the microsecond Yes Yes Yes Yes
Interval Precision to the microsecond, valid interval values must not exceed 24 hours Yes Yes No Yes

Optional values (types that allow NULL)

Any typed data in YQL, including table columns, can be either non-nullable (guaranteed value) or nullable (empty value denoted as NULL). These values are called "optional" (or "nullable", in SQL terms).

The most common operation for such data types is COALESCE, which lets you leave filled values unchanged while replacing NULL with the following default value.

When you declare such data types in text format, use the question mark at the end (for example, String?) or the notation Optional<...>.

Containers

Table 4. Composite YQL data types

Name Type declaration Type example Explanation
List List<Type> List<Int32> A variable-length sequence consisting of same-type elements.
Dictionary Dict<KeyType, ValueType> Dict<String, Int32> Set of key-value pairs with a fixed type of keys and values.
Tuple Tuple<Type1, ..., TypeN> Tuple<Int32, Double> Set of unnamed fixed-length elements with types specified for all elements.
Structure Struct<Name1:Type1, ..., NameN:TypeN> Struct<Name:String, Age:Int32> A set of named fields with specified value types, fixed at query start (must be data-independent).
Stream Stream<Type> Stream<Int32> Single-pass iterator by same-type values, not serializable
Variant on tuple Variant<Type1, Type2> Variant<Int32, String> A tuple known to have exactly one element filled
Variant on structure Variant<Name1:Type1, Name2:Type2> Variant<value:Int32, error:String> A structure known to have exactly one element filled

If necessary, you can nest containers in any combination, for example, List<Tuple<Int32, Int32>> (a list containing tuples as elements).

In certain contexts, optional values can also be considered a container type (Optional<Type>) that behaves like a list of length 0 or 1.

To implement sets, use a dictionary with Void - Dict<T, Void> type values.

In this article:
  • Supported data types
  • Numeric data types
  • String data types
  • Date and time
  • Optional values (types that allow NULL)
  • Containers
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC