FIELD

Updated at:

Retrieves the value of a member variable from a STRUCT object.

Command format

T field(struct <s>, string <fieldName>)

Parameters

  • s: Required. A STRUCT object. The structure of the STRUCT is {f1,T1, f2,T2[, ...]}. f1 and f2 are member variables. T1 and T2 are the values of the member variables f1 and f2, respectively.

  • fieldName: Required. A STRING value that specifies the name of the member variable.

Return value

Returns the value of the specified member variable.

Example

-- Returns hello.
select field(named_struct('f1', 'hello', 'f2', 3), 'f1');

Related functions

The FIELD function is a complex type function. For more functions that process complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.