Documentation

InfluxQL selector functions

InfluxDB 3 Core is in Public Alpha

InfluxDB 3 Core is in public alpha and available for testing and feedback, but is not meant for production use. Both the product and this documentation are works in progress. We welcome and encourage your input about your experience with the alpha and invite you to join our public channels for updates and to share feedback.

Alpha expectations and recommendations

Use selector functions to assess, select, and return values in your data. Selector functions return one or more rows with the selected values from each InfluxQL group.

Examples use the sample data set provided in the Get started with InfluxDB tutorial.

Missing InfluxQL functions

Some InfluxQL functions are in the process of being rearchitected to work with the InfluxDB 3 storage engine. If a function you need is not here, check the InfluxQL feature support page for more information.

BOTTOM()

Returns the smallest N field values. BOTTOM() supports int64 and float64 field value data types.

BOTTOM(field_expression[, tag_expression_1[, ..., tag_expression_n]], N)

Note: BOTTOM() returns the field value with the earliest timestamp if there’s a tie between two or more values for the smallest value.

Arguments

  • field_expression: Expression to identify the field to operate on. Can be a field key or constant.
  • tag_expression: Expression to identify a tag key to segment by. Can be a tag key or constant. Comma-delimit multiple tags.
  • N: Number of results to return from each InfluxQL group or specified tag segment.

Notable behaviors

Examples

Select the bottom three values of a field

Select the bottom field value for two unique tag values

Select the bottom three field values and the tag value associated with each

Select the bottom field values for unique tag values and within time windows (grouped by time)

FIRST()

Returns the field value with the oldest timestamp.

FIRST(field_expression)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, regular expression, or wildcard (*). Supports all field data types.

Notable behaviors

Examples

Select the first value for a field

Select the first value from each field

Select the first value from field keys that match a regular expression

Select the first value from a field within time windows (grouped by time)

LAST()

Returns the field value with the most recent timestamp.

LAST(field_expression)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, regular expression, or wildcard (*). Supports all field data types.

Notable behaviors

Examples

Select the last value for a field

Select the last value from each field

Select the last value from field keys that match a regular expression

Select the last value from a field within time windows (grouped by time)

MAX()

Returns the greatest field value.

MAX(field_expression)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, regular expression, or wildcard (*). Supports numeric fields.

Notable behaviors

Examples

Select the maximum value from a field

Select the maximum value from each field

Select the maximum value from field keys that match a regular expression

Select the maximum value from a field within time windows (grouped by time)

MIN()

Returns the lowest field value.

MIN(field_expression)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, regular expression, or wildcard (*). Supports numeric fields.

Notable behaviors

Examples

Select the minimum value from a field

Select the minimum value from each field

Select the minimum value from field keys that match a regular expression

Select the minimum value from a field within time windows (grouped by time)

PERCENTILE()

Returns the Nth percentile field value.

PERCENTILE(field_expression, N)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, regular expression, or wildcard (*). Supports numeric fields.
  • N: Percentile to return. Must be an integer or float value greater than 0 and less than or equal to 100.

Notable behaviors

Examples

Select the 50th percentile value from a field

Select the 50th percentile value from each field

Select the 50th percentile value from field keys that match a regular expression

Select the 50th percentile value from a field within time windows (grouped by time)

TOP()

Returns the greatest N field values. TOP() supports int64 and float64 field value data types.

TOP(field_expression[, tag_expression_1[, ..., tag_expression_n]], N)

Note: TOP() returns the field value with the earliest timestamp if there’s a tie between two or more values for the greatest value.

Arguments

  • field_expression: Expression to identify the field to operate on. Can be a field key or constant.
  • tag_expression: Expression to identify a tag key to segment by. Can be a tag key or constant. Comma-delimit multiple tags.
  • N: Number of results to return from each InfluxQL group or specified tag segment.

Notable behaviors

Examples

Select the top three values of a field

Select the top field value for two unique tag values

Select the top three field values and the tag value associated with each

Select the top field values for unique tag values and within time windows (grouped by time)

Notable behaviors of selector functions

Timestamps when grouping by time

When using selector functions with a GROUP BY time() clause, most selector functions return the timestamp of the starting boundary for each time interval. However functions with an N argument that specifies the number of results to return per group maintain the original timestamp of each returned point.

Return the start time of each time interval
Maintain the original timestamp

Selector functions may return fewer points than expected

Queries that use the following selector functions with an N argument may return fewer points than expected.

If the InfluxQL group or specified tag key contains X points or unique tag values and X is less than N, the function returns X results instead of N for each group or tag value.

View example for FN(field_key, N)

View example for FN(field_key, tag_key, N)


Was this page helpful?

Thank you for your feedback!


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.

Read more

InfluxDB 3 Open Source Now in Public Alpha

InfluxDB 3 Open Source is now available for alpha testing, licensed under MIT or Apache 2 licensing.

We are releasing two products as part of the alpha.

InfluxDB 3 Core, is our new open source product. It is a recent-data engine for time series and event data. InfluxDB 3 Enterprise is a commercial version that builds on Core’s foundation, adding historical query capability, read replicas, high availability, scalability, and fine-grained security.

For more information on how to get started, check out: