Documentation

Get started querying data

InfluxDB Cloud Serverless supports multiple query languages:

  • SQL: Traditional SQL powered by the Apache Arrow DataFusion query engine. The supported SQL syntax is similar to PostgreSQL.
  • InfluxQL: An SQL-like query language designed to query time series data stored in InfluxDB.

This tutorial walks you through the fundamentals of querying data in InfluxDB and focuses on using SQL to query your time series data. The InfluxDB SQL implementation is built using Arrow Flight SQL, a protocol for interacting with SQL databases using the Arrow in-memory format and the Flight RPC framework. It leverages the performance of Apache Arrow with the simplicity of SQL.

The examples in this section of the tutorial query the get-started bucket for data written in the Get started writing data section.

Tools to execute queries

InfluxDB Cloud Serverless supports many different tools for querying data, including:

* Covered in this tutorial

Avoid using /api/v2/query

Avoid using the /api/v2/query API endpoint and associated tooling, such as the influx query CLI command and > InfluxDB v2 client libraries, with InfluxDB Cloud Serverless.

SQL query basics

The InfluxDB Cloud Serverless SQL implementation is powered by the Apache Arrow DataFusion query engine which provides an SQL syntax similar to PostgreSQL.

This is a brief introduction to writing SQL queries for InfluxDB. For more in-depth details, see Query data with SQL.

InfluxDB SQL queries most commonly include the following clauses:

* Required
  • * SELECT: Identify specific fields and tags to query from a measurement or use the wildcard alias (*) to select all fields and tags from a measurement.
  • * FROM: Identify the measurement to query. If coming from an 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.
-- Return the average temperature and humidity within time bounds from each room
SELECT
  avg(temp),
  avg(hum),
  room
FROM
  home
WHERE
  time >= '2025-06-14T08:00:00Z'
  AND time <= '2025-06-14T20:00:00Z'
GROUP BY
  room
  • Copy
  • Fill window

Example SQL queries

Select all data in a measurement
SELECT * FROM home
  • Copy
  • Fill window
Select all data in a measurement within time bounds
SELECT
  *
FROM
  home
WHERE
  time >= '2025-06-14T08:00:00Z'
  AND time <= '2025-06-14T20:00:00Z'
  • Copy
  • Fill window
Select a specific field within relative time bounds
SELECT temp FROM home WHERE time >= now() - INTERVAL '1 day'
  • Copy
  • Fill window
Select specific fields and tags from a measurement
SELECT temp, room FROM home
  • Copy
  • Fill window
Select data based on tag value
SELECT * FROM home WHERE room = 'Kitchen'
  • Copy
  • Fill window
Select data based on tag value within time bounds
SELECT
  *
FROM
  home
WHERE
  time >= '2025-06-14T08:00:00Z'
  AND time <= '2025-06-14T20:00:00Z'
  AND room = 'Living Room'
  • Copy
  • Fill window
Downsample data by applying interval-based aggregates
SELECT
  DATE_BIN(INTERVAL '1 hour', time, '2025-06-14T00:00:00Z') as _time,
  room,
  selector_max(temp, time)['value'] AS 'max temp'
FROM
  home
GROUP BY
  _time,
  'max temp',
  room
ORDER BY room, _time
  • Copy
  • Fill window

Execute an SQL query

Get started with one of the following tools for querying data stored in an InfluxDB Cloud Serverless bucket:

  • InfluxDB UI: View your schema, build queries using the query editor, and generate data visualizations.
  • InfluxDB 3 client libraries: Use language-specific (Python, Go, etc.) clients to execute queries in your terminal or custom code.
  • influx3 data CLI: Send queries from your terminal command-line.
  • Grafana: Use the FlightSQL Data Source plugin, to query, connect, and visualize data.

Avoid using /api/v2/query

Avoid using the /api/v2/query API endpoint in InfluxDB Cloud Serverless and associated tooling, such as the influx > query CLI command and InfluxDB v2 client libraries. You can’t use SQL or InfluxQL with these tools.

For this example, use the following query to select all the data written to the get-started bucket between 2025-06-14T08:00:00Z and 2025-06-14T20:00:00Z.

