Skip to main content

to_variant_object function

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

Convert a complex expression (ARRAY, MAP, STRUCT) into a VARIANT where maps and structs are converted to variant objects which are unordered. MAP can only have STRING keys.

Syntax

to_variant_object(expr)

Arguments

  • expr: A STRUCT, MAP<STRING, ...>, or ARRAY expression.

Returns

A VARIANT.

Examples

SQL
> SELECT to_variant_object(named_struct('a', 1, 'b', 2));
{"a":1,"b":2}

> SELECT to_variant_object(array(1, 2, 3));
[1,2,3]

> SELECT to_variant_object(array(named_struct('a', 1)));
[{"a":1}]

> SELECT to_variant_object(array(map("a", 2)));
[{"a":2}]