Documentation

Fill gaps in data

Use date_bin_gapfill with interpolate or locf to fill gaps of time where no data is returned. Gap-filling SQL queries handle missing data in time series data by filling in gaps with interpolated values or by carrying forward the last available observation.

To fill gaps in data:

  1. Use the date_bin_gapfill function to window your data into time-based groups and apply an aggregate function to each window. If no data exists in a window, date_bin_gapfill inserts a new row with the starting timestamp of the window, all columns in the GROUP BY clause populated, and null values for the queried fields.

  2. Use either interpolate or locf to fill the inserted null values in the specified column.

    • interpolate: fills null values by interpolating values between non-null values.
    • locf: fills null values by carrying the last observed value forward.

    The expression passed to interpolate or locf must use an aggregate function.

  3. Include a WHERE clause that sets upper and lower time bounds. For example:

WHERE time >= '2022-01-01T08:00:00Z' AND time <= '2022-01-01T10:00:00Z'

Example of filling gaps in data

The following examples use the Home sensor sample data to show how to use date_bin_gapfill and the different results of interplate and locf.

SELECT
  date_bin_gapfill(INTERVAL '30 minutes', time) as time,
  room,
  interpolate(avg(temp))
FROM home
WHERE
    time >= '2022-01-01T08:00:00Z'
    AND time <= '2022-01-01T10:00:00Z'
GROUP BY 1, room
timeroomAVG(home.temp)
2022-01-01T08:00:00ZKitchen21
2022-01-01T08:30:00ZKitchen22
2022-01-01T09:00:00ZKitchen23
2022-01-01T09:30:00ZKitchen22.85
2022-01-01T10:00:00ZKitchen22.7
2022-01-01T08:00:00ZLiving Room21.1
2022-01-01T08:30:00ZLiving Room21.25
2022-01-01T09:00:00ZLiving Room21.4
2022-01-01T09:30:00ZLiving Room21.6
2022-01-01T10:00:00ZLiving Room21.8
SELECT
  date_bin_gapfill(INTERVAL '30 minutes', time) as time,
  room,
  locf(avg(temp))
FROM home
WHERE
    time >= '2022-01-01T08:00:00Z'
    AND time <= '2022-01-01T10:00:00Z'
GROUP BY 1, room
timeroomAVG(home.temp)
2022-01-01T08:00:00ZKitchen21
2022-01-01T08:30:00ZKitchen21
2022-01-01T09:00:00ZKitchen23
2022-01-01T09:30:00ZKitchen23
2022-01-01T10:00:00ZKitchen22.7
2022-01-01T08:00:00ZLiving Room21.1
2022-01-01T08:30:00ZLiving Room21.1
2022-01-01T09:00:00ZLiving Room21.4
2022-01-01T09:30:00ZLiving Room21.4
2022-01-01T10:00:00ZLiving Room21.8

Was this page helpful?

Thank you for your feedback!


New in InfluxDB 3.5

Key enhancements in InfluxDB 3.5 and the InfluxDB 3 Explorer 1.3.

See the Blog Post

InfluxDB 3.5 is now available for both Core and Enterprise, introducing custom plugin repository support, enhanced operational visibility with queryable CLI parameters and manual node management, stronger security controls, and general performance improvements.

InfluxDB 3 Explorer 1.3 brings powerful new capabilities including Dashboards (beta) for saving and organizing your favorite queries, and cache querying for instant access to Last Value and Distinct Value caches—making Explorer a more comprehensive workspace for time series monitoring and analysis.

For more information, check out:

InfluxDB Docker latest tag changing to InfluxDB 3 Core

On November 3, 2025, the latest tag for InfluxDB Docker images will point to InfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags in your Docker deployments.

If using Docker to install and run InfluxDB, the latest tag will point to InfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags in your Docker deployments. For example, if using Docker to run InfluxDB v2, replace the latest version tag with a specific version tag in your Docker pull command–for example:

docker pull influxdb:2