OFFSET and SOFFSET clauses

Use OFFSET and SOFFSET to paginate points and series returned.

OFFSET clause

OFFSET <N> paginates N points in the query results.

Syntax

  1. SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] LIMIT_clause OFFSET <N> [SLIMIT_clause]

N specifies the number of points to paginate. The OFFSET clause requires a LIMIT clause.

Note: InfluxDB returns no results if the WHERE clause includes a time range and the OFFSET clause would cause InfluxDB to return points with timestamps outside of that time range.

Examples

Paginate points

  1. SELECT "water_level","location" FROM "h2o_feet" LIMIT 3 OFFSET 3

Output:

Name: h2o_feet

timewater_levellocation
2019-08-17T00:06:00Z2.1160000000santa_monica
2019-08-17T00:12:00Z7.8870000000coyote_creek
2019-08-17T00:12:00Z2.0280000000santa_monica

The query returns the fourth, fifth, and sixth points from the h2o_feet measurement. If the query did not include OFFSET 3, it would return the first, second, and third points from that measurement.

Paginate points and include several clauses

  1. SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:42:00Z' GROUP BY *,time(12m) ORDER BY time DESC LIMIT 2 OFFSET 2 SLIMIT 1

Output:

name: h2o_feet
tags: location=coyote_creek

timemean
2019-08-18T00:12:00Z8.2725000000
2019-08-18T00:00:00Z8.4615000000

In this example:

  • The SELECT clause specifies the InfluxQL MEAN() function.
  • The [FROM clause] (/influxdb/v2/query-data/influxql/explore-data/select/#from-clause) specifies a single measurement.
  • The WHERE clause specifies the time range for the query.
  • The GROUP BY clause groups results by all tags (*) and into 12-minute intervals.
  • The ORDER BY time DESC clause returns results in descending timestamp order.
  • The LIMIT 2 clause limits the number of points returned to two.
  • The OFFSET 2 clause excludes the first two averages from the query results.
  • The SLIMIT 1 clause limits the number of series returned to one.

Without OFFSET 2, the query would return the first two averages of the query results:

Output:

name: h2o_feet
tags: location=coyote_creek

timemean
2019-08-18T00:36:00Z7.8330000000
2019-08-18T00:24:00Z8.0710000000

SOFFSET clause

SOFFSET <N> paginates N series in the query results.

Syntax

  1. SELECT_clause FROM_clause [WHERE_clause] GROUP BY *[,time(time_interval)] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] SLIMIT_clause SOFFSET <N>

N specifies the number of series to paginate. The SOFFSET clause requires an [SLIMIT clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/. Using the SOFFSET clause without an SLIMIT clause can cause inconsistent query results. SLIMIT queries must include GROUP BY *.

Note: InfluxDB returns no results if the SOFFSET clause paginates through more than the total number of series.

Examples

Paginate series

Paginate series

  1. SELECT "water_level" FROM "h2o_feet" GROUP BY * SLIMIT 1 SOFFSET 1

Output:

name: h2o_feet
tags: location=santa_monica

timewater_level
2019-08-17T00:00:00Z2.0640000000
2019-08-17T00:06:00Z2.1160000000
2019-08-17T00:12:00Z2.0280000000
2019-08-17T00:18:00Z2.1260000000
2019-08-17T00:24:00Z2.0410000000
2019-08-17T00:30:00Z2.0510000000
2019-08-17T00:36:00Z2.0670000000
2019-08-17T00:42:00Z2.0570000000

The results above are partial, as the data set is quite large. The query returns data for the series associated with the h2o_feet measurement and the location = santa_monica tag. Without SOFFSET 1, the query returns data for the series associated with the h2o_feet measurement and the location = coyote_creek tag.

Paginate points and include several clauses

Paginate series and include all clauses

  1. SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:42:00Z' GROUP BY *,time(12m) ORDER BY time DESC LIMIT 2 OFFSET 2 SLIMIT 1 SOFFSET 1

Output:

name: h2o_feet
tags: location=santa_monica

timemean
2019-08-18T00:12:00Z2.3360000000
2019-08-18T00:00:00Z2.3655000000

In this example:

Without SOFFSET 1, the query would return the results for a different series:

Output:

name: h2o_feet
tags: location=coyote_creek

timemean
2019-08-18T00:12:00Z8.2725000000
2019-08-18T00:00:00Z8.4615000000