---
title: map function
description: Learn the syntax of the map function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/map
---

# `map` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Creates a map with the specified key-value pairs.

## Syntax

```
map( [key1, value1] [, ...] )
```

## Arguments

* `keyN`: An expression of any comparable type. All `keyN` must share a least common type.
* `valueN`: An expression of any type. All `valueN` must share a least common type.

## Returns

A MAP with keys typed as the least common type of `keyN` and values typed as the least common type of `valueN`.

There can be 0 or more pairs.

Databricks raises [DUPLICATED\_MAP\_KEY](https://docs.databricks.com/aws/en/error-messages/error-classes.md#duplicated_map_key) if any `keyN` values are duplicates.

Databricks raises [NULL\_MAP\_KEY](https://docs.databricks.com/aws/en/error-messages/error-classes.md#null_map_key) if any `keyN` is NULL.

## Common error conditions

* [DUPLICATED\_MAP\_KEY](https://docs.databricks.com/aws/en/error-messages/error-classes.md#duplicated_map_key)
* [NULL\_MAP\_KEY](https://docs.databricks.com/aws/en/error-messages/error-classes.md#null_map_key)

## Examples

```sql
> SELECT map(1.0, '2', 3.0, '4');
 {1.0 -> 2, 3.0 -> 4}

> SELECT map(1, 'a', 1, 'b');
  Error: DUPLICATED_MAP_KEY
```

## Related

* [\[ \] operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/bracketsign.md)
* [`map_concat` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_concat.md)
* [`map_entries` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_entries.md)
* [`map_filter` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_filter.md)
* [`map_from_arrays` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_from_arrays.md)
* [`map_from_entries` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_from_entries.md)
* [`map_keys` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_keys.md)
* [`map_values` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_values.md)
* [`map_zip_with` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_zip_with.md)
* [SQL data type rules](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datatype-rules.md)
