Query data with InfluxQL
Learn to use InfluxQL to query data stored in InfluxDB Clustered.
- Explore your schema with InfluxQL
- Perform a basic InfluxQL query
- Aggregate data with InfluxQL
- Troubleshoot InfluxQL errors
- Use parameterized queries with InfluxQL
Explore your schema with InfluxQL
Use InfluxQL SHOW
statements to return information about your data schema.
List measurements
SHOW MEASUREMENTS
List field keys in a measurement
SHOW FIELD KEYS FROM "measurement"
List tag keys in a measurement
SHOW TAG KEYS FROM "measurement"
List tag values for a specific tag key
SHOW TAG VALUES FROM "measurement" WITH KEY = "tag-key" WHERE time > now() - 1d
Perform a basic InfluxQL query
A basic InfluxQL query that queries data from InfluxDB most commonly includes SELECT
, FROM
, and WHERE
clauses.
SELECT temp, room FROM home WHERE time >= now() - 1d
Aggregate data with InfluxQL
Use InfluxQL aggregate and selector functions to perform aggregate operations on your time series data.
Aggregate fields by groups
SELECT
MEAN(temp) AS mean,
FIRST(hum) as first,
FROM home
GROUP BY tag
Aggregate by time-based intervals
SELECT
MEAN(temp),
sum(hum),
FROM home
WHERE time >= now() - 24h
GROUP BY time(1h),room
Troubleshoot InfluxQL errors
Learn how to troubleshoot and fix common InfluxQL errors.
Use parameterized queries with InfluxQL
Use parameterized queries to prevent injection attacks and make queries more reusable.
Using Go and the influxdb3-go client
// Use the $parameter syntax to reference parameters in a query.
// The following InfluxQL query contains $room and $min_time parameters.
query := `
SELECT * FROM home
WHERE time >= $min_time
AND temp >= $min_temp
AND room = $room`
// Assign parameter names to input values.
parameters := influxdb3.QueryParameters{
"room": "Kitchen",
"min_temp": 20.0,
"min_time": "2024-03-18 00:00:00.00",
}
// Call the client's function to query InfluxDB with parameters and the
// the InfluxQL QueryType.
iterator, err := client.QueryWithParameters(context.Background(),
query,
parameters,
influxdb3.WithQueryType(influxdb3.InfluxQL))
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:
Customers with an annual or support contract can contact InfluxData Support.