named_struct function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Creates a struct with the specified field names and values.

Syntax

named_struct( {name1, val1} [, ...] )

Arguments

  • nameN: A STRING literal naming field N.

  • valN: An expression of any type specifying the value for field N.

Returns

A struct with field N matching the type of valN.

Examples

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