STRUCT
type
Applies to: Databricks SQL Databricks Runtime
Represents values with the structure described by a sequence of fields.
Syntax
STRUCT < [fieldName [:] fieldType [NOT NULL] [COLLATE collationName] [COMMENT str] [, …] ] >
fieldName
: An identifier naming the field. The names need not be unique.fieldType
: Any data type.NOT NULL
: When specified, the struct guarantees that the value of this field is neverNULL
.COLLATE
collationName: This optionally specifies the collation to use for afieldType
ofSTRING
.If not specified, the collation is
UTF8_BINARY
.COMMENT str
: An optional string literal describing the field.
Literals
See struct function and named_struct function for details on how to produce literal array values.
Examples
> SELECT struct('Spark', 5);
{Spark, 5}
> SELECT typeof(named_struct('Field1', 'Spark', 'Field2', 5));
struct<Field1:string,Field2:int>
> SELECT typeof(struct('Spark', 5));
struct<col1:string,col2:int>
> SELECT typeof(CAST(NULL AS STRUCT<Field1:INT NOT NULL COMMENT 'The first field.',Field2:ARRAY<INT>>));
struct<Field1:int,Field2:array<int>>
> SELECT collation(cast(struct(‘hello’)) AS STRUCT<name STRING COLLATE UNICODE_CI>)
UNICODE_CI