Creates a STRUCT value with named fields from alternating name-value pairs.
Syntax
struct named_struct(string <name1>, T1 <value1>, string <name2>, T2 <value2>[, ...])Parameters alternate in name, value, name, value, ... order. Each name is a STRING constant that becomes the field name; each value can be any data type.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | STRING | Yes | Field name for the struct. Must be a constant, not a variable. |
value | Any | Yes | Value assigned to the preceding field name. |
Return value
Returns a value of the STRUCT type. Fields are named sequentially as name1, name2, ... in the order provided.
Examples
Basic usage
-- Returns {user_id:10001, user_name:LiLei, married:F, weight:63.5}
SELECT named_struct('user_id', 10001, 'user_name', 'LiLei', 'married', 'F', 'weight', 63.50);Related functions
NAMED_STRUCT is a complex type function. For more information about functions that process complex data types such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.