Documentation

SQL conditional functions

The InfluxDB Clustered SQL implementation supports the following conditional functions for conditionally handling null values:

coalesce

Returns the first of its arguments that is not null. Returns null if all arguments are null. This function is often used to substitute a default value for null values.

coalesce(expression1[, ..., expression_n])
  • Copy
  • Fill window
Arguments
  • expression1, expression_n: Expression to use if previous expressions are null. Can be a constant, column, or function, and any combination of arithmetic operators. Pass as many expression arguments as necessary.

View coalesce query example

ifnull

Alias of nvl.

nullif

Returns null if expression1 equals expression2; otherwise it returns expression1. This can be used to perform the inverse operation of coalesce.

nullif(expression1, expression2)
  • Copy
  • Fill window
Arguments
  • expression1: Expression to compare and return if equal to expression2. Can be a constant, column, or function, and any combination of arithmetic operators.
  • expression2: Expression to compare to expression1. Can be a constant, column, or function, and any combination of arithmetic operators.

View nullif query example

nvl

Returns expression2 if expression1 is null; otherwise it returns expression1.

nvl(expression1, expression2)
  • Copy
  • Fill window
Arguments
  • expression1: Return this expression if not null. Can be a constant, column, or function, and any combination of arithmetic operators.
  • expression2: Return this expression if expression1 is null. Can be a constant, column, or function, and any combination of arithmetic operators.

View nvl query example

nvl2

Returns expression2 if expression1 is not null; otherwise it returns expression3.

nvl2(expression1, expression2, expression3)
  • Copy
  • Fill window
Arguments
  • expression1: First expression to test for null. Can be a constant, column, or function, and any combination of operators.
  • expression2: Second expression to return if expression1 is not null. Can be a constant, column, or function, and any combination of operators.
  • expression3: Expression to return if expression1 is null. Can be a constant, column, or function, and any combination of operators.

View nvl2 query example


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 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out: