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
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, the following resources are available:
InfluxDB Cloud and InfluxDB Enterprise customers can contact InfluxData Support.