Creates a STRUCT value from specified values.
Syntax
struct(<value1>[, <value2>, ...])Parameters
| Parameter | Required | Description |
|---|---|---|
| *value* | Yes | A value of any data type. Specify one or more values, separated by commas. |
Return value
Returns a STRUCT value. Fields are named col1, col2, col3, and so on, matching the order of input values.
Examples
Basic usage
Create a STRUCT from values of different data types:
SELECT struct('a', 123, 'true', 56.90);Output:
{col1:a, col2:123, col3:true, col4:56.9}Each value maps to an auto-named field:
| Input value | Field | Result |
|---|---|---|
'a' (STRING) | col1 | a |
123 (INT) | col2 | 123 |
'true' (STRING) | col3 | true |
56.90 (DOUBLE) | col4 | 56.9 |
Two-value STRUCT
SELECT struct(100, 'MaxCompute');Output:
{col1:100, col2:MaxCompute}Use with table data
SELECT struct(name, age) FROM employees;Each row produces a STRUCT with fields col1 and col2 derived from the name and age columns.
Usage notes
Values of different data types can be mixed in a single call.
Fields are named automatically. Reference individual fields by their generated name, such as
col1.
Related functions
STRUCT is a complex type function. For other functions that process ARRAY, MAP, STRUCT, and JSON data types, see Complex type functions.