Documentation

Query data in InfluxDB 3 Enterprise

InfluxDB 3 Enterprise supports both native SQL and InfluxQL for querying data. InfluxQL is an SQL-like query language designed for InfluxDB v1 and customized for time series queries.

Flux, the language introduced in InfluxDB v2, is not supported in InfluxDB 3.

Query data with the influxdb3 CLI

To get started querying data in InfluxDB 3 Enterprise, use the influxdb3 query command and provide the following:

  • -H, --host: The host URL of the server (default is http://127.0.0.1:8181)
  • -d, --database: (Required) The name of the database to query
  • -l, --language: The query language of the provided query string
    • sql (default)
    • influxql
  • SQL or InfluxQL query as a string

If the INFLUXDB3_AUTH_TOKEN environment variable defined in Set up InfluxDB 3 Enterprise isn’t set in your environment, set it or provide your token using the -t, --token option in your command.

To query the home sensor sample data you wrote in Write data to InfluxDB 3 Enterprise, run the following command:

influxdb3 query \
  --database 
DATABASE_NAME
\
"SELECT * FROM home ORDER BY time"
  • Copy
  • Fill window
influxdb3 query \
  --database 
DATABASE_NAME
\
--language influxql \ "SELECT * FROM home"
  • Copy
  • Fill window

Replace DATABASE_NAME with the name of the database to query.

To query from a specific time range, use the WHERE clause to designate the boundaries of your time range.

influxdb3 query \
  --database 
DATABASE_NAME
\
"SELECT * FROM home WHERE time >= now() - INTERVAL '7 days' ORDER BY time"
  • Copy
  • Fill window
influxdb3 query \
  --database 
DATABASE_NAME
\
--language influxql \ "SELECT * FROM home WHERE time >= now() - 7d"
  • Copy
  • Fill window

Example queries

List tables in a database

Return the average temperature of all rooms

Return the average temperature of the kitchen

Query data from an absolute time range

Query data from a relative time range

Calculate average humidity in 3-hour windows per room

Other tools for executing queries

Other tools are available for querying data in InfluxDB 3 Enterprise, including the following:

Query using the API

Query using the Python client

Query using InfluxDB 3 Explorer

SQL vs InfluxQL

InfluxDB 3 Enterprise supports two query languages–SQL and InfluxQL. While these two query languages are similar, there are important differences to consider.

SQL

The InfluxDB 3 SQL implementation provides a full-featured SQL query engine powered by Apache DataFusion. InfluxDB extends DataFusion with additional time series-specific functionality and supports the complex SQL queries, including queries that use joins, unions, window functions, and more.

InfluxQL

InfluxQL is a SQL-like query language built for InfluxDB v1 and supported in InfluxDB 3 Enterprise. Its syntax and functionality is similar SQL, but specifically designed for querying time series data. InfluxQL does not offer the full range of query functionality that SQL does.

If you are migrating from previous versions of InfluxDB, you can continue to use InfluxQL and the established InfluxQL-related APIs you have been using.

Optimize queries

InfluxDB 3 Enterprise provides the following optimization options to improve specific kinds of queries:

Last values cache

The InfluxDB 3 Enterprise last values cache (LVC) stores the last N values in a series or column hierarchy in memory. This gives the database the ability to answer these kinds of queries in under 10 milliseconds. For information about configuring and using the LVC, see:

Distinct values cache

The InfluxDB 3 Enterprise distinct values cache (DVC) stores distinct values for specified columns in a series or column hierarchy in memory. This is useful for fast metadata lookups, which can return in under 30 milliseconds. For information about configuring and using the DVC, see:

File indexes

InfluxDB 3 Enterprise lets you customize how your data is indexed to help optimize query performance for your specific workload, especially workloads that include single-series queries. Define custom indexing strategies for databases or specific tables. For more information, see Manage file indexes.


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

New in InfluxDB 3.2

Key enhancements in InfluxDB 3.2 and the InfluxDB 3 Explorer UI is now generally available.

See the Blog Post

InfluxDB 3.2 is now available for both Core and Enterprise, bringing the general availability of InfluxDB 3 Explorer, a new UI that simplifies how you query, explore, and visualize data. On top of that, InfluxDB 3.2 includes a wide range of performance improvements, feature updates, and bug fixes including automated data retention and more.

For more information, check out: