STRUCT type

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Represents values with the structure described by a sequence of fields.

Syntax

STRUCT < [fieldName [:] fieldType [NOT NULL] [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 never NULL.

  • COMMENT str: An optional string literal describing the field.

Limits

The type supports any number of fields greater or equal to 0.

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>>