Get started querying data
InfluxDB Cloud backed by InfluxDB IOx supports multiple query languages:
- SQL: Traditional SQL powered by the Apache Arrow DataFusion query engine. The supported SQL syntax is similar to PostgreSQL.
- Flux: A functional scripting language designed to query and process data from InfluxDB and other data sources.
This tutorial walks you through the fundamentals of querying data in InfluxDB and focuses on using SQL to query your time series data.
The examples in this section of the tutorial query the data from written in the Get started writing data section.
Tools to execute queries
InfluxDB supports many different tools for querying data, including:
* Covered in this tutorial- InfluxDB user interface (UI)*
- InfluxDB HTTP API*
influx
CLI*- Superset
- Grafana
- Chronograf
- InfluxDB client libraries
SQL query basics
InfluxDB Cloud’s SQL implementation is powered by the Apache Arrow DataFusion query engine which provides a SQL syntax similar to PostgreSQL.
This is a brief introduction to writing SQL queries for InfluxDB. For more in-depth details, see the SQL reference documentation.
InfluxDB SQL queries most commonly include the following clauses:
* Required- *
SELECT
: Identify specific fields and tags to query from a measurement or use the wild card alias (*
) to select all fields and tags from a measurement. - *
FROM
: Identify the measurement to query. If coming from a SQL background, an InfluxDB measurement is the equivalent of a relational table. WHERE
: Only return data that meets defined conditions such as falling within a time range, containing specific tag values, etc.GROUP BY
: Group data into SQL partitions and apply an aggregate or selector function to each group.
Example SQL queries
Execute a SQL query
Use the InfluxDB UI, influx
CLI, or InfluxDB API to execute SQL queries.
For this example, use the following query to select all the data written to the
get-started bucket between
Go to cloud2.influxdata.com in a browser to log in and access the InfluxDB UI.
In the left navigation bar, click Data Explorer.
In the schema browser on the left, select the get-started bucket from the bucket drop-down menu. The displayed measurements and fields are read-only and are meant to show you the schema of data stored in the selected bucket.
Enter the SQL query in the text editor.
Click Run.
Results are displayed under the text editor.
The influx query
command
uses the InfluxDB /api/v2/query
endpoint to query InfluxDB.
This endpoint only accepts Flux queries. To use SQL with the influx
CLI, wrap
your SQL query in Flux and use iox.sql()
to query the InfluxDB IOx storage engine with SQL.
Provide the following:
- Bucket name with the
bucket
parameter - SQL query with the
query
parameter
If you haven’t already, download, install, and configure the
influx
CLI.Use the
influx query
command to query InfluxDB using Flux.Provide the following:
- String-encoded Flux query that uses
iox.sql()
to query the InfluxDB IOx storage engine with SQL. - Connection and authentication credentials
- String-encoded Flux query that uses
To query data from InfluxDB using SQL and the InfluxDB HTTP API, send a request
to the InfluxDB API /api/v2/query
endpoint
using the POST
request method.
POST http://localhost:8086/api/v2/query
The /api/v2/query
endpoint only accepts Flux queries.
To query data with SQL, wrap your SQL query in Flux and use iox.sql()
to query the InfluxDB IOx storage engine with SQL.
Provide the following:
- Bucket name with the
bucket
parameter - SQL query with the
query
parameter
Include the following with your request:
- Headers:
- Authorization: Token <INFLUX_TOKEN>
- Content-Type: application/vnd.flux
- Accept: application/csv
- (Optional) Accept-Encoding: gzip
- Request body: Flux query as plain text. In the Flux query, use
iox.sql()
and provide your bucket name and your SQL query.
The following example uses cURL and the InfluxDB API to query data with Flux:
The InfluxDB /api/v2/query
endpoint returns query results in
annotated CSV.
Query results
Congratulations! You’ve learned the basics of querying data in InfluxDB with SQL. For a deep dive into all the ways you can query InfluxDB, see the Query data in InfluxDB section of documentation.
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, use the following resources:
InfluxDB Cloud and InfluxDB Enterprise customers can contact InfluxData Support.