Documentation

dict.insert() function

The dict.insert() function inserts a key value pair into a dictionary and returns a new, updated dictionary. If the key already exists in the dictionary, the function overwrites the existing value.

import "dict"

dict.insert(
  dict: [1: "foo", 2: "bar"],
  key: 3,
  value: "baz"
)

Parameters

All paremeters are required

dict

Dictionary to update.

Data type: Dictionary

key

Key to insert into the dictionary. Must be the same type as existing keys in the dictionary.

Data type: String | Boolean | Integer | Uinteger | Float | Time | Bytes

default

Value to insert into the dictionary. Must be the same type as existing values in the dictionary.

Data type: String | Boolean | Integer | Uinteger | Float | Time | Bytes

Examples

Insert a new key-value pair into a dictionary
import "dict"

d = [1: "foo", 2: "bar"]

dNew = dict.insert(
  dict: d,
  key: 3,
  value: "baz"
)

// Verify the new key-value pair was inserted
dict.get(dict: dNew, key: 3, default: "")

// Returns baz
Overwrite an existing key-value pair in a dictionary
import "dict"

d = [1: "foo", 2: "bar"]

dNew = dict.insert(
  dict: d,
  key: 2,
  value: "baz"
)

// Verify the new key-value pair was overwritten
dict.get(dict: dNew, key: 2, default: "")

// Returns baz

New! Cloud or OSS?

InfluxDB OSS 2.0 now generally available!

InfluxDB OSS 2.0 is now generally available and ready for production use. See the InfluxDB OSS 2.0 release notes.

For information about upgrading to InfluxDB OSS 2.0, see: