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

> Builds a map from an array of two-field structs.

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

Returns NULL for a NULL input array or when an input entry struct is NULL. NULL keys are invalid; NULL values are allowed.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
map_from_entries(entries)
```

## 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, MAP 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 |
| - | - | - | - |
| entries | ARRAY\<STRUCT\<key: K, value: V>> | Yes | The first field supplies the key and the second the value. A lookup key must have the map's key type after conversion. Map keys must be non-NULL. Nested values retain their declared element/field types. |

## Returns

* Type: MAP\<K,V>
* Possible values: The constructed map.
* NULL behavior: Returns NULL for a NULL input array or when an input entry struct is NULL. NULL keys are invalid; NULL values are allowed.
* Shape: One key/value entry per distinct key.
* Ordering: No sorted-map guarantee.

## Properties

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

## Usage notes

* For last-wins duplicate handling, the retained entries appear in the original order of the surviving last occurrences, without key sorting.
* If a key appears more than once, its last value is retained. This differs from MAP\_FROM\_ARRAYS in the Databricks context, which rejects duplicate keys.
* 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_entries(ARRAY[named_struct('key', 'a', 'value', 1)]) AS "value";
```

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

### Duplicate keys

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT map_from_entries(ARRAY[named_struct('key','a','value',1),named_struct('key','a','value',2)]) AS duplicates;
```

| duplicates |
| - |
| \[\["a",2]] |

## Limitations

* Each element must be a struct with exactly two fields. The first is the key and the second is the value, regardless of field names. NULL keys are rejected. Keys must support equality comparison and hashing.


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