Skip to main content

Variant type

The variant data type can store any type of value and contains metadata about the value's data type so the database and application can easily use the data.

The variant data type uses a JSON object to represent any value. This JSON object is called the variant object. Any system can read the variant object and know how to convert it into a native binary value.

For example, you could embed a 7z-compressed JPEG image in a variant object. Any system reading the variant object will know that the variant object contains a JPEG image compressed using the 7z protocol. The system can easily decode the variant to create the native binary format of the JPEG image.

Variant's behavior in different APIs

CTDB and ISAM

In CTDB and ISAM, a variant field returns a structure representing key information about the variant including its length, value, and type.

SQL

In SQL, a field that has a variant type is set and returned using the Variant Object, which is a JSON object.

There are two forms of JSON that represent a variant:

  • JSON stored in a variant

  • Variant Object