3.9 KiB
title | description | weight | influxdb/v2.0/tags | menu | products | related | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Query data with InfluxQL | Use the [InfluxDB 1.x `/query` compatibility endpoint](/influxdb/v2.0/reference/api/influxdb-1x/query) to query data in InfluxDB 2.0 with **InfluxQL**. | 102 |
|
|
|
|
Use the InfluxDB 1.x /query
compatibility endpoint
to query data in InfluxDB 2.0 with InfluxQL.
The InfluxDB 1.x compatibility API supports
all InfluxDB 1.x client libraries and integrations in InfluxDB 2.0.
Provide the following:
- InfluxDB authentication token (See compatibility API authentication)
- db query parameter: 1.x database to query
- rp query parameter: 1.x retention policy to query
- q query parameter: InfluxQL query
{{% note %}} URL-encode the InfluxQL query to ensure it's formatted correctly when submitted to InfluxDB. {{% /note %}}
curl -G https://cloud2.influxdata.com/query?db=db&rp=rp \
-H "Authorization: Token YourAuthToken" \
--data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1"
By default, the /query
compatibility endpoint returns results in JSON.
To return results as CSV, include the Accept: application/csv
header.
Map a bucket to a database and retention policy
If you have an existing bucket that does't follow the database/retention-policy
naming convention, you must manually create a database and retention policy
mapping to query that bucket with the /query
compatibility API.
Use the using the /api/v2/dbrps
API endpoint to
manually create and manage DBRP mappings.
To manually create a DBRP mapping, provide the following:
- authentication token
- organization name or ID (organization or organization_id)
- target bucket ID (bucket_id)
- database to map
- retention policy to map
curl -XPOST https://cloud2.influxdata.com/api/v2/dbrps \
-H "Authorization: Token YourAuthToken" \
-H 'Content-type: application/json' \
-d '{
"organization": "example-org",
"bucket_id": "12ab34cd56ef",
"database": "example-db",
"retention_policy": "example-rp",
"default": true
}'
For more information, see the /api/v2/dbrps
endpoint documentation.
InfluxDB 2.0 combines the 1.x concept of databases and retention policies into buckets. To support InfluxDB 1.x query and write patterns in InfluxDB 2.0, databases and retention policies are mapped to buckets using the database and retention policy (DBRP) mapping service. See DBRP mapping for more information.
InfluxQL support
InfluxQL in InfluxDB 2.0 supports read-only queries.
{{< flex >}} {{< flex-content >}} {{% note %}}
Supported InfluxQL queries
SELECT
(read-only)SHOW DATABASES
SHOW MEASUREMENTS
SHOW TAG KEYS
SHOW TAG VALUES
SHOW FIELD KEYS
{{% /note %}} {{< /flex-content >}} {{< flex-content >}} {{% warn %}}
Unsupported InfluxQL queries
SELECT INTO
ALTER
CREATE
DELETE
DROP
GRANT
KILL
REVOKE
{{% /warn %}} {{< /flex-content >}} {{< /flex >}}
Use the InfluxDB 2.0 UI, CLI, and API to perform the following actions: