Schema exploration using InfluxQL
Sample data
The data used in this document are available for download on the Sample Data page.
Before proceeding, login to the Influx CLI.
Returns a list of all on your instance.
Examples
Run a SHOW DATABASES query
> SHOW DATABASES
name: databases
name
----
NOAA_water_database
_internal
The query returns database names in a tabular format.This InfluxDB instance has two databases: NOAA_water_database
and _internal
.
SHOW RETENTION POLICIES
Returns a list of for the specified database.
Syntax
SHOW RETENTION POLICIES [ON <database_name>]
Description of syntax
ON <database_name>
is optional.If the query does not include ON <database_name>
, you must specify thedatabase with USE <database_name>
in the or with the db
querystring parameter in the InfluxDB API request.
Examples
Run a SHOW RETENTION POLICIES query with the ON clause
> SHOW RETENTION POLICIES ON NOAA_water_database
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 true
The query returns the list of retention policies in the NOAA_water_database
database in tabular format.The database has one retention policy called autogen
.The autogen
retention policy has an infinite ,a seven-day shard group duration,a of one, and it is the DEFAULT
retention policy for the database.
Run a SHOW RETENTION POLICIES query without the ON clause
Specify the database with USE <database_name>
> USE NOAA_water_database
Using database NOAA_water_database
> SHOW RETENTION POLICIES
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 true
Specify the database with the db
query string parameter:
~# curl -G "http://localhost:8086/query?db=NOAA_water_database&pretty=true" --data-urlencode "q=SHOW RETENTION POLICIES"
{
"results": [
{
"statement_id": 0,
"series": [
{
"columns": [
"name",
"duration",
"shardGroupDuration",
"replicaN",
"default"
],
"values": [
[
"autogen",
"0s",
"168h0m0s",
1,
true
]
]
}
]
}
]
}
Returns a list of forthe specified database.
Syntax
SHOW SERIES [ON <database_name>] [FROM_clause] [WHERE <tag_key> <operator> [ '<tag_value>' | <regular_expression>]] [LIMIT_clause] [OFFSET_clause]
Description of syntax
ON <database_name>
is optional.If the query does not include ON <database_name>
, you must specify thedatabase with USE <database_name>
in the or with the db
querystring parameter in the InfluxDB API request.
The FROM
, WHERE
, LIMIT
, and OFFSET
clauses are optional.The WHERE
clause supports tag comparisons; field comparisons are notvalid for the SHOW SERIES
query.
Supported operators in the WHERE
clause:=
equal to<>
not equal to!=
not equal to=~
matches against!~
doesn’t match against
See the Data Exploration page for documentation on the,LIMIT
clause,,and on Regular Expressions in Queries.
Run a SHOW SERIES query with the ON clause
// Returns series for all shards in the database
> SHOW SERIES ON NOAA_water_database
key
---
average_temperature,location=coyote_creek
average_temperature,location=santa_monica
h2o_feet,location=coyote_creek
h2o_feet,location=santa_monica
h2o_pH,location=coyote_creek
h2o_pH,location=santa_monica
h2o_quality,location=coyote_creek,randtag=1
h2o_quality,location=coyote_creek,randtag=2
h2o_quality,location=coyote_creek,randtag=3
h2o_quality,location=santa_monica,randtag=1
h2o_quality,location=santa_monica,randtag=2
h2o_quality,location=santa_monica,randtag=3
h2o_temperature,location=coyote_creek
h2o_temperature,location=santa_monica
The query’s output is similar to the line protocol format.Everything before the first comma is the name.Everything after the first comma is either a tag key or a .The NOAA_water_database
has five different measurements and 14 different series.
Run a SHOW SERIES query without the ON clause
Specify the database with USE <database_name>
> USE NOAA_water_database
Using database NOAA_water_database
> SHOW SERIES
key
---
average_temperature,location=coyote_creek
average_temperature,location=santa_monica
h2o_feet,location=coyote_creek
h2o_feet,location=santa_monica
h2o_pH,location=coyote_creek
h2o_pH,location=santa_monica
h2o_quality,location=coyote_creek,randtag=1
h2o_quality,location=coyote_creek,randtag=2
h2o_quality,location=coyote_creek,randtag=3
h2o_quality,location=santa_monica,randtag=1
h2o_quality,location=santa_monica,randtag=2
h2o_quality,location=santa_monica,randtag=3
h2o_temperature,location=coyote_creek
h2o_temperature,location=santa_monica
Specify the database with the db
query string parameter:
~# curl -G "http://localhost:8086/query?db=NOAA_water_database&pretty=true" --data-urlencode "q=SHOW SERIES"
{
"results": [
{
"statement_id": 0,
"series": [
{
"columns": [
"key"
],
"values": [
[
"average_temperature,location=coyote_creek"
],
[
"average_temperature,location=santa_monica"
],
[
"h2o_feet,location=coyote_creek"
],
[
"h2o_feet,location=santa_monica"
],
[
"h2o_pH,location=coyote_creek"
],
[
"h2o_pH,location=santa_monica"
],
[
"h2o_quality,location=coyote_creek,randtag=1"
],
[
"h2o_quality,location=coyote_creek,randtag=2"
],
[
"h2o_quality,location=coyote_creek,randtag=3"
],
[
"h2o_quality,location=santa_monica,randtag=1"
],
[
"h2o_quality,location=santa_monica,randtag=2"
],
[
"h2o_quality,location=santa_monica,randtag=3"
],
[
"h2o_temperature,location=coyote_creek"
],
[
"h2o_temperature,location=santa_monica"
]
]
}
]
}
]
}
Run a SHOW SERIES query with several clauses
> SHOW SERIES ON NOAA_water_database FROM "h2o_quality" WHERE "location" = 'coyote_creek' LIMIT 2
key
---
h2o_quality,location=coyote_creek,randtag=1
h2o_quality,location=coyote_creek,randtag=2
The query returns all series in the NOAA_water_database
database that areassociated with the h2o_quality
measurement and the tag location = coyote_creek
.The LIMIT
clause limits the number of series returned to two.
Run a SHOW SERIES query limited by time
Limit series returned within a specified shard group duration.
// Returns all series in the current shard.
> SHOW SERIES ON NOAA_water_database WHERE time < now() - 1m
key
---
average_temperature,location=coyote_creek
h2o_feet,location=coyote_creek
h2o_pH,location=coyote_creek
h2o_quality,location=coyote_creek,randtag=2
h2o_quality,location=coyote_creek,randtag=3
h2o_temperature,location=coyote_creek
The query above returns all series in the NOAA_water_database
database in the current shard group. The WHERE
clause limits results to series in the shard group that contain a timestamp in the last minute. Note, if a shard group duration is 7 days, results returned may be up to 7 days old.
Note, if the specified shard group duration is 7 days, the query above returns series for the last 3 or 4 shards.
SHOW MEASUREMENTS
Syntax
SHOW MEASUREMENTS [ON <database_name>] [WITH MEASUREMENT <operator> ['<measurement_name>' | <regular_expression>]] [WHERE <tag_key> <operator> ['<tag_value>' | <regular_expression>]] [LIMIT_clause] [OFFSET_clause]
Description of Syntax
ON <database_name>
is optional.If the query does not include ON <database_name>
, you must specify thedatabase with USE <database_name>
in the CLI or with the db
querystring parameter in the request.
The WITH
, WHERE
, LIMIT
and OFFSET
clauses are optional.The WHERE
clause supports tag comparisons; field comparisons are not valid for the SHOW MEASUREMENTS
query.
Supported operators in the WHERE
clause:=
equal to<>
not equal to!=
not equal to=~
matches against!~
doesn’t match against
See the Data Exploration page for documentation on theLIMIT
clause,,and on Regular expressions in queries.
Examples
Run a SHOW MEASUREMENTS query with the ON clause
> SHOW MEASUREMENTS ON NOAA_water_database
name: measurements
name
----
average_temperature
h2o_feet
h2o_pH
h2o_quality
h2o_temperature
The query returns the list of measurements in the NOAA_water_database
database.The database has five measurements: average_temperature
, h2o_feet
,h2o_pH
, h2o_quality
, and h2o_temperature
.
Run a SHOW MEASUREMENTS query without the ON clause
Specify the database with USE <database_name>
> USE NOAA_water_database
Using database NOAA_water_database
> SHOW MEASUREMENTS
name: measurements
name
----
h2o_feet
h2o_pH
h2o_quality
h2o_temperature
Specify the database with the db
query string parameter:
~# curl -G "http://localhost:8086/query?db=NOAA_water_database&pretty=true" --data-urlencode "q=SHOW MEASUREMENTS"
{
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "measurements",
"columns": [
"name"
],
"values": [
[
"average_temperature"
],
[
"h2o_feet"
],
[
"h2o_pH"
],
[
"h2o_quality"
],
[
"h2o_temperature"
]
]
}
]
}
]
}
Run a SHOW MEASUREMENTS query with several clauses (i)
> SHOW MEASUREMENTS ON NOAA_water_database WITH MEASUREMENT =~ /h2o.*/ LIMIT 2 OFFSET 1
name: measurements
name
----
h2o_pH
h2o_quality
The query returns the measurements in the NOAA_water_database
database thatstart with h2o
.The LIMIT
and OFFSET
clauses limit the number of measurement names returned totwo and offset the results by one, skipping the h2o_feet
measurement.
Run a SHOW MEASUREMENTS query with several clauses (ii)
> SHOW MEASUREMENTS ON NOAA_water_database WITH MEASUREMENT =~ /h2o.*/ WHERE "randtag" =~ /\d/
name: measurements
name
----
h2o_quality
The query returns all measurements in the NOAA_water_database
that startwith h2o
and have values for the tag key randtag
that include an integer.
Returns a list of tag keysassociated with the specified .
Syntax
SHOW TAG KEYS [ON <database_name>] [FROM_clause] [WHERE <tag_key> <operator> ['<tag_value>' | <regular_expression>]] [LIMIT_clause] [OFFSET_clause]
Description of syntax
ON <database_name>
is optional.If the query does not include ON <database_name>
, you must specify thedatabase with USE <database_name>
in the CLI or with the db
querystring parameter in the request.
The FROM
clause and the WHERE
clause are optional.The WHERE
clause supports tag comparisons; field comparisons are notvalid for the SHOW TAG KEYS
query.
Supported operators in the WHERE
clause:=
equal to<>
not equal to!=
not equal to=~
matches against!~
doesn’t match against
See the Data Exploration page for documentation on theFROM
clause,,OFFSET
clause,and on .
Examples
Run a SHOW TAG KEYS query with the ON clause
> SHOW TAG KEYS ON "NOAA_water_database"
name: average_temperature
tagKey
------
location
name: h2o_feet
tagKey
------
location
name: h2o_pH
tagKey
------
location
name: h2o_quality
tagKey
------
location
randtag
name: h2o_temperature
tagKey
------
location
The query returns the list of tag keys in the NOAA_water_database
database.The output groups tag keys by measurement name;it shows that every measurement has the location
tag key and that theh2o_quality
measurement has an additional randtag
tag key.
Run a SHOW TAG KEYS query without the ON clause
Specify the database with USE <database_name>
> USE NOAA_water_database
Using database NOAA_water_database
> SHOW TAG KEYS
name: average_temperature
tagKey
------
location
name: h2o_feet
tagKey
------
location
name: h2o_pH
tagKey
------
location
name: h2o_quality
tagKey
------
location
randtag
name: h2o_temperature
tagKey
------
location
Specify the database with the db
query string parameter:
~# curl -G "http://localhost:8086/query?db=NOAA_water_database&pretty=true" --data-urlencode "q=SHOW TAG KEYS"
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "average_temperature",
"columns": [
"tagKey"
],
"values": [
[
"location"
]
]
},
{
"name": "h2o_feet",
"columns": [
"tagKey"
],
"values": [
[
"location"
]
]
},
{
"name": "h2o_pH",
"columns": [
"tagKey"
],
"values": [
[
"location"
]
]
},
{
"name": "h2o_quality",
"columns": [
"tagKey"
],
"values": [
[
"location"
],
[
"randtag"
]
]
},
{
"name": "h2o_temperature",
"columns": [
"tagKey"
],
"values": [
[
"location"
]
]
}
]
}
]
}
Run a SHOW TAG KEYS query with several clauses
> SHOW TAG KEYS ON "NOAA_water_database" FROM "h2o_quality" LIMIT 1 OFFSET 1
name: h2o_quality
tagKey
------
randtag
The query returns tag keys from the h2o_quality
measurement in theNOAA_water_database
database.The LIMIT
and OFFSET
clauses limit the number of tag keys returned to oneand offsets the results by one.
SHOW TAG VALUES
Returns the list of for the specified tag key(s) in the database.
SHOW TAG VALUES [ON <database_name>][FROM_clause] WITH KEY [ [<operator> "<tag_key>" | <regular_expression>] | [IN ("<tag_key1>","<tag_key2")]] [WHERE <tag_key> <operator> ['<tag_value>' | <regular_expression>]] [LIMIT_clause] [OFFSET_clause]
Description of syntax
ON <database_name>
is optional.If the query does not include ON <database_name>
, you must specify thedatabase with USE <database_name>
in the CLI or with the db
query string parameter in the request.
The WITH
clause is required.It supports specifying a single tag key, a regular expression, and multiple tag keys.
The FROM
, WHERE
, LIMIT
, and OFFSET
clauses are optional.The WHERE
clause supports tag comparisons; field comparisons are notvalid for the SHOW TAG KEYS
query.
See the Data Exploration page for documentation on theFROM
clause,,OFFSET
clause,and on .
Examples
Run a SHOW TAG VALUES query with the ON clause
The query returns all tag values of the randtag
tag key in the NOAA_water_database
database.SHOW TAG VALUES
groups query results by measurement name.
Run a SHOW TAG VALUES query without the ON clause
Specify the database with USE <database_name>
> USE NOAA_water_database
Using database NOAA_water_database
> SHOW TAG VALUES WITH KEY = "randtag"
key value
--- -----
randtag 1
randtag 2
Specify the database with the db
query string parameter:
~# curl -G "http://localhost:8086/query?db=NOAA_water_database&pretty=true" --data-urlencode 'q=SHOW TAG VALUES WITH KEY = "randtag"'
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "h2o_quality",
"columns": [
"key",
"value"
],
"values": [
[
"randtag",
"1"
],
[
"randtag",
"2"
],
[
"randtag",
"3"
]
]
}
]
}
]
}
Run a SHOW TAG VALUES query with several clauses
> SHOW TAG VALUES ON "NOAA_water_database" WITH KEY IN ("location","randtag") WHERE "randtag" =~ /./ LIMIT 3
name: h2o_quality
key value
--- -----
location coyote_creek
location santa_monica
randtag 1
The query returns the tag values of the tag keys location
and randtag
forall measurements in the NOAA_water_database
database where randtag
has tag values.The LIMIT
clause limits the number of tag values returned to three.
Returns the field keys and the of theirfield values.
Syntax
SHOW FIELD KEYS [ON <database_name>] [FROM <measurement_name>]
Description of syntax
ON <database_name>
is optional.If the query does not include ON <database_name>
, you must specify thedatabase with USE <database_name>
in the or with the db
querystring parameter in the InfluxDB API request.
The FROM
clause is also optional.See the Data Exploration page for documentation on the.
Examples
Run a SHOW FIELD KEYS query with the ON clause
> SHOW FIELD KEYS ON "NOAA_water_database"
name: average_temperature
fieldKey fieldType
-------- ---------
degrees float
name: h2o_feet
fieldKey fieldType
-------- ---------
level description string
water_level float
name: h2o_pH
fieldKey fieldType
-------- ---------
pH float
name: h2o_quality
fieldKey fieldType
-------- ---------
index float
name: h2o_temperature
fieldKey fieldType
-------- ---------
degrees float
The query returns the field keys and field value data types for eachmeasurement in the NOAA_water_database
database.
Run a SHOW FIELD KEYS query without the ON clause
Specify the database with USE <database_name>
> USE NOAA_water_database
Using database NOAA_water_database
> SHOW FIELD KEYS
name: average_temperature
fieldKey fieldType
-------- ---------
degrees float
name: h2o_feet
fieldKey fieldType
-------- ---------
level description string
water_level float
name: h2o_pH
fieldKey fieldType
-------- ---------
pH float
name: h2o_quality
fieldKey fieldType
-------- ---------
index float
name: h2o_temperature
fieldKey fieldType
-------- ---------
degrees float
Specify the database with the db
query string parameter:
~# curl -G "http://localhost:8086/query?db=NOAA_water_database&pretty=true" --data-urlencode 'q=SHOW FIELD KEYS'
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "average_temperature",
"columns": [
"fieldKey",
"fieldType"
],
"values": [
[
"degrees",
"float"
]
]
},
{
"name": "h2o_feet",
"columns": [
"fieldKey",
"fieldType"
],
"values": [
[
"level description",
"string"
],
[
"water_level",
"float"
]
]
},
{
"name": "h2o_pH",
"columns": [
"fieldKey",
"fieldType"
],
"values": [
[
"pH",
"float"
]
]
},
{
"name": "h2o_quality",
"columns": [
"fieldKey",
"fieldType"
],
"values": [
[
"index",
"float"
]
]
},
{
"name": "h2o_temperature",
"columns": [
"fieldKey",
"fieldType"
],
"values": [
[
"degrees",
"float"
]
]
}
]
}
]
}
Run a SHOW FIELD KEYS query with the FROM clause
> SHOW FIELD KEYS ON "NOAA_water_database" FROM "h2o_feet"
name: h2o_feet
fieldKey fieldType
-------- ---------
level description string
water_level float
The query returns the fields keys and field value data types for the h2o_feet
measurement in the NOAA_water_database
database.
Common Issues with SHOW FIELD KEYS
SHOW FIELD KEYS and field type discrepancies
Field valuedata typescannot differ within a but theycan differ across shards.SHOW FIELD KEYS
returns every data type, across every shard, associated withthe field key.
Example
The all_the_types
field stores four different data types:
> SHOW FIELD KEYS
name: mymeas
fieldKey fieldType
-------- ---------
all_the_types integer
all_the_types float
all_the_types string
all_the_types boolean
Note that SHOW FIELD KEYS
handles field type discrepancies differently fromSELECT
statements.For more information, see the.
When you filter meta queries by time, you may see results outside of your specified time. Meta query results are filtered at the shard level, so results can be approximately as granular as your shard group duration. If your time filter spans multiple shards, you’ll get results from all shards with points in the specified time range. To review your shards and timestamps on points in the shard, run SHOW SHARDS
. To learn more about shards and their duration, see recommended shard groups durations.
The example below shows how to filter SHOW TAG KEYS
by approximately one hour using a 1h shard group duration. To filter other meta data, replace SHOW TAG KEYS
with SHOW TAG VALUES
, SHOW SERIES
, SHOW MEASUREMENTS
, SHOW FIELD KEYS
, and so on.
Example filtering SHOW TAG KEYS by time
- Specify a shard duration on a new database or alter an existing shard duration. To specify a 1h shard duration when creating a new database, run the following command:
> CREATE database mydb with duration 7d REPLICATION 1 SHARD DURATION 1h name myRP;
Note: The minimum shard duration is 1h.
- Verify the shard duration has the correct time interval (precision) by running the
SHOW SHARDS
command. The example below shows a shard duration with an hour precision.
> SHOW SHARDS
name: mydb
id database retention_policy shard_group start_time end_time expiry_time owners
-- -------- ---------------- ----------- ---------- -------- ----------- ------
> precision h
- (Optional) Insert sample tag keys. This step is for demonstration purposes. If you already have tag keys (or other meta data) to search for, skip this step.
// Insert a sample tag called "test_key" into the "test" measurement, and then check the timestamp:
> INSERT test,test_key=hello value=1
> select * from test
name: test
time test_key value
---- -------- -----
434820 hello 1
// Add new tag keys with timestamps one, two, and three hours earlier:
> INSERT test,test_key_1=hello value=1 434819
> INSERT test,test_key_2=hello value=1 434819
> INSERT test,test_key_3_=hello value=1 434818
> INSERT test,test_key_4=hello value=1 434817
- To find tag keys within a shard duration, run one of the following commands:
SHOW TAG KEYS ON database-name <WHERE time clause>
OR
The examples below use test data from step 3.