named_struct

Description

Creates a struct with the specified field names and values.

Syntax

STRUCT named_struct({STRING name1, ANY val1} [, ...] )

Parameters

  • nameN: A STRING field.

  • valN: An expression of any type that specifies the value for field N. Values are nullable.

The expressions of names and values must be in pairs. Otherwise, the struct cannot be created. You must pass at least one pair of field name and value, separated by a comma (,).

Return value

Returns a STRUCT value.

Examples

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

SELECT named_struct('a', null, 'b', 2, 'c', 3);
+-----------------------------------------+
| named_struct('a', null, 'b', 2, 'c', 3) |
+-----------------------------------------+
| {"a":null,"b":2,"c":3}                  |
+-----------------------------------------+

References