---
title: SQL map functions
description: Use map functions to create and operate on Arrow maps in SQL queries.
url: https://docs.influxdata.com/influxdb3/enterprise/reference/sql/functions/map/
estimated_tokens: 5018
product: InfluxDB 3 Enterprise
version: enterprise
---

# SQL map functions

Use map functions to create and operate on Arrow maps in SQL queries.

-   [element\_at](#element_at)
-   [make\_map](#make_map)
-   [map](#map)
-   [map\_extract](#map_extract)
-   [map\_keys](#map_keys)
-   [map\_values](#map_values)

## element\_at

*Alias of [map\_extract](#map_extract).*

## make\_map

Returns an Arrow map with the specified key and value.

```sql
make_map(key, value)
```

### Arguments

-   **key**: Expression to use for the key. Can be a constant, column, function, or any combination of arithmetic or string operators.
-   **value**: Expression to use for the value. Can be a constant, column, function, or any combination of arithmetic or string operators.

[](#view-make_map-query-example)

View `make_map` query example

*The following example uses the [Home sensor sample data](/influxdb3/enterprise/reference/sample-data/#home-sensor-data).*

```sql
SELECT
  make_map(room, temp) AS make_map
FROM
  home
LIMIT 4
```

| make_map |
| --- |
| {Kitchen: 22.4} |
| {Living Room: 22.2} |
| {Kitchen: 22.7} |
| {Living Room: 22.2} |

## map

Returns an Arrow map with the specified key-value pairs. Keys are mapped to values by their positions in each respective list. Each *key* must be unique and non-null.

```sql
map(key_list, value_list)
-- or
map { key: value, ... }
```

### Arguments

-   **key\_list**: List of keys to use in the map. Each key must be unique and non-null.
-   **value\_list**: List of values to map to the corresponding keys.

[](#view-map-query-example)

View `map` query example

```sql
SELECT
  map(
    [400, 401, 402, 403, 404],
    ['Bad Request', 'Unauthorized', 'Payment Required', 'Forbidden', 'Not Found']
  ) AS map
```

| map |
| --- |
| {400: Bad Request, 401: Unauthorized, 402: Payment Required, 403: Forbidden, 404: Not Found} |

[](#view-map-query-example-with-alternate-syntax)

View `map` query example with alternate syntax

```sql
SELECT
  map {
    400: 'Bad Request',
    401: 'Unauthorized',
    402: 'Payment Required',
    403: 'Forbidden',
    404: 'Not Found'
  } AS map
```

| map |
| --- |
| {400: Bad Request, 401: Unauthorized, 402: Payment Required, 403: Forbidden, 404: Not Found} |

## map\_extract

Returns a list containing the value for the given key or an empty list if the Returns a list containing the value for the given key, or an empty list if the key is not present in the map. The returned list will contain exactly one element (the value) when the key is found.

```sql
map_extract(map, key)
```

### Arguments

-   **map**: Map expression. Can be a constant, column, or function, and any combination of map operators.
-   **key**: Key to extract from the map. Can be a constant, column, or function, any combination of arithmetic or string operators, or a named expression of the previously listed.

#### Aliases

-   `element_at`

##### Related functions

[get\_field](/influxdb3/enterprise/reference/sql/functions/misc/#get_field)

[](#view-map_extract-query-example)

View `map_extract` query example

The following example uses the [NOAA Bay Area weather sample data](/influxdb3/enterprise/reference/sample-data/#noaa-bay-area-weather-data) to perform the a query that:

-   Defines a set of constants that includes a map that assigns integers to days of the week.
-   Queries the weather sample data and use `date_part` to extract an integer representing the day of the week of the row’s `time` value.
-   Uses `map_extract` and the output of `date_part` to return an array containing the name of the day of the week.
-   Uses bracket notation (`[i]`) to reference an element by index in the returned list (SQL arrays are 1-indexed, so `[1]` retrieves the first element).

```sql
WITH constants AS (
  SELECT map(
    [0, 1, 2, 3, 4, 5, 6],
    ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
  ) AS days_of_week
)
SELECT 
  weather.time,
  map_extract(c.days_of_week, date_part('dow', time))[1] AS day_of_week
FROM
  weather,
  constants AS c
ORDER BY
  weather.time
LIMIT 6
```

| time | day_of_week |
| --- | --- |
| 2020-01-01T00:00:00 | Wednesday |
| 2020-01-01T00:00:00 | Wednesday |
| 2020-01-01T00:00:00 | Wednesday |
| 2020-01-02T00:00:00 | Thursday |
| 2020-01-02T00:00:00 | Thursday |
| 2020-01-02T00:00:00 | Thursday |

## map\_keys

Returns a list of all keys in the map.

```sql
map_keys(map)
```

### Arguments

-   **map**: Map expression. Can be a constant, column, or function, and any combination of map operators.

##### Related functions

[get\_field](/influxdb3/enterprise/reference/sql/functions/misc/#get_field)

[](#view-map_keys-query-example)

View `map_keys` query example

```sql
SELECT map_keys(map {'a': 1, 'b': NULL, 'c': 3}) AS map_keys
```

| map_keys |
| --- |
| [a, b, c] |

## map\_values

Returns a list of all values in the map.

```sql
map_values(map)
```

### Arguments

-   **map**: Map expression. Can be a constant, column, or function, and any combination of map operators.

[](#view-map_values-query-example)

View `map_values` query example

```sql
SELECT map_values(map {'a': 1, 'b': NULL, 'c': 3}) AS map_values
```

| map_values |
| --- |
| [1, , 3] |
