Skip to content

Commit 6607728

Browse files
committed
WIP get started query
1 parent 821dcd4 commit 6607728

File tree

1 file changed

+197
-47
lines changed
  • content/shared/influxdb3-get-started

1 file changed

+197
-47
lines changed

content/shared/influxdb3-get-started/query.md

Lines changed: 197 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,41 @@ run the following command:
4343
{{% /code-tabs %}}
4444
{{% code-tab-content %}}
4545

46+
<!-- pytest.mark.skip -->
47+
```bash
48+
influxdb3 query \
49+
--database DATABASE_NAME \
50+
"SELECT * FROM home ORDER BY time"
51+
```
52+
{{% /code-tab-content %}}
53+
{{% code-tab-content %}}
54+
<!-- pytest.mark.skip -->
55+
```bash
56+
influxdb3 query \
57+
--database DATABASE_NAME \
58+
--language influxql \
59+
"SELECT * FROM home"
60+
```
61+
{{% /code-tab-content %}}
62+
{{< /code-tabs-wrapper >}}
63+
64+
{{% /code-placeholders %}}
65+
66+
_Replace {{% code-placeholder-key %}}`DATABASE_NAME`{{% /code-placeholder-key %}}
67+
with the name of the database to query._
68+
69+
To query from a specific time range, use the `WHERE` clause to designate the
70+
boundaries of your time range.
71+
72+
{{% code-placeholders "DATABASE_NAME|AUTH_TOKEN" %}}
73+
74+
{{< code-tabs-wrapper >}}
75+
{{% code-tabs %}}
76+
[SQL](#)
77+
[InfluxQL](#)
78+
{{% /code-tabs %}}
79+
{{% code-tab-content %}}
80+
4681
<!-- pytest.mark.skip -->
4782
```bash
4883
influxdb3 query \
@@ -63,66 +98,181 @@ influxdb3 query \
6398

6499
{{% /code-placeholders %}}
65100

66-
Replace {{% code-placeholder-key %}}`DATABASE_NAME`{{% /code-placeholder-key %}}
67-
with the name of the database to query.
101+
## Example queries
68102

103+
{{< expand-wrapper >}}
104+
{{% expand "List tables in a database" %}}
69105

70-
#### Example: query `“SHOW TABLES”` on the `servers` database:
106+
{{< code-tabs-wrapper >}}
107+
{{% code-tabs %}}
108+
[SQL](#)
109+
[InfluxQL](#)
110+
{{% /code-tabs %}}
111+
{{% code-tab-content %}}
112+
```sql
113+
SHOW TABLES
114+
```
115+
{{% /code-tab-content %}}
116+
{{% code-tab-content %}}
117+
```sql
118+
SHOW MEASUREMENTS
119+
```
120+
{{% /code-tab-content %}}
121+
{{< /code-tabs-wrapper >}}
71122

72-
```console
73-
$ influxdb3 query --database servers "SHOW TABLES"
74-
+---------------+--------------------+--------------+------------+
75-
| table_catalog | table_schema | table_name | table_type |
76-
+---------------+--------------------+--------------+------------+
77-
| public | iox | cpu | BASE TABLE |
78-
| public | information_schema | tables | VIEW |
79-
| public | information_schema | views | VIEW |
80-
| public | information_schema | columns | VIEW |
81-
| public | information_schema | df_settings | VIEW |
82-
| public | information_schema | schemata | VIEW |
83-
+---------------+--------------------+--------------+------------+
123+
{{% /expand %}}
124+
{{% expand "Return the average temperature of all rooms" %}}
125+
126+
{{< code-tabs-wrapper >}}
127+
{{% code-tabs %}}
128+
[SQL](#)
129+
[InfluxQL](#)
130+
{{% /code-tabs %}}
131+
{{% code-tab-content %}}
132+
```sql
133+
SELECT avg(temp) AS avg_temp FROM home
134+
```
135+
{{% /code-tab-content %}}
136+
{{% code-tab-content %}}
137+
```sql
138+
SELECT MEAN(temp) AS avg_temp FROM home
84139
```
140+
{{% /code-tab-content %}}
141+
{{< /code-tabs-wrapper >}}
85142

86-
#### Example: query the `cpu` table, limiting to 10 rows:
87-
88-
```console
89-
$ influxdb3 query --database servers "SELECT DISTINCT usage_percent, time FROM cpu LIMIT 10"
90-
+---------------+---------------------+
91-
| usage_percent | time |
92-
+---------------+---------------------+
93-
| 63.4 | 2024-02-21T19:25:00 |
94-
| 25.3 | 2024-02-21T19:06:40 |
95-
| 26.5 | 2024-02-21T19:31:40 |
96-
| 70.1 | 2024-02-21T19:03:20 |
97-
| 83.7 | 2024-02-21T19:30:00 |
98-
| 55.2 | 2024-02-21T19:00:00 |
99-
| 80.5 | 2024-02-21T19:05:00 |
100-
| 60.2 | 2024-02-21T19:33:20 |
101-
| 20.5 | 2024-02-21T18:58:20 |
102-
| 85.2 | 2024-02-21T19:28:20 |
103-
+---------------+---------------------+
143+
{{% /expand %}}
144+
{{% expand "Return the average temperature of the kitchen" %}}
145+
146+
{{< code-tabs-wrapper >}}
147+
{{% code-tabs %}}
148+
[SQL](#)
149+
[InfluxQL](#)
150+
{{% /code-tabs %}}
151+
{{% code-tab-content %}}
152+
```sql
153+
SELECT avg(temp) AS avg_temp FROM home WHERE room = 'Kitchen'
154+
```
155+
{{% /code-tab-content %}}
156+
{{% code-tab-content %}}
157+
```sql
158+
SELECT MEAN(temp) AS avg_temp FROM home WHERE room = 'Kitchen'
104159
```
160+
{{% /code-tab-content %}}
161+
{{< /code-tabs-wrapper >}}
105162

106-
### Query using the CLI for InfluxQL
163+
{{% /expand %}}
164+
{{% expand "Query data from an absolute time range" %}}
107165

108-
[InfluxQL](/influxdb3/version/reference/influxql/) is an SQL-like language developed by InfluxData with specific features tailored for leveraging and working with InfluxDB. It’s compatible with all versions of InfluxDB, making it a good choice for interoperability across different InfluxDB installations.
166+
{{% influxdb/custom-timestamps %}}
109167

110-
To query using InfluxQL, enter the `influxdb3 query` subcommand and specify `influxql` in the language option--for example:
168+
{{< code-tabs-wrapper >}}
169+
{{% code-tabs %}}
170+
[SQL](#)
171+
[InfluxQL](#)
172+
{{% /code-tabs %}}
173+
{{% code-tab-content %}}
174+
```sql
175+
SELECT
176+
*
177+
FROM
178+
home
179+
WHERE
180+
time >= '2022-01-01T12:00:00Z'
181+
AND time <= '2022-01-01T18:00:00Z'
182+
```
183+
{{% /code-tab-content %}}
184+
{{% code-tab-content %}}
185+
```sql
186+
SELECT
187+
*
188+
FROM
189+
home
190+
WHERE
191+
time >= '2022-01-01T12:00:00Z'
192+
AND time <= '2022-01-01T18:00:00Z'
193+
```
194+
{{% /code-tab-content %}}
195+
{{< /code-tabs-wrapper >}}
111196

112-
{{% code-placeholders "DATABASE_NAME|AUTH_TOKEN" %}}
113-
```bash
114-
influxdb3 query \
115-
--database DATABASE_NAME \
116-
--token <AUTH_TOKEN> \
117-
--language influxql \
118-
"SELECT DISTINCT usage_percent FROM cpu WHERE time >= now() - 1d"
197+
{{% /influxdb/custom-timestamps %}}
198+
199+
{{% /expand %}}
200+
{{% expand "Query data from a relative time range" %}}
201+
202+
{{< code-tabs-wrapper >}}
203+
{{% code-tabs %}}
204+
[SQL](#)
205+
[InfluxQL](#)
206+
{{% /code-tabs %}}
207+
{{% code-tab-content %}}
208+
```sql
209+
SELECT
210+
*
211+
FROM
212+
home
213+
WHERE
214+
time >= now() - INTERVAL '7 days'
119215
```
120-
{{% /code-placeholders %}}
216+
{{% /code-tab-content %}}
217+
{{% code-tab-content %}}
218+
```sql
219+
SELECT
220+
*
221+
FROM
222+
home
223+
WHERE
224+
time >= now() - 7d
225+
```
226+
{{% /code-tab-content %}}
227+
{{< /code-tabs-wrapper >}}
121228

122-
Replace the following placeholders with your values:
229+
{{% /expand %}}
230+
{{% expand "Calculate average humidity in 3-hour windows per room" %}}
123231

124-
- {{% code-placeholder-key %}}`DATABASE_NAME`{{% /code-placeholder-key %}}: the name of the database to query
125-
- {{% code-placeholder-key %}}`AUTH_TOKEN`{{% /code-placeholder-key %}}: your {{% token-link "database" %}}{{% show-in "enterprise" %}} with permission to query the specified database{{% /show-in %}}
232+
{{< code-tabs-wrapper >}}
233+
{{% code-tabs %}}
234+
[SQL](#)
235+
[InfluxQL](#)
236+
{{% /code-tabs %}}
237+
{{% code-tab-content %}}
238+
```sql
239+
SELECT
240+
date_bin(INTERVAL '3 hours', time) AS time,
241+
room,
242+
avg(hum) AS avg_hum
243+
FROM
244+
home
245+
GROUP BY
246+
1,
247+
room
248+
ORDER BY
249+
room,
250+
1
251+
```
252+
{{% /code-tab-content %}}
253+
{{% code-tab-content %}}
254+
```sql
255+
SELECT
256+
MEAN(hum) AS avg_hum
257+
FROM
258+
home
259+
WHERE
260+
time >= '2022-01-01T08:00:00Z'
261+
AND time <= '2022-01-01T20:00:00Z'
262+
GROUP BY
263+
time(3h),
264+
room
265+
```
266+
{{% /code-tab-content %}}
267+
{{< /code-tabs-wrapper >}}
268+
269+
{{% /expand %}}
270+
{{< /expand-wrapper >}}
271+
272+
273+
## SQL vs InfluxQL
274+
275+
## LVC, DVC
126276

127277
### Query using the API
128278

0 commit comments

Comments
 (0)