2014-12-09 16:19:43 +00:00
The top level name is called a measurement. These names can contain any characters. Then there are field names, field values, tag keys and tag values, which can also contain any characters. Because of this, anywhere a measurement name, field name, field value, tag name, or tag value appears should be able to get wrapped in double quotes to deal with special characters.
2015-01-05 19:10:01 +00:00
# Databases & retention policies
2014-12-29 16:05:13 +00:00
```sql
-- create a database
2015-01-05 19:10:01 +00:00
CREATE DATABASE < name >
2014-12-29 17:36:16 +00:00
2015-01-05 19:10:01 +00:00
-- create a retention policy
CREATE RETENTION POLICY < rp-name > ON < db-name > DURATION < duration > REPLICATION < n > [DEFAULT]
-- alter retention policy
ALTER RETENTION POLICY < rp-name > ON < db-name > (DURATION < duration > | REPLICATION < n > | DEFAULT)+
-- drop a database
DROP DATABASE < name >
2014-12-29 16:05:13 +00:00
```
# Users and permissions
```sql
-- create user
2014-12-29 16:23:19 +00:00
CREATE USER < name > WITH PASSWORD < password >
2014-12-29 16:05:13 +00:00
2015-01-05 19:10:01 +00:00
-- grant privilege on a database
GRANT < privilege > ON < db > TO < user >
2014-12-29 16:05:13 +00:00
-- grant cluster admin privileges
GRANT ALL [PRIVILEGES] TO < user >
2014-12-29 17:36:16 +00:00
2015-01-05 19:10:01 +00:00
-- revoke privilege
REVOKE < privilege > ON < db > FROM < user >
2014-12-29 17:36:16 +00:00
-- revoke all privileges for a DB
REVOKE ALL [PRIVILEGES] ON < db > FROM < user >
-- revoke all of user's privileges (all DBs and/or cluster admin)
REVOKE ALL [PRIVILEGES] FROM < user >
-- delete a user
2015-01-05 19:10:01 +00:00
DROP USER < name >
2014-12-29 16:05:13 +00:00
```
2015-01-05 19:10:01 +00:00
< privilege > := READ | WRITE | All [PRIVILEGES]
2014-12-29 16:05:13 +00:00
2014-11-25 22:27:34 +00:00
# Select
2014-12-09 15:24:35 +00:00
```sql
2014-12-09 16:09:33 +00:00
-- get the top 10 host measurements for the last hour (same host can appear multiple times)
SELECT top(10, value), host FROM cpu WHERE time > now() - 1h
2014-11-25 22:27:34 +00:00
2014-12-09 16:09:33 +00:00
-- get the top 10 unique hosts for the last hour
SELECT top(10, value), distinct(host) FROM cpu WHERE time > now() - 1h
2014-12-09 15:24:35 +00:00
```
2014-11-25 22:27:34 +00:00
## Group By
# Delete
# Series
## Destroy
2014-12-09 16:19:43 +00:00
```sql
DROP MEASUREMENT < name >
DROP MEASUREMENT cpu WHERE region = 'uswest'
```
2014-11-25 22:27:34 +00:00
## List
2014-12-09 15:49:42 +00:00
List series queries are for pulling out individual series from measurement names and tag data. They're useful for discovery.
```sql
2014-12-09 16:26:34 +00:00
-- list measurement names
LIST MEASUREMENTS
LIST MEASUREMENTS WHERE service = 'redis'
2014-12-09 15:49:42 +00:00
-- list all series across all measurements/tagsets
LIST SERIES
-- get a list of all series for any measurements where tag key region = tak value 'uswest'
LIST SERIES WHERE region = 'uswest'
2015-01-12 21:51:56 +00:00
LIST SERIES FROM cpu_load WHERE region = 'uswest' LIMIT 10
2014-12-09 15:49:42 +00:00
-- get a list of all tag keys across all measurements
2014-12-09 16:26:34 +00:00
LIST TAG KEYS
2014-12-09 15:49:42 +00:00
-- list all the tag keys for a given measurement
2014-12-09 16:26:34 +00:00
LIST TAG KEYS FROM cpu
LIST TAG KEYS FROM temperature, wind_speed
2014-12-09 15:49:42 +00:00
2014-12-30 19:40:44 +00:00
-- list all the tag values. note that a single WHERE TAG KEY = '...' clause is required
LIST TAG VALUES WHERE TAG KEY = 'region'
LIST TAG VALUES FROM cpu WHERE region = 'uswest' and TAG KEY = 'host'
2014-12-09 16:26:34 +00:00
-- and you can do stuff against fields
LIST FIELD KEYS FROM cpu
-- but you can't do this
LIST FIELD VALUES
-- we don't index field values, so this query should be invalid.
2014-12-09 15:49:42 +00:00
```
2014-12-09 16:19:43 +00:00
Note that `FROM` and `WHERE` are optional clauses in all of the list series queries.
2014-12-09 15:49:42 +00:00
And the list series output looks like this:
```json
[
{
"name": "cpu",
"columns": ["id", "region", "host"],
"values": [
1, "uswest", "servera",
2, "uswest", "serverb"
]
},
{
"name": "reponse_time",
"columns": ["id", "application", "host"],
"values": [
3, "myRailsApp", "servera"
]
}
]
```
2014-11-25 22:27:34 +00:00
# Continuous Queries
Continous queries are going to be inspired by MySQL `TRIGGER` syntax:
http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html
Instead of having automatically-assigned ids, named continuous queries allows for some level of duplication prevention,
particularly in the case where creation is scripted.
## Create
CREATE CONTINUOUS QUERY < name > AS SELECT ... FROM ...
## Destroy
DROP CONTINUOUS QUERY < name >
## List
LIST CONTINUOUS QUERIES