MAP_INSERT
functionsupportedCore SQL functionsReturns a new MAP consisting of the input MAP with a new key-value pair inserted. That is, an existing key is updated with a new value.
Syntax
supportedpartialnot supportednot scored
MAP_INSERT( <map> , <key> , <value> [ , <updateFlag> ] )
Parameters
| Name | Required | Description |
|---|---|---|
map | required | The source map into which the new key-value pair is inserted. |
key | required | The new key to insert into the map. Must be different from all existing keys in the map, unless updateFlag is set to TRUE. |
value | required | The value associated with the key. |
updateFlag | optional | A Boolean flag that, when set to TRUE, specifies the input value is used to update an existing value for a key in the map, rather than inserting a new key-value pair. The default is FALSE. |
Returns
Returns a MAP consisting of the input MAP with a new key-value pair inserted or an existing key updated with a new value.
Usage notes
- The type of the key expression must match the type of the map’s key. If the type is VARCHAR, then the types can be different lengths.
- The function supports JSON null values, but not SQL NULL values or keys: If key is any string other than NULL and value is a JSON null (for example, PARSE_JSON('NULL')), then the key-value pair is inserted into the returned map.
- If key is any string other than NULL and value is a SQL NULL (for example, NULL), then the value is converted to JSON null, and the key-value pair is inserted into the returned map.
- If key is a SQL NULL, the key-value pair is omitted from the returned map.
- If updateFlag is set to TRUE, then the existing input key is updated to the input value. If updateFlag is omitted or set to FALSE, and the input key already exists in the map, then an error is returned.
- If updateFlag is set to TRUE, but the corresponding key does not already exist in the map, then the key-value pair is added.