v.24.1New Feature

Implement Experimental Variant Data Type in ClickHouse

Implement Variant data type that represents a union of other data types. Type Variant(T1, T2, ..., TN) means that each row of this type has a value of either type T1 or T2 or ... or TN or none of them (NULL value). Variant type is available under a setting allow_experimental_variant_type. Reference: #54864. #58047 (Kruglov Pavel).
Variant data type has been implemented to represent a union of multiple data types. The type Variant(T1, T2, ..., TN) allows each row to hold a value of one of the specified types or a NULL value.

Why it matters

This feature addresses the need to store heterogeneous data within a single column by supporting multiple types under one unified data type. It enables more flexible schema designs and simplifies handling of mixed data without separate columns for each type.

How to use it

Enable the feature by setting the experimental setting allow_experimental_variant_type to 1. Then define columns using Variant(T1, T2, ..., TN) syntax, where T1, T2, ..., TN are the allowed data types.