MAP type

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

Represents values comprising a set of key-value pairs.

Syntax

MAP <keyType, valueType>
  • keyType: Any data type other than MAP specifying the keys.

  • valueType: Any data type specifying the values.

Limits

The map type supports maps of any cardinality greater or equal to 0.

The keys must be unique and not be NULL.

MAP is not a comparable data type.

Literals

See map function for details on how to produce literal map values.

See [ ] operator for details on how to retrieve values from a map by key.

Examples

> SELECT map('red', 1, 'green', 2);
  {red->1, green->2}

> SELECT typeof(CAST(NULL AS MAP<TIMESTAMP, INT>));
  MAP<TIMESTAMP, INT>

> SELECT map(array(1, 2), map('green', 5));
  {[1, 2]->{green->5}}

> SELECT CAST(map(struct('Hello', 'World'), 'Greeting') AS MAP<STRUCT<w1:string, w2:string>, string>);
  {{Hello, World}->Greeting}

> SELECT m['red'] FROM VALUES(map('red', 1, 'green', 2)) AS T(m);
  1

> SELECT map('red', 1) = map('red', 1);
  Error: EqualTo does not support ordering on type map<string,int>