Documentation

InfluxQL transformation functions

InfluxQL transformation functions modify and return values in each row of queried data.

Missing InfluxQL functions

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

Notable behaviors of transformation functions

Must use aggregate or selector functions when grouping by time

Most transformation functions support GROUP BY clauses that group by tags, but do not directly support GROUP BY clauses that group by time. To use transformation functions with with a GROUP BY time() clause, apply an aggregate or selector function to the field_expression argument. The transformation operates on the result of the aggregate or selector operation.


ABS()

Returns the absolute value of the field value.

ABS(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply ABS() to a field

Apply ABS() to each field

Apply ABS() to time windows (grouped by time)

ACOS()

Returns the arccosine (in radians) of the field value. Field values must be between -1 and 1.

ACOS(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply ACOS() to a field

Apply ACOS() to each field

Apply ACOS() to time windows (grouped by time)

ASIN()

Returns the arcsine (in radians) of the field value. Field values must be between -1 and 1.

ASIN(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply ASIN() to a field

Apply ASIN() to each field

Apply ASIN() to time windows (grouped by time)

ATAN()

Returns the arctangent (in radians) of the field value.

ATAN(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply ATAN() to a field

Apply ATAN() to each field

Apply ATAN() to time windows (grouped by time)

ATAN2()

Returns the the arctangent of y/x in radians.

ATAN2(expression_y, expression_x)

Arguments

  • expression_y: Expression to identify the y numeric value or one or more fields to operate on. Can be a number literal, field key, constant, or wildcard (*). Supports numeric field types.
  • expression_x: Expression to identify the x numeric value or one or more fields to operate on. Can be a number literal, field key, constant, or wildcard (*). Supports numeric field types.

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply ATAN2() to a field divided by another field

Apply ATAN2() to each field divided by a numeric value

Apply ATAN2() to time windows (grouped by time)

CEIL()

Returns the subsequent value rounded up to the nearest integer.

CEIL(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply CEIL() to a field

Apply CEIL() to each field

Apply CEIL() to time windows (grouped by time)

COS()

Returns the cosine of the field value.

COS(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply COS() to a field

Apply COS() to each field

Apply COS() to time windows (grouped by time)

CUMULATIVE_SUM()

Returns the running total of subsequent field values.

CUMULATIVE_SUM(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 field types.

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply CUMULATIVE_SUM() to a field

Apply CUMULATIVE_SUM() to each field

Apply CUMULATIVE_SUM() to field keys that match a regular expression

Apply CUMULATIVE_SUM() to time windows (grouped by time)

DERIVATIVE()

Returns the rate of change between subsequent field values per unit.

SELECT DERIVATIVE(field_expression[, unit])

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 field types.
  • unit: Unit of time to use to calculate the rate of change. Supports duration literals. Default is 1s (per second).

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply DERIVATIVE() to a field to calculate the per second change

Apply DERIVATIVE() to a field to calculate the per 5 minute change

Apply DERIVATIVE() to each field

Apply DERIVATIVE() to field keys that match a regular expression

Apply DERIVATIVE() to time windows (grouped by time)

DIFFERENCE()

Returns the result of subtraction between subsequent field values.

DIFFERENCE(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 field types.

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply DIFFERENCE() to a field

Apply DIFFERENCE() to each field

Apply DIFFERENCE() to field keys that match a regular expression

Apply DIFFERENCE() to time windows (grouped by time)

ELAPSED()

Returns the difference between subsequent field value’s timestamps in a specified unit of time.

ELAPSED(field_expression[, unit ])

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 types.
  • unit: Unit of time to return the elapsed time in. Supports duration literals. Default is 1ns (nanoseconds).

Notable behaviors

  • If the unit is greater than the elapsed time between points, ELAPSED() returns 0.
  • ELAPSED() supports the GROUP BY time() clause but the query results aren’t very useful. An ELAPSED() query with a nested function and a GROUP BY time() clause returns the interval specified in the GROUP BY time() clause.

Examples

The following examples use the Random numbers sample data.

Apply ELAPSED() to a field and return elapsed time in nanoseconds

Apply ELAPSED() to a field and return elapsed time in seconds

Apply ELAPSED() to each field

Apply ELAPSED() to field keys that match a regular expression

EXP()

Returns the exponential of the field value.

EXP(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply EXP() to a field

Apply EXP() to each field

Apply EXP() to time windows (grouped by time)

FLOOR()

Returns the subsequent value rounded down to the nearest integer.

FLOOR(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply FLOOR() to a field

Apply FLOOR() to each field

Apply FLOOR() to time windows (grouped by time)

LN()

Returns the natural logarithm of the field value. Field values must be greater than or equal to 0.

LN(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply LN() to a field

Apply LN() to each field

Apply LN() to time windows (grouped by time)

LOG()

Returns the logarithm of the field value with base b. Field values must be greater than or equal to 0.

LOG(field_expression, b)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, or wildcard (*). Supports numeric field types.
  • b: Logarithm base to use in the operation.

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply LOG() to a field with a base of 3

Apply LOG() to each field with a base of 5

Apply LOG() to time windows (grouped by time)

LOG2()

Returns the logarithm of the field value to the base 2. Field values must be greater than or equal to 0.

LOG2(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply LOG2() to a field

Apply LOG2() to each field

Apply LOG2() to time windows (grouped by time)

LOG10()

Returns the logarithm of the field value to the base 10. Field values must be greater than or equal to 0.

LOG10(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply LOG10() to a field

Apply LOG10() to each field

Apply LOG10() to time windows (grouped by time)

MOVING_AVERAGE()

Returns the rolling average across a window of subsequent field values.

MOVING_AVERAGE(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 all field types.
  • N: Number of field values to use when calculating the moving average.

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply MOVING_AVERAGE() to a field

Apply MOVING_AVERAGE() to each field

Apply MOVING_AVERAGE() to field keys that match a regular expression

Apply MOVING_AVERAGE() to time windows (grouped by time)

NON_NEGATIVE_DERIVATIVE()

Returns only non-negative rate of change between subsequent field values. Negative rates of change return null.

NON_NEGATIVE_DERIVATIVE(field_expression[, unit])

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 field types.
  • unit: Unit of time to use to calculate the rate of change. Supports duration literals. Default is 1s (per second).

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply NON_NEGATIVE_DERIVATIVE() to a field to calculate the per second change

Apply NON_NEGATIVE_DERIVATIVE() to a field to calculate the per 5 minute change

Apply NON_NEGATIVE_DERIVATIVE() to each field

Apply NON_NEGATIVE_DERIVATIVE() to field keys that match a regular expression

Apply NON_NEGATIVE_DERIVATIVE() to time windows (grouped by time)

NON_NEGATIVE_DIFFERENCE()

Returns only non-negative result of subtraction between subsequent field values. Negative differences return null.

NON_NEGATIVE_DIFFERENCE(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 field types.

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply NON_NEGATIVE_DIFFERENCE() to a field

Apply NON_NEGATIVE_DIFFERENCE() to each field

Apply NON_NEGATIVE_DIFFERENCE() to field keys that match a regular expression

Apply NON_NEGATIVE_DIFFERENCE() to time windows (grouped by time)

POW()

Returns the field value to the power of x.

POW(field_expression, x)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply POW() to a field with a power of 3

Apply POW() to each field with a power of 5

Apply POW() to time windows (grouped by time)

ROUND()

Returns a field value rounded to the nearest integer.

ROUND(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply ROUND() to a field

Apply ROUND() to each field

Apply ROUND() to time windows (grouped by time)

SIN()

Returns the sine of a field value.

SIN(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply SIN() to a field

Apply SIN() to each field

Apply SIN() to time windows (grouped by time)

SQRT()

Returns the square root of a field value. Field values must be greater than or equal to 0. Negative field values return null.

SQRT(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply SQRT() to a field

Apply SQRT() to each field

Apply SQRT() to time windows (grouped by time)

TAN()

Returns the tangent of the field value.

TAN(field_expression)

Arguments

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

Notable behaviors

Examples

The following examples use the Random numbers sample data.

Apply TAN() to a field

Apply TAN() to each field

Apply TAN() to time windows (grouped by time)


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.

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:

InfluxDB Cloud Serverless