Skip to content

Commit

Permalink
Merge branch 'master' of github.com:influxdata/docs-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderson committed Nov 16, 2022
2 parents 488125b + d74b856 commit eaf677d
Show file tree
Hide file tree
Showing 60 changed files with 26,519 additions and 143 deletions.
1 change: 1 addition & 0 deletions assets/styles/layouts/_article.scss
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"article/flux",
"article/html-diagrams",
"article/influxdbu",
"article/influxql",
"article/keybinding",
"article/list-filters",
"article/lists",
Expand Down
9 changes: 9 additions & 0 deletions assets/styles/layouts/article/_influxql.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.influxql-table-meta p {
font-size: .9rem;
line-height: 1.25rem;
&:last-child {margin-bottom: 0rem}
}

table + .influxql-table-meta {
margin-top:-1.5rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Because InfluxQL uses the 1.x data model, a bucket must be mapped to a database

{{% note %}}
#### InfluxQL reference documentation

For complete InfluxQL reference documentation, see
[Influx Query Language in the latest InfluxDB 1.x documentation](/{{< latest "influxdb" "v1" >}}/query_language/).
{{% /note %}}
Expand All @@ -41,8 +42,7 @@ For more information, see [Database and retention policy mapping](/influxdb/v2.1
If you're not sure how data was written into a bucket, verify the bucket has a mapping.
{{% /note %}}

Use the [`influx` CLI](/influxdb/v2.1/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2.1/reference/api/)
to verify the buckets you want to query are mapped to a database and retention policy.
Use the [`influx` CLI](/influxdb/v2.1/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2.1/reference/api/) to verify the buckets you want to query are mapped to a database and retention policy.

{{< tabs-wrapper >}}
{{% tabs %}}
Expand Down Expand Up @@ -116,13 +116,14 @@ If you **do not find a DBRP mapping for a bucket**, complete the next procedure
_For more information on the DBRP mapping API, see the [`/api/v2/dbrps` endpoint documentation](/influxdb/v2.1/api/#tag/DBRPs)._

## Map unmapped buckets
Use the [`influx` CLI](/influxdb/v2.1/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2.1/reference/api/)
to manually create DBRP mappings for unmapped buckets.

Use the [`influx` CLI](/influxdb/v2.1/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2.1/reference/api/) to manually create DBRP mappings for unmapped buckets.

{{< tabs-wrapper >}}
{{% tabs %}}
[influx CLI](#)
[InfluxDB API](#)

{{% /tabs %}}
{{% tab-content %}}

Expand Down Expand Up @@ -245,6 +246,7 @@ To learn more about InfluxQL, see [Influx Query Language (InfluxQL)](/{{< latest
- `GRANT`
- `KILL`
- `REVOKE`
- `SHOW SERIES CARDINALITY`
{{% /warn %}}
{{< /flex-content >}}
{{< /flex >}}
120 changes: 60 additions & 60 deletions content/influxdb/v2.4/query-data/influxql/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,78 @@ menu:
influxdb_2_4:
name: Query with InfluxQL
parent: Query data
cascade:
related:
- /influxdb/v2.4/reference/api/influxdb-1x/
- /influxdb/v2.4/reference/api/influxdb-1x/query
- /influxdb/v2.4/reference/api/influxdb-1x/dbrp
- /influxdb/v2.4/tools/influxql-shell/
related:
- /influxdb/v2.4/reference/api/influxdb-1x/
- /influxdb/v2.4/reference/api/influxdb-1x/query
- /influxdb/v2.4/reference/api/influxdb-1x/dbrp
- /influxdb/v2.4/tools/influxql-shell/
---

Use InfluxQL (an SQL-like query language) to interact with InfluxDB, and query and analyze your times series data.

In InfluxDB 1.x, data is stored in [databases](/{{< latest "influxdb" "v1" >}}/concepts/glossary/#database)
and [retention policies](/{{< latest "influxdb" "v1" >}}/concepts/glossary/#retention-policy-rp).
InfluxDB {{< current-version >}} combines and replaces database and retention
policies with [buckets](/influxdb/v2.4/reference/glossary/#bucket).
Because InfluxQL uses the 1.x data model, a database and retention policy combination
(DBRP) must be mapped to a bucket before it can be queried using InfluxQL.

{{% note %}}
#### InfluxQL reference documentation
For complete InfluxQL reference documentation, see
[Influx Query Language in the latest InfluxDB 1.x documentation](/{{< latest "influxdb" "v1" >}}/query_language/).
{{% /note %}}
In InfluxDB OSS {{< current-version >}}, data is stored in [buckets](/influxdb/v2.4/reference/glossary/#bucket).
Because InfluxQL uses the 1.x data model, a bucket must be mapped to a database and retention policy (DBRP) before it can be queried using InfluxQL.

**To use InfluxQL to query bucket data, complete the following steps:**
**To query data with InfluxQL, complete the following steps:**

1. [Verify buckets have a mapping](#verify-buckets-have-a-mapping).
2. [Create DBRP mappings for unmapped buckets](#create-dbrp-mappings-for-unmapped-buckets).
3. [Query a mapped bucket with InfluxQL](#query-a-mapped-bucket-with-influxql).

{{% note %}}

#### InfluxQL reference documentation

For complete InfluxQL reference documentation, see the
[InfluxQL specification for InfluxDB 2.x](/influxdb/v2.4/reference/syntax/influxql/spec/).
{{% /note %}}

## Verify buckets have a mapping

Use the [`influx` CLI](/influxdb/v2.4/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2.4/reference/api/)
to verify the buckets you want to query are mapped to a database and retention policy.
1. To verify the buckets you want to query are mapped to a database and retention policy, use the [`influx` CLI](/influxdb/v2.4/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2.4/reference/api/).
_For examples, see [List DBRP mappings](/influxdb/v2.4/query-data/influxql/dbrp/#list-dbrp-mappings)._

If you **do not find a DBRP mapping for a bucket**, [create a new DBRP mapping]() to
2. If you **do not find a DBRP mapping for a bucket**, [create a new DBRP mapping](/influxdb/v2.4/query-data/influxql/dbrp/#create-dbrp-mappings) to
map the unmapped bucket.

## Create DBRP mappings for unmapped buckets
Use the [`influx` CLI](/influxdb/v2.4/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2.4/reference/api/)

- Use the [`influx` CLI](/influxdb/v2.4/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2.4/reference/api/)
to manually create DBRP mappings for unmapped buckets.
_For examples, see [Create DBRP mappings](/influxdb/v2.4/query-data/influxql/dbrp/#create-dbrp-mappings)._

## Query a mapped bucket with InfluxQL

{{< tabs-wrapper >}}
{{% tabs %}}
[InfluxQL Shell](#)
[InfluxQL shell](#)
[InfluxDB API](#)
{{% /tabs %}}
{{% tab-content %}}
<!---------------------------- BEGIN InfluxQL shell --------------------------->

The [`influx` CLI](/influxdb/v2.4/tools/influx-cli/) provides an InfluxQL shell
where you can execute InfluxQL queries in an interactive Read-Eval-Print-Loop (REPL).
The [`influx` CLI](/influxdb/v2.4/reference/cli/influx/) provides an [InfluxQL shell](/influxdb/v2.4/tools/influxql-shell/) where you can execute InfluxQL queries in an interactive Read-Eval-Print-Loop (REPL).

{{% note %}}
If you haven't already, be sure to do the following:
1. If you haven't already, do the following:

- [Download and install the `influx` CLI](/influxdb/v2.4/tools/influx-cli/#install-the-influx-cli)
- [Configure your authentication credentials](/influxdb/v2.4/tools/influx-cli/#provide-required-authentication-credentials)
{{% /note %}}
- [Download and install the `influx` CLI](/influxdb/v2.4/tools/influx-cli/#install-the-influx-cli)
- [Configure your authentication credentials](/influxdb/v2.4/tools/influx-cli/#provide-required-authentication-credentials)

Use the following command to start an InfluxQL shell:
2. Use the following command to start an InfluxQL shell:

```sh
influx v1 shell
```
```sh
influx v1 shell
```

Execute an InfluxQL query inside the InfluxQL shell.
3. Execute an InfluxQL query inside the InfluxQL shell.

```sql
> SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1
```
```sql
SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1
```

For more information about using the InfluxQL shell, see
[Use the InfluxQL shell](/influxdb/v2.4/tools/influxql-shell/).
For more information, see how to [use the InfluxQL shell](/influxdb/v2.4/tools/influxql-shell/). For more information about DBRP mappings, see [Manage DBRP mappings](/influxdb/v2.4/query-data/influxql/dbrp/).

<!----------------------------- END InfluxQL shell ---------------------------->
{{% /tab-content %}}
Expand All @@ -93,37 +90,36 @@ For more information about using the InfluxQL shell, see
The [InfluxDB 1.x compatibility API](/influxdb/v2.4/reference/api/influxdb-1x/) supports
all InfluxDB 1.x client libraries and integrations in InfluxDB {{< current-version >}}.

To query a mapped bucket with InfluxQL, use the [`/query` 1.x compatibility endpoint](/influxdb/v2.4/reference/api/influxdb-1x/query/).
Include the following in your request:
1. To query a mapped bucket with InfluxQL, use the [`/query` 1.x compatibility endpoint](/influxdb/v2.4/reference/api/influxdb-1x/query/), and include the following in your request:

- **Request method:** `GET`
- **Headers:**
- **Authorization:** _See [compatibility API authentication](/influxdb/v2.4/reference/api/influxdb-1x/#authentication)_
- **Query parameters:**
- **db**: 1.x database to query
- **rp**: 1.x retention policy to query _(if no retention policy is specified, InfluxDB uses the default retention policy for the specified database)_
- **q**: URL-encoded InfluxQL query

- **Request method:** `GET`
- **Headers:**
- **Authorization:** _See [compatibility API authentication](/influxdb/v2.4/reference/api/influxdb-1x/#authentication)_
- **Query parameters:**
- **db**: 1.x database to query
- **rp**: 1.x retention policy to query _(if no retention policy is specified, InfluxDB uses the default retention policy for the specified database)_
- **q**: URL-encoded InfluxQL query
{{% api/url-encode-note %}}

{{% api/url-encode-note %}}
```sh
curl --get http://localhost:8086/query?db=example-db \
--header "Authorization: Token YourAuthToken" \
--data-urlencode "q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1"
```

```sh
curl --get http://localhost:8086/query?db=example-db \
--header "Authorization: Token YourAuthToken" \
--data-urlencode "q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1"
```
By default, the `/query` compatibility endpoint returns results in **JSON**.

By default, the `/query` compatibility endpoint returns results in **JSON**.
To return results as **CSV**, include the `Accept: application/csv` header.
2. (Optional) To return results as **CSV**, include the `Accept: application/csv` header.

For more information about DBRP mappings, see [Manage DBRP mappings](/influxdb/v2.4/query-data/influxql/dbrp/).
<!------------------------------ END InfluxDB API ----------------------------->
{{% /tab-content %}}
{{< /tabs-wrapper >}}

## InfluxQL support

InfluxDB {{< current-version >}} supports InfluxQL queries.
See supported and unsupported queries below.
To learn more about InfluxQL, see [Influx Query Language (InfluxQL)](/{{< latest "influxdb" "v1" >}}/query_language/).
InfluxDB OSS 2.x supports the following InfluxQL statements and clauses. See supported and unsupported queries below.

{{< flex >}}
{{< flex-content >}}
Expand All @@ -135,10 +131,13 @@ To learn more about InfluxQL, see [Influx Query Language (InfluxQL)](/{{< latest
- `EXPLAIN ANALYZE`
- `SELECT` _(read-only)_
- `SHOW DATABASES`
- `SHOW SERIES`
- `SHOW MEASUREMENTS`
- `SHOW TAG KEYS`
- `SHOW TAG VALUES`
- `SHOW FIELD KEYS`
- `SHOW SERIES EXACT CARDINALITY`
- `SHOW TAG KEY CARDINALITY`
- `SHOW FIELD KEY CARDINALITY`

\* These commands delete data.
{{% /note %}}
Expand All @@ -155,6 +154,7 @@ To learn more about InfluxQL, see [Influx Query Language (InfluxQL)](/{{< latest
- `GRANT`
- `KILL`
- `REVOKE`
- `SHOW SERIES CARDINALITY`
{{% /warn %}}
{{< /flex-content >}}
{{< /flex >}}
6 changes: 3 additions & 3 deletions content/influxdb/v2.4/query-data/influxql/dbrp.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ description: >
menu:
influxdb_2_4:
parent: Query with InfluxQL
weight: 202
weight: 201
influxdb/v2.4/tags: [influxql, dbrp]
---

InfluxQL requires a database and retention policy (DBRP) combination to query data from.
InfluxQL requires a database and retention policy (DBRP) combination in order to query data.
In InfluxDB {{< current-version >}}, databases and retention policies have been
combined and replaced by InfluxDB [buckets](/influxdb/v2.4/reference/glossary/#bucket).
To query an InfluxDB {{< current-version >}} with InfluxQL, the specified DBRP
To query InfluxDB {{< current-version >}} with InfluxQL, the specified DBRP
combination must be mapped to a bucket.

- [Automatic DBRP mapping](#automatic-dbrp-mapping)
Expand Down
73 changes: 73 additions & 0 deletions content/influxdb/v2.4/query-data/influxql/explore-data/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
title: Explore data using InfluxQL
description: >
Explore time series data using InfluxQL, InfluxData's SQL-like query language.
Use the `SELECT` statement to query data from measurements, tags, and fields.
menu:
influxdb_2_4:
name: Explore data
parent: Query with InfluxQL
weight: 202
---

To start exploring data with InfluxQL, do the following:

1. Verify your bucket has a database and retention policy (DBRP) mapping by [listing DBRP mappings for your bucket](/influxdb/v2.4/query-data/influxql/dbrp/#list-dbrp-mappings). If not, [create a new DBRP mapping](/influxdb/v2.4/query-data/influxql/dbrp/#create-dbrp-mappings).

2. [Configure timestamps in the InfluxQL shell](/influxdb/v2.4/query-data/influxql/explore-data/time-and-timezone/).

3. _(Optional)_ If you would like to use the data used in the examples below, [download the NOAA sample data](#download-sample-data).

4. Use the InfluxQL `SELECT` statement with other key clauses to explore your data.

{{< children type="anchored-list" >}}

{{< children readmore=true hr=true >}}

## Download sample data

The example InfluxQL queries in this documentation use publicly available [National Oceanic and Atmospheric Administration (NOAA)](https://www.noaa.gov/) data.

To download a subset of NOAA data used in examples, run the script under [NOAA water sample data](/influxdb/v2.4/reference/sample-data/#noaa-water-sample-data) (for example, copy and paste the script into your Data Explorer - Script Editor), and replace "example-org" in the script with the name of your InfluxDB organization.

Let's get acquainted with this subsample of the data in the `h2o_feet` measurement:

Output:
{{% influxql/table-meta %}}
Name: h2o_feet
{{% /influxql/table-meta %}}

|time | level description | location | water_level |
| :------------------- | :------------------ | :----------------------- |----------------------:|
| 2019-08-18T00:00:00Z | between 6 and 9 feet |coyote_creek | 8.1200000000 |
| 2019-08-18T00:00:00Z | below 3 feet | santa_monica | 2.0640000000 |
| 2019-08-18T00:06:00Z | between 6 and 9 feet | coyote_creek | 8.0050000000 |
| 2019-08-18T00:06:00Z | below 3 feet| santa_monica | 2.1160000000 |
| 2019-08-18T00:12:00Z | between 6 and 9 feet| coyote_creek | 7.8870000000 |
| 2019-08-18T00:12:00Z | below 3 feet | santa_monica | 2.0280000000 |
The data in the `h2o_feet` [measurement](/influxdb/v2.4/reference/glossary/#measurement)
occurs at six-minute time intervals.
This measurement has one [tag key](/influxdb/v2.4/reference/glossary/#tag-key)
(`location`) which has two [tag values](/influxdb/v2.4/reference/glossary/#tag-value):
`coyote_creek` and `santa_monica`.
The measurement also has two [fields](/influxdb/v2.4/reference/glossary/#field):
`level description` stores string [field values](/influxdb/v2.4/reference/glossary/#field-value)
and `water_level` stores float field values.


### Configure timestamps in the InfluxQL shell

By default, the [InfluxQL shell](/influxdb/v2.4/tools/influxql-shell/) returns timestamps in
nanosecond UNIX epoch format by default.
To return human-readable RFC3339 timestamps instead of Unix nanosecond timestamps,
use the [precision helper command](/influxdb/v2.4/tools/influxql-shell/#precision) ` to configure
the timestamp format:

```sql
precision rfc3339
```

The [InfluxDB API](/influxdb/v2.4/reference/api/influxdb-1x/) returns timestamps
in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) format by default.
Specify alternative formats with the [`epoch` query string parameter](/influxdb/v2.4/reference/api/influxdb-1x/).
Loading

0 comments on commit eaf677d

Please sign in to comment.