This section describes functions that operate on the VARIANT type.
New Most variant_* functions were introduced in DuckDB 2.0. The variant_extract, variant_normalize, and variant_typeof functions were already available in DuckDB 1.5.
Return a binary sort key (a BLOB) that orders a VARIANT value according to the logical ordering of VARIANT values. This is used internally so that VARIANTs compare and sort consistently with the corresponding native DuckDB types, rather than by their internal byte representation.
Example
variant_comparator({'a': 1, 'b': 2}::VARIANT)
Result
A BLOB sort key
Values are ordered first by type bucket (for example, booleans before numbers, numbers before strings) and then by value within a bucket, so that sorting a VARIANT column matches the order of the underlying values:
Return a canonical representation of a VARIANT value. Two VARIANT values that represent the same data normalize to the same result, regardless of how they were constructed or physically stored. This is useful when comparing or storing VARIANT values.
Aggregate function. Returns a VARIANT object containing all key, value pairs in the group, where key is a VARCHAR and value is a VARIANT. A NULL key or a duplicate key raises an error.
Example
variant_group_object('duck', 'goose'::VARIANT)
Result
{'duck': goose}
New The variant_group_object aggregate was added in DuckDB 2.0.
Collects all values of x into a VARIANT array, preserving order. Defined as a macro equivalent to list(x)::VARIANT, so it has aggregate semantics and also works as a window function. NULL values are kept as VARIANT nulls.
Example
variant_group_array(i)
Result
[0, 1, 2, 3]
New The variant_group_array function was added in DuckDB 2.0.