---
title: Use the influxctl CLI to query data
description: Use the influxctl query command to query data in InfluxDB Cloud Dedicated with SQL.
url: https://docs.influxdata.com/influxdb3/cloud-dedicated/query-data/execute-queries/influxctl-cli/
estimated_tokens: 5672
product: InfluxDB Cloud Dedicated
version: cloud-dedicated
---

# Use the influxctl CLI to query data

Use the [`influxctl query` command](/influxdb3/cloud-dedicated/reference/cli/influxctl/query/) to query data in InfluxDB Cloud Dedicated with SQL or InfluxQL.

Provide the following with your command:

-   **Database token**: A [database token](/influxdb3/cloud-dedicated/admin/tokens/#database-tokens) with read permissions on the queried database. By default, this uses the `database` setting from the [`influxctl` connection profile](/influxdb3/cloud-dedicated/reference/cli/influxctl/#configure-connection-profiles) or the `--token` command flag.
    
-   **Database name**: The name of the database to query. By default, this uses the `database` setting from the [`influxctl` connection profile](/influxdb3/cloud-dedicated/reference/cli/influxctl/#configure-connection-profiles) or the `--database` command flag.
    
-   **Query language** *(Optional)*: The query language of the query. Use the `--language` flag to specify one of the following query languages:
    
    -   `sql` *(default)*
    -   `influxql`
-   **Query**: SQL or InfluxQL query to execute. Pass the query in one of the following ways:
    
    -   a string on the command line
    -   a path to a file that contains the query
    -   a single dash (`-`) to read the query from stdin

<!-- Tabbed content: Select one of the following options -->

**SQL:**

<!-- Tabbed content: Select one of the following options -->

**string:**

```sh
influxctl query \
  --token DATABASE_TOKEN \
  --database DATABASE_NAME \
  "SELECT * FROM home"
```

**file:**

```sh
influxctl query \
  --token DATABASE_TOKEN \
  --database DATABASE_NAME \
  /path/to/query.sql
```

**stdin:**

```sh
cat ./query.sql | influxctl query \
  --token DATABASE_TOKEN \
  --database DATABASE_NAME \
  - 
```

<!-- End tabbed content -->

**InfluxQL:**

<!-- Tabbed content: Select one of the following options -->

**string:**

```sh
influxctl query \
  --token DATABASE_TOKEN \
  --database DATABASE_NAME \
  --language influxql \
  "SELECT * FROM home"
```

**file:**

```sh
influxctl query \
  --token DATABASE_TOKEN \
  --database DATABASE_NAME \
  --language influxql \
  /path/to/query.influxql
```

**stdin:**

```sh
cat ./query.influxql | influxctl query \
  --token DATABASE_TOKEN \
  --database DATABASE_NAME \
  --language influxql \
  - 
```

<!-- End tabbed content -->

<!-- End tabbed content -->

Replace the following:

-   `DATABASE_TOKEN`: Database token with read access to the queried database
-   `DATABASE_NAME`: Name of the database to query

## Query timeouts

The [`influxctl --timeout` global flag](/influxdb3/cloud-dedicated/reference/cli/influxctl/) sets the maximum duration for API calls, including query requests. If a query takes longer than the specified timeout, the operation will be canceled.

### Timeout examples

Use different timeout values based on your query type:

```sh
# Shorter timeout for testing dashboard queries (10 seconds)
influxctl query \
  --timeout 10s \
  --token DATABASE_TOKEN \
  --database DATABASE_NAME \
  "SELECT AVG(temperature) FROM sensors WHERE time >= now() - INTERVAL '1 day'"

# Longer timeout for analytical queries (5 minutes)
influxctl query \
  --timeout 5m \
  --token DATABASE_TOKEN \
  --database DATABASE_NAME \
  "SELECT room, AVG(temperature) FROM sensors WHERE time >= now() - INTERVAL '30 days' GROUP BY room"
```

For guidance on selecting appropriate timeout values, see [Query timeout best practices](/influxdb3/cloud-dedicated/query-data/troubleshoot-and-optimize/query-timeout-best-practices/).

## Output format

The `influxctl query` command supports the following output formats:

-   `table` *(default)*
-   `json`

Use the `--format` flag to specify the output format:

\`\`\`sh influxctl query \\ --format json \\ "SELECT \* FROM home WHERE time >= '2022-01-01T08:00:00Z' LIMIT 5" \`\`\`

[](#view-example-table-formatted-results)

View example table-formatted results

```
+-------+--------+---------+------+----------------------+
|    co |    hum | room    | temp | time                 |
+-------+--------+---------+------+----------------------+
|     0 |   35.9 | Kitchen |   21 | 2022-01-01T08:00:00Z |
|     0 |   36.2 | Kitchen |   23 | 2022-01-01T09:00:00Z |
|     0 |   36.1 | Kitchen | 22.7 | 2022-01-01T10:00:00Z |
|     0 |     36 | Kitchen | 22.4 | 2022-01-01T11:00:00Z |
|     0 |     36 | Kitchen | 22.5 | 2022-01-01T12:00:00Z |
+-------+--------+---------+------+----------------------+
| TOTAL | 5 ROWS |         |      |                      |
+-------+--------+---------+------+----------------------+
```

[](#view-example-json-formatted-results)

View example JSON-formatted results

```json
[
  {
    "co": 0,
    "hum": 35.9,
    "room": "Kitchen",
    "temp": 21,
    "time": 1641024000000000000
  },
  {
    "co": 0,
    "hum": 36.2,
    "room": "Kitchen",
    "temp": 23,
    "time": 1641027600000000000
  },
  {
    "co": 0,
    "hum": 36.1,
    "room": "Kitchen",
    "temp": 22.7,
    "time": 1641031200000000000
  },
  {
    "co": 0,
    "hum": 36,
    "room": "Kitchen",
    "temp": 22.4,
    "time": 1641034800000000000
  },
  {
    "co": 0,
    "hum": 36,
    "room": "Kitchen",
    "temp": 22.5,
    "time": 1641038400000000000
  }
]
```

## Timestamp format

When using the `table` [output format](#output-format), you can specify which of the following timestamp formats to use to display timestamp values in the query results:

-   `rfc3339nano`: *(Default)* [RFC3339Nano-formatted timestamp](/influxdb3/cloud-dedicated/reference/glossary/#rfc3339nano-timestamp)–for example: `2024-01-01T00:00:00.000000000Z`
-   `unixnano`: [Unix nanosecond timestamp](/influxdb3/cloud-dedicated/reference/glossary/#unix-timestamp)

\`\`\`sh influxctl query \\ --time-format unixnano \\ "SELECT \* FROM home WHERE time >= '2022-01-01T08:00:00Z' LIMIT 5" \`\`\`

[](#view-example-results-with-unix-nanosecond-timestamps)

View example results with Unix nanosecond timestamps

```
+-------+--------+---------+------+---------------------+
|    co |    hum | room    | temp |                time |
+-------+--------+---------+------+---------------------+
|     0 |   35.9 | Kitchen |   21 | 1641024000000000000 |
|     0 |   36.2 | Kitchen |   23 | 1641027600000000000 |
|     0 |   36.1 | Kitchen | 22.7 | 1641031200000000000 |
|     0 |     36 | Kitchen | 22.4 | 1641034800000000000 |
|     0 |     36 | Kitchen | 22.5 | 1641038400000000000 |
+-------+--------+---------+------+---------------------+
| TOTAL | 5 ROWS |         |      |                     |
+-------+--------+---------+------+---------------------+
```

#### Related

-   [influxctl query](/influxdb3/cloud-dedicated/reference/cli/influxctl/query/)
-   [Get started querying data](/influxdb3/cloud-dedicated/get-started/query/#execute-an-sql-query)
-   [Query timeout best practices](/influxdb3/cloud-dedicated/query-data/troubleshoot-and-optimize/query-timeout-best-practices/)
-   [SQL reference documentation](/influxdb3/cloud-dedicated/reference/sql/)
-   [InfluxQL reference documentation](/influxdb3/cloud-dedicated/reference/influxql/)
