Documentation

Operate on columns

This page documents an earlier version of InfluxDB. InfluxDB v2.6 is the latest stable version. View this page in the v2.6 documentation.

Use the following common queries to operate on columns:

These examples use NOAA water sample data.

Find and count unique values in a column

Find and count the number of unique values in a specified column. The following examples find and count unique locations where data was collected.

Find unique values

This query:

  • Uses group() to ungroup data and return results in a single table.
  • Uses keep() and unique() to return unique values in the specified column.
from(bucket: "noaa")
    |> range(start: 2019-08-17)
    |> keep(columns: ["location"])
    |> group()
    |> unique(column: "location")

Example results

location
coyote_creek
santa_monica

Count unique values

This query:

  • Uses group() to ungroup data and return results in a single table.
  • Uses keep(), unique(), and then count() to count the number of unique values.
from(bucket: "noaa")
    |> range(start: 2019-08-17)
    |> keep(columns: ["location"])
    |> group()
    |> unique(column: "location")
    |> count(column: "location")

Example results

location
2

Recalculate the _values column

To recalculate the _value column, use the with operator in map() to overwrite the existing _value column.

The following query:

  • Uses filter() to filter the average_temperature measurement.
  • Uses map() to convert Fahrenheit temperature values into Celsius.

from(bucket: "noaa")
    |> range(start: 2019-08-17)
    |> filter(fn: (r) => r._measurement == "average_temperature")
    |> map(fn: (r) => ({r with _value: (float(v: r._value) - 32.0) * 5.0 / 9.0} ))
_field_measurement_start_stop_timelocation_value
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:00:00Zcoyote_creek27.77777777777778
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:06:00Zcoyote_creek22.77777777777778
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:12:00Zcoyote_creek30
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:18:00Zcoyote_creek31.666666666666668
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:24:00Zcoyote_creek25
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:30:00Zcoyote_creek21.11111111111111
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:36:00Zcoyote_creek28.88888888888889
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:42:00Zcoyote_creek24.444444444444443
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:48:00Zcoyote_creek29.444444444444443
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:54:00Zcoyote_creek26.666666666666668
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T01:00:00Zcoyote_creek21.11111111111111
•••••••••••••••••••••

Calculate a new column

To use values in a row to calculate and add a new column, use map(). This example below converts temperature from Fahrenheit to Celsius and maps the Celsius value to a new celsius column.

The following query:

  • Uses filter() to filter the average_temperature measurement.
  • Uses map() to create a new column calculated from existing values in each row.
from(bucket: "noaa")
    |> range(start: 2019-08-17)
    |> filter(fn: (r) => r._measurement == "average_temperature")
    |> map(fn: (r) => ({r with celsius: (r._value - 32.0) * 5.0 / 9.0}))

Example results

_start_stop_field_measurementlocation_time_valuecelsius
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:00:00Z8227.78
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:06:00Z7322.78
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:12:00Z8630.00
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:18:00Z8931.67
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:24:00Z7725.00
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:30:00Z7021.11
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:36:00Z8428.89
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:42:00Z7624.44
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:48:00Z8529.44
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:54:00Z8026.67
••••••••••••••••••••••••

Was this page helpful?

Thank you for your feedback!


Set your InfluxDB URL

Linux Package Signing Key Rotation

All signed InfluxData Linux packages have been resigned with an updated key. If using Linux, you may need to update your package configuration to continue to download and verify InfluxData software packages.

For more information, see the Linux Package Signing Key Rotation blog post.

InfluxDB Cloud backed by InfluxDB IOx

All InfluxDB Cloud organizations created on or after January 31, 2023 are backed by the new InfluxDB IOx storage engine. Check the right column of your InfluxDB Cloud organization homepage to see which InfluxDB storage engine you’re using.

If powered by IOx, this is the correct documentation.

If powered by TSM, see the TSM-based InfluxDB Cloud documentation.

InfluxDB Cloud backed by InfluxDB TSM

All InfluxDB Cloud organizations created on or after January 31, 2023 are backed by the new InfluxDB IOx storage engine which enables nearly unlimited series cardinality and SQL query support. Check the right column of your InfluxDB Cloud organization homepage to see which InfluxDB storage engine you’re using.

If powered by TSM, this is the correct documentation.

If powered by IOx, see the IOx-based InfluxDB Cloud documentation.

State of the InfluxDB Cloud (IOx) documentation

The new documentation for InfluxDB Cloud backed by InfluxDB IOx 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.