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

> Builds a map by pairing corresponding keys and values.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

Returns NULL if either array is NULL. NULL map keys raise an error; NULL values are allowed.

## Syntax

### Scalar

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

## Arguments

Type notation used below:

* K is the map key type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY or STRUCT.
* 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 |
| - | - | - | - |
| keys | ARRAY\<K> | Yes | The map keys. A lookup key must have the map's key type after conversion. Map keys must be non-NULL. |
| values | ARRAY\<V> | Yes | The map values; length must match keys. Nested values retain their declared element/field types. |

## Returns

* Type: MAP\<K,V>
* Possible values: The paired map entries.
* NULL behavior: Returns NULL if either array is NULL. NULL map keys raise an error; NULL values are allowed.
* Shape: One entry per distinct key.
* Ordering: Map entries are not sorted. Their order follows insertion and duplicate removal.

## Properties

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

## Usage notes

* Duplicate keys raise an error for Databricks source dialect; other dialects use the last value for a repeated key.
* NaN and signed zero keys are normalized for duplicate comparisons.
* For last-wins duplicate handling, the retained entries appear in the original order of the surviving last occurrences, without key sorting.
* 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_from_arrays(ARRAY['a', 'b'], ARRAY[1, 2]) AS "value";
```

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

### Duplicate keys, Databricks dialect

* Databricks dialect; duplicate-key errors enabled.

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

Expected error: Duplicate map key

## Limitations

* Arrays of different lengths or arrays containing NULL keys raise an execution error.


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