> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MAP

> Constructs a map from alternating keys and values, or from parallel arrays of keys and values.

Scalar function

NULL values are allowed. NULL keys raise an error.

## Syntax

### Scalar

Alternating key/value arguments:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
map(key, value, ...)
```

Parallel arrays:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
map(keys, values)
```

When both arguments are arrays, matching positions become key/value pairs. The arrays must have the same length.

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

| Name | Type | Required | Description |
| - | - | - | - |
| key | K | Yes | First key; additional key/value pairs may follow. 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. A lookup key must have the map's key type after conversion. Map keys must be non-NULL. For an array-valued key, use MAP\_FROM\_ARRAYS to avoid the two-array interpretation and the row-dependent array limitation below. This argument can repeat. |
| value | V | Yes | Corresponding value. Nested values retain their declared element/field types. For an array-valued value, use MAP\_FROM\_ARRAYS to avoid the two-array interpretation and the row-dependent array limitation below. This argument can repeat. |

For the parallel-array form:

| Name | Type | Required | Description |
| - | - | - | - |
| keys | ARRAY\<K> | Yes | Array of non-NULL, unique keys. K has the key types listed above. |
| values | ARRAY\<V> | Yes | Corresponding values. Must have the same length as keys. V has the value types listed above. |

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

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

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

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT map('a', 1, 'b', 2) AS "value";
```

| value |
| - |
| \[\["a",1],\["b",2]] |

Construct a map from parallel arrays:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT map(ARRAY['a', 'b'], ARRAY[1, 2]) AS result;
```

| result |
| - |
| \[\["a",1],\["b",2]] |

Use MAP\_FROM\_ARRAYS for array values that change by row:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH t AS (SELECT id FROM range(0, 2)) SELECT id, map_from_arrays(ARRAY['a'], ARRAY[ARRAY[id]]) AS result FROM t ORDER BY id;
```

| id | result |
| - | - |
| 0 | \[\["a",\[0]]] |
| 1 | \[\["a",\[1]]] |

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.