Skip to main content

VARIANT type

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 15.3 and above

Preview

This feature is in Public Preview.

Represents semi-structured data.

note

Iceberg v2 tables do not support VARIANT columns. Apache Iceberg v3 supports VARIANT columns. See Use Apache Iceberg v3 features.

Syntax

VARIANT

Limits

The type supports storing any semi-structured data, including STRUCT, ARRAY, MAP, and scalar types. VARIANT can only store MAP types with keys of type STRING.

Literals

See parse_json function function for details on creating a VARIANT value. You can also use the CAST function to convert a literal of some type to VARIANT.

Notes

Examples

SQL
> SELECT parse_json('{"key": 123, "data": [4, 5, "str"]}');
{"data":[4,5,"str"],"key":123}

> SELECT parse_json(null);
null

> SELECT parse_json('123');
123

> SELECT CAST(123.456 AS VARIANT);
123.456