SELECT
  *
FROM
  home
WHERE
  time >= '2025-06-14T08:00:00Z'
  AND time <= '2025-06-14T20:00:00Z'
  • Copy
  • Fill window

Some examples in this getting started tutorial assume your InfluxDB credentials (URL, organization, and token) are provided by environment variables.

  1. In the influxdb_csharp_client directory you created in the Write data section, create a new file named Query.cs.

  2. In Query.cs, enter the following sample code:

    // Query.cs
    
    using System;
    using System.Threading.Tasks;
    using InfluxDB3.Client;
    using InfluxDB3.Client.Query;
    
    namespace InfluxDBv3;
    
    public class Query
    {
      /**
        * Queries an InfluxDB database (bucket) using the C# .NET client
        * library.
        **/
      public static async Task QuerySQL()
      {
        /** INFLUX_TOKEN is an environment variable you assigned to your
          * API READ token value.
          **/
        string? token = System.Environment
            .GetEnvironmentVariable("INFLUX_TOKEN");
    
        /**
          * Instantiate the InfluxDB client with credentials.
          **/
        using var client = new InfluxDBClient(
            "https://cloud2.influxdata.com", token: token, database: database);
    
        const string sql = @"
          SELECT time, room, temp, hum, co
          FROM home
          WHERE time >= '2025-06-14T08:00:00Z'
          AND time <= '2025-06-14T20:00:00Z'
        ";
    
        Console.WriteLine("{0,-30}{1,-15}{2,-15}{3,-15}{4,-15}",
            "time", "room", "co", "hum", "temp");
    
        await foreach (var row in client.Query(query: sql))
        {
          {
            /** 
              * Iterate over rows and print column values in table format.
              * Format the timestamp as sortable UTC format.
              */
            Console.WriteLine("{0,-30:u}{1,-15}{4,-15}{3,-15}{2,-15}",
                row[0], row[1], row[2], row[3], row[4]);
          }
        }
        Console.WriteLine();
      }
    }
    
    • Copy
    • Fill window

    The sample code does the following:

    1. Imports the following classes:

      • System
      • System.Threading.Tasks;
      • InfluxDB3.Client;
      • InfluxDB3.Client.Query;
    2. Defines a Query class with a QuerySQL() method that does the following:

      1. Calls the new InfluxDBClient() constructor to instantiate a client configured with InfluxDB credentials.

        • host: your InfluxDB Cloud Serverless region URL.
        • token: an API token with read permission on the specified bucket. Store this in a secret store or environment variable to avoid exposing the raw token string.
        • database: the name of the InfluxDB Cloud Serverless bucket to query
      2. Defines a string variable for the SQL query.

      3. Calls the InfluxDBClient.Query() method to send the query request with the SQL string. Query() returns batches of rows from the response stream as a two-dimensional array–an array of rows in which each row is an array of values.

      4. Iterates over rows and prints the data in table format to stdout.

  3. In your editor, open the Program.cs file you created in the Write data section and insert code to call the Query() function–for example:

    // Program.cs
    
    using System;
    using System.Threading.Tasks;
    
    namespace InfluxDBv3;
    
    public class Program
    {
      public static async Task Main()
      {
        await Write.WriteLineProtocol();
        await Query.QuerySQL();
      }
    }
    
    • Copy
    • Fill window
  4. To build and execute the program and query InfluxDB Cloud Serverless, enter the following commands in your terminal:

    dotnet run
    
    • Copy
    • Fill window

Query results

View 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 Cloud Serverless, see the Query data in InfluxDB section of documentation.


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

Now Generally Available

InfluxDB 3 Core and Enterprise

Start fast. Scale faster.

Get the Updates

InfluxDB 3 Core is an open source, high-speed, recent-data engine that collects and processes data in real-time and persists it to local disk or object storage. InfluxDB 3 Enterprise builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries and optimized storage. A free tier of InfluxDB 3 Enterprise is available for non-commercial at-home or hobbyist use.

For more information, check out:

InfluxDB Cloud Serverless