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

# `str_to_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 after splitting the input into key-value pairs using delimiters.

## Syntax

```
str_to_map(expr [, pairDelim [, keyValueDelim] ] )
```

## Arguments

* `expr`: An `STRING` expression.
* `pairDelim`: An optional `STRING` literal defaulting to `','` that specifies how to split entries.
* `keyValueDelim`: An optional `STRING` literal defaulting to `':'` that specifies how to split each key-value pair.

## Returns

A `MAP` of `STRING` for both keys and values.

Both `pairDelim` and `keyValueDelim` are treated as regular expressions.

Databricks raises [DUPLICATED\_MAP\_KEY](https://docs.databricks.com/aws/en/error-messages/error-classes.md#duplicated_map_key) if the input produces duplicate keys.

## Common error conditions

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

## Examples

```sql
> SELECT str_to_map('a:1,b:2,c:3', ',', ':');
 {a -> 1, b -> 2, c -> 3}

> SELECT str_to_map('a');
 {a-> NULL}

> SELECT str_to_map('5A10B6A20' COLLATE UTF8_BINARY, 'b', 'a');
 {5A10B6A20 -> NULL}

> SELECT str_to_map('5A10B6A20' COLLATE UTF8_LCASE, 'b', 'a');
 {5 -> 10, 6 -> 20}

> SELECT str_to_map('a:1,a:2');
  Error: DUPLICATED_MAP_KEY
```

## Related functions

* [`map` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map.md)
