Work with records

A record type is a set of key-value pairs (also known as properties). Keys (also known as labels) are strings. Values can be any data type. Each property can have a different value type.

Record syntax

A record literal contains a set of key-value pairs (properties) enclosed in curly brackets ({}). Properties are comma-delimitted. Property keys must be strings and can optionally be enclosed in double quotes ("). If a property key contains whitespace characters or only numeric characters, you must enclose the property key in double quotes. Property keys are associated to values by a colon (:). Values can be any type.

Example records
{foo: "bar", baz: 123.4, quz: -2}

{"Company Name": "ACME", "Street Address": "123 Main St.", id: 1123445}

Reference values in a record

Flux records are key-indexed. To reference values in a record, use dot notation or bracket notation and specify the key to reference.

Dot notation

Specify the record to access followed by a period (.) and the property key.

c = {name: "John Doe", address: "123 Main St.", id: 1123445}
// Returns John Doe
// Returns 1123445

Bracket notation

Specify the record to access followed by the property key enclosed in double quotes and square brackets ([""]).

Use bracket notation to access keys with special or whitespace characters.

c = {"Company Name": "ACME", "Street Address": "123 Main St.", id: 1123445}

c["Company Name"]
// Returns ACME

// Returns 1123445

Reference nested records

To reference nested records, use chained dot or bracket notation for each nested level.

customer = 
        name: "John Doe",
        address: {
            street: "123 Main St.",
            city: "Pleasantville",
            state: "New York"

// Returns 123 Main St.

// Returns Pleasantville

// Returns New York

Reference keys statically

Record keys can only be referenced statically, meaning you cannot dynamically specify a key to access. For example:

key = "foo"
o = {foo: "bar", baz: 123.4}

// Error: type error: record is missing label key

To dynamically reference keys in a composite type, consider using a dictionary.

Operate on records

Extend a record

Use the with operator to extend a record. The with operator overwrites record properties if the specified keys exists or adds the new properties if the keys do not exist.

c = {name: "John Doe", id: 1123445}

{c with spouse: "Jane Doe", pet: "Spot"}
// Returns {id: 1123445, name: John Doe, pet: Spot, spouse: Jane Doe}

List keys in a record

  1. Import the experimental package.
  2. Use experimental.objectKeys to return an array of keys in a record.
import "experimental"

c = {name: "John Doe", id: 1123445}

experimental.objectKeys(o: c)
// Returns [name, id]

Compare records

Use the == comparison operator to check if two records are equal. Equality is based on keys, their values, and types.

{id: 1, msg: "hello"} == {id: 1, msg: "goodbye"}
// Returns false

{foo: 12300.0, bar: 34500.0} == {bar: float(v: "3.45e+04"), foo: float(v: "1.23e+04")}
// Returns true

Return the string representation of a record

Use display() to return the Flux literal representation of a record as a string.

x = {a: 1, b: 2, c: 3}

display(v: x)

// Returns "{a: 1, b: 2, c: 3}"

Include the string representation of a record in a table

Use display() to return the Flux literal representation of a record as a string and include it as a column value.

import "sampledata"

    |> map(fn: (r) => ({_time: r._time, exampleRecord: display(v: {tag: r.tag, value:r._value})}))


_time (time)exampleRecord (string)
2021-01-01T00:00:00Z{tag: t1, value: smpl_g9qczs}
2021-01-01T00:00:10Z{tag: t1, value: smpl_0mgv9n}
2021-01-01T00:00:20Z{tag: t1, value: smpl_phw664}
2021-01-01T00:00:30Z{tag: t1, value: smpl_guvzy4}
2021-01-01T00:00:40Z{tag: t1, value: smpl_5v3cce}
2021-01-01T00:00:50Z{tag: t1, value: smpl_s9fmgy}
2021-01-01T00:00:00Z{tag: t2, value: smpl_b5eida}
2021-01-01T00:00:10Z{tag: t2, value: smpl_eu4oxp}
2021-01-01T00:00:20Z{tag: t2, value: smpl_5g7tz4}
2021-01-01T00:00:30Z{tag: t2, value: smpl_sox1ut}
2021-01-01T00:00:40Z{tag: t2, value: smpl_wfm757}
2021-01-01T00:00:50Z{tag: t2, value: smpl_dtn2bv}

Was this page helpful?

Thank you for your feedback!

Introducing InfluxDB Clustered

A highly available InfluxDB 3.0 cluster on your own infrastructure.

InfluxDB Clustered is a highly available InfluxDB 3.0 cluster built for high write and query workloads on your own infrastructure.

InfluxDB Clustered is currently in limited availability and is only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Learn more
Contact InfluxData Sales

The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following:

State of the InfluxDB Cloud Serverless documentation

InfluxDB Cloud Serverless documentation is a work in progress.

The new documentation for InfluxDB Cloud Serverless is a work in progress. We are adding new information and content almost daily. Thank you for your patience!

If there is specific information you’re looking for, please submit a documentation issue.