Documentation

Operators in the Flux language

Flux includes the following types of operators:

Also see:

Arithmetic operators

Arithmetic operators take two numerical values (either literals or variables) and perform a calculation that returns a single numerical value.

OperatorDescriptionExampleResult
+Addition1 + 12
-Subtraction3 - 21
*Multiplication2 * 36
/Division9 / 33
^Exponentiation2 ^ 38
%Modulo10 % 50

In the current version of Flux, values used in arithmetic operations must be of the same numeric type (integer or float). Operations with values of different numeric types will result in a type error.

Comparison operators

Comparison operators compare expressions and return true or false based on the comparison.

OperatorDescriptionExampleResult
==Equal to"abc" == "abc"true
!=Not equal to"abc" != "def"true
<Less than1 < 2true
>Greater than1 > 2false
<=Less than or equal1 <= 2true
>=Greater than or equal1 >= 2false
=~Equal to regular expression"abc" =~ /[a-z]*/true
!~Not equal to regular expression"abc" !~ /[0-9]*/true

The > and < operators also compare the lexicographic order of strings.

Logical operators

OperatorDescription
notReturns true if right operand is false. Otherwise, returns false.
existsReturns false if right operand is null. Otherwise, returns true.
andReturns true if both operands are true. Otherwise, returns false.
orReturns true if any operand is true. Otherwise, returns false.

Short-circuit evaluation

Flux logical operators observe the short-circuiting behavior seen in other programming languages. The evaluation of the left-hand (LH) operand determines if the right-hand (RH) operand is evaluated.

  • When the operator is and and the LH operand evaluates to false, the evaluation returns false without evaluating the RH operand.
  • When the operator is or and the LH operand evaluates to true, the evaluation returns true without evaluating the RH operand.

Assignment operators

An assignment operator assigns a value to its left operand based on the value of its right operand.

OperatorDescriptionExampleMeaning
=Assign value of left expression to right expressionx = yx = y

Function operators

Function operators facilitate the creation of functions and control the flow of data through operations.

OperatorDescriptionExamplesMeaning
|>Pipe‑forwarddata |> function()Tables contained in the “data” variable are piped into the function.
<-Pipe‑receivetables=<-The “tables” variable or parameter is assigned to data piped into the operation. This operator is used for any data type passed into a function; not just table data.
=>Arrow(r) => r.tag1 == "tagvalue"The arrow passes a record or parameters into function operations.
()Function calltop(n:10)Call the top function setting the n parameter to 10 and perform the associated operations.

See Define custom functions for examples of function operators is use.


String Operators

String operators concatenate or compare string values.

OperatorDescriptionExamplesResult
+Concatenation"ab" + "c""abc"
<Less than in lexicographic order"ant" < "bee"true
>Greater than in lexicographic order"ant" > "bee"false

Literal constructors

Literal constructors define fixed values.

OperatorDescription
[ ]List / array
{ }Record
""String

Miscellaneous operators

OperatorDescriptionExample
( )Logical groupingr._value / (r._value * 2)
,Sequence delimiteritem1, item2, item3
:Key-value separator{name: "Bob"}
.Member access / dot referencer._measurement

Operator precedence

The table below outlines operator precedence. Operators with a lower number have higher precedence.

PrecedenceOperatorDescription
1a()Function call
a[]Member or index access
.Member access
2|>Pipe forward
3() => 1FunctionLiteral
4^Exponentiation
5* / %Multiplication, division, and modulo
6+ -Addition and subtraction
7== !=Comparison operators
< <=
> >=
=~ !~
8notUnary logical operator
existsNull check operator
9andLogical AND
10orLogical OR
11if then elseConditional

Was this page helpful?

Thank you for your feedback!


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.