Syntax
Scalar
Alternating key/value arguments:Arguments
Type notation used below:- V is the map value type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT.
For the parallel-array form:
Returns
- Type: MAP<K,V>
- Possible values: The specified key/value pairs.
- NULL behavior: NULL values are allowed. NULL keys raise an error.
- Shape: One entry per unique key. K is the map key type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT.
- Ordering: Construction order without a sorted-map guarantee.
Properties
Usage notes
- Supply at least one key/value pair, with an even total number of arguments. All keys must have compatible types, as must all values. Use explicit casts for mixed types.
- With exactly two ARRAY arguments, corresponding elements become keys and values. With four or more arguments, each argument is one key or value; constant arrays can be used in this form. Calls with array-valued keys or values that change by row can currently fail in either form. Use MAP_FROM_ARRAYS for those inputs.
- INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
Examples
Typical behavior
Construct a map from parallel arrays:
Use MAP_FROM_ARRAYS for array values that change by row:
Limitations
- Requires even argument count; keys must be non-NULL and unique.
- MAP() without arguments is not supported. For two ARRAY inputs, query tools may report ARRAY key/value types even though the resulting map contains the arrays’ elements. MAP_FROM_ARRAYS makes the key-array/value-array interpretation explicit.
- Do not use row-dependent ARRAY keys or values with MAP. These calls can fail during execution; use MAP_FROM_ARRAYS as shown above.
- Duplicate keys raise an error rather than applying MAP_FROM_ARRAYS/MAP_FROM_ENTRIES last-wins behavior. NULL map values are permitted; a NULL key raises an error.