SQL Reference

In this part, we will introduce you IoTDB’s Query Language. IoTDB offers you a SQL-like query language for interacting with IoTDB, the query language can be devided into 4 major parts:

  • Schema Statement: statements about schema management are all listed in this section.
  • Data Management Statement: statements about data management (such as: data insertion, data query, etc.) are all listed in this section.
  • Database Management Statement: statements about database management and authentication are all listed in this section.
  • Functions: functions that IoTDB offers are all listed in this section.

All of these statements are write in IoTDB’s own syntax, for details about the syntax composition, please check the Reference section.

Show Version

  1. show version
  1. +---------------+
  2. | version|
  3. +---------------+
  4. |1.0.0|
  5. +---------------+
  6. Total line number = 1
  7. It costs 0.417s

Schema Statement

  • Create Database
  1. CREATE DATABASE <FullPath>
  2. Eg: IoTDB > CREATE DATABASE root.ln.wf01.wt01
  3. Note: FullPath can not include wildcard `*` or `**`
  • Delete database
  1. DELETE DATABASE <PathPattern> [COMMA <PathPattern>]*
  2. Eg: IoTDB > DELETE DATABASE root.ln.wf01.wt01
  3. Eg: IoTDB > DELETE DATABASE root.ln.wf01.wt01, root.ln.wf01.wt02
  4. Eg: IoTDB > DELETE DATABASE root.ln.wf01.*
  5. Eg: IoTDB > DELETE DATABASE root.**
  • Create Timeseries Statement
  1. CREATE TIMESERIES <FullPath> WITH <AttributeClauses>
  2. alias
  3. : LR_BRACKET ID RR_BRACKET
  4. ;
  5. attributeClauses
  6. : DATATYPE OPERATOR_EQ <DataTypeValue>
  7. COMMA ENCODING OPERATOR_EQ <EncodingValue>
  8. (COMMA (COMPRESSOR | COMPRESSION) OPERATOR_EQ <CompressorValue>)?
  9. (COMMA property)*
  10. tagClause
  11. attributeClause
  12. ;
  13. attributeClause
  14. : ATTRIBUTES LR_BRACKET propertyClause (COMMA propertyClause)* RR_BRACKET
  15. ;
  16. tagClause
  17. : TAGS LR_BRACKET propertyClause (COMMA propertyClause)* RR_BRACKET
  18. ;
  19. propertyClause
  20. : name=ID OPERATOR_EQ propertyValue
  21. ;
  22. DataTypeValue: BOOLEAN | DOUBLE | FLOAT | INT32 | INT64 | TEXT
  23. EncodingValue: GORILLA | PLAIN | RLE | TS_2DIFF | REGULAR
  24. CompressorValue: UNCOMPRESSED | SNAPPY
  25. AttributesType: SDT | COMPDEV | COMPMINTIME | COMPMAXTIME
  26. PropertyValue: ID | constant
  27. Eg: CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN
  28. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE
  29. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, COMPRESSOR=SNAPPY, MAX_POINT_NUMBER=3
  30. Eg: CREATE TIMESERIES root.turbine.d0.s0(temperature) WITH DATATYPE=FLOAT, ENCODING=RLE, COMPRESSOR=SNAPPY tags(unit=f, description='turbine this is a test1') attributes(H_Alarm=100, M_Alarm=50)
  31. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, DEADBAND=SDT, COMPDEV=0.01
  32. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, DEADBAND=SDT, COMPDEV=0.01, COMPMINTIME=3
  33. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, DEADBAND=SDT, COMPDEV=0.01, COMPMINTIME=2, COMPMAXTIME=15
  34. Note: Datatype and encoding type must be corresponding. Please check Chapter 3 Encoding Section for details.
  35. Note: When propertyValue is SDT, it is required to set compression deviation COMPDEV, which is the maximum absolute difference between values.
  36. Note: For SDT, values withtin COMPDEV will be discarded.
  37. Note: For SDT, it is optional to set compression minimum COMPMINTIME, which is the minimum time difference between stored values for purpose of noise reduction.
  38. Note: For SDT, it is optional to set compression maximum COMPMAXTIME, which is the maximum time difference between stored values regardless of COMPDEV.
  • Create Timeseries Statement (Simplified version, from v0.13)
  1. CREATE TIMESERIES <FullPath> <SimplifiedAttributeClauses>
  2. SimplifiedAttributeClauses
  3. : WITH? (DATATYPE OPERATOR_EQ)? <DataTypeValue>
  4. ENCODING OPERATOR_EQ <EncodingValue>
  5. ((COMPRESSOR | COMPRESSION) OPERATOR_EQ <CompressorValue>)?
  6. (COMMA property)*
  7. tagClause
  8. attributeClause
  9. ;
  10. Eg: CREATE TIMESERIES root.ln.wf01.wt01.status BOOLEAN ENCODING=PLAIN
  11. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature FLOAT ENCODING=RLE
  12. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature FLOAT ENCODING=RLE COMPRESSOR=SNAPPY MAX_POINT_NUMBER=3
  13. Eg: CREATE TIMESERIES root.turbine.d0.s0(temperature) FLOAT ENCODING=RLE COMPRESSOR=SNAPPY tags(unit=f, description='turbine this is a test1') attributes(H_Alarm=100, M_Alarm=50)
  14. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature FLOAT ENCODING=RLE DEADBAND=SDT COMPDEV=0.01
  15. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature FLOAT ENCODING=RLE DEADBAND=SDT COMPDEV=0.01 COMPMINTIME=3
  16. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature FLOAT ENCODING=RLE DEADBAND=SDT COMPDEV=0.01 COMPMINTIME=2 COMPMAXTIME=15
  • Create Aligned Timeseries Statement
  1. CREATE ALIGNED TIMESERIES <FullPath> alignedMeasurements
  2. alignedMeasurements
  3. : LR_BRACKET nodeNameWithoutWildcard attributeClauses
  4. (COMMA nodeNameWithoutWildcard attributeClauses)+ RR_BRACKET
  5. ;
  6. Eg: CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(lat FLOAT ENCODING=GORILLA, lon FLOAT ENCODING=GORILLA COMPRESSOR=SNAPPY)
  7. Note: It is not supported to set different compression for a group of aligned timeseries.
  8. Note: It is not currently supported to set an alias, tag, and attribute for aligned timeseries.
  • Create Schema Template Statement
  1. CREATE SCHEMA TEMPLATE <TemplateName> LR_BRACKET <TemplateMeasurementClause> (COMMA plateMeasurementClause>)* RR_BRACKET
  2. templateMeasurementClause
  3. : suffixPath attributeClauses #nonAlignedTemplateMeasurement
  4. | suffixPath LR_BRACKET nodeNameWithoutWildcard attributeClauses
  5. (COMMA nodeNameWithoutWildcard attributeClauses)+ RR_BRACKET #alignedTemplateMeasurement
  6. ;
  7. Eg: CREATE SCHEMA TEMPLATE temp1(
  8. s1 INT32 encoding=Gorilla, compression=SNAPPY,
  9. vector1(
  10. s1 INT32 encoding=Gorilla,
  11. s2 FLOAT encoding=RLE, compression=SNAPPY)
  12. )
  • Set Schema Template Statement
  1. SET SCHEMA TEMPLATE <TemplateName> TO <PrefixPath>
  2. Eg: SET SCHEMA TEMPLATE temp1 TO root.beijing
  • Create Timeseries Of Schema Template Statement
  1. CREATE TIMESERIES OF SCHEMA TEMPLATE ON <PrefixPath>
  2. Eg: CREATE TIMESERIES OF SCHEMA TEMPLATE ON root.beijing
  • Unset Schema Template Statement
  1. UNSET SCHEMA TEMPLATE <TemplateName> FROM <PrefixPath>
  2. Eg: UNSET SCHEMA TEMPLATE temp1 FROM root.beijing
  • Delete Timeseries Statement
  1. (DELETE | DROP) TIMESERIES <PathPattern> [COMMA <PathPattern>]*
  2. Eg: IoTDB > DELETE TIMESERIES root.ln.wf01.wt01.status
  3. Eg: IoTDB > DELETE TIMESERIES root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature
  4. Eg: IoTDB > DELETE TIMESERIES root.ln.wf01.wt01.*
  5. Eg: IoTDB > DROP TIMESERIES root.ln.wf01.wt01.*
  • Alter Timeseries Statement
  1. ALTER TIMESERIES fullPath alterClause
  2. alterClause
  3. : RENAME beforeName=ID TO currentName=ID
  4. | SET property (COMMA property)*
  5. | DROP ID (COMMA ID)*
  6. | ADD TAGS property (COMMA property)*
  7. | ADD ATTRIBUTES property (COMMA property)*
  8. | UPSERT tagClause attributeClause
  9. ;
  10. attributeClause
  11. : (ATTRIBUTES LR_BRACKET property (COMMA property)* RR_BRACKET)?
  12. ;
  13. tagClause
  14. : (TAGS LR_BRACKET property (COMMA property)* RR_BRACKET)?
  15. ;
  16. Eg: ALTER timeseries root.turbine.d1.s1 RENAME tag1 TO newTag1
  17. Eg: ALTER timeseries root.turbine.d1.s1 SET tag1=newV1, attr1=newV1
  18. Eg: ALTER timeseries root.turbine.d1.s1 DROP tag1, tag2
  19. Eg: ALTER timeseries root.turbine.d1.s1 ADD TAGS tag3=v3, tag4=v4
  20. Eg: ALTER timeseries root.turbine.d1.s1 ADD ATTRIBUTES attr3=v3, attr4=v4
  21. EG: ALTER timeseries root.turbine.d1.s1 UPSERT TAGS(tag2=newV2, tag3=v3) ATTRIBUTES(attr3=v3, attr4=v4)
  • Show All Timeseries Statement
  1. SHOW TIMESERIES
  2. Eg: IoTDB > SHOW TIMESERIES
  3. Note: This statement can only be used in IoTDB Client. If you need to show all timeseries in JDBC, please use `DataBaseMetadata` interface.
  • Show Specific Timeseries Statement
  1. SHOW TIMESERIES <Path>
  2. Eg: IoTDB > SHOW TIMESERIES root.**
  3. Eg: IoTDB > SHOW TIMESERIES root.ln.**
  4. Eg: IoTDB > SHOW TIMESERIES root.ln.*.*.status
  5. Eg: IoTDB > SHOW TIMESERIES root.ln.wf01.wt01.status
  6. Note: The path can be timeseries path or path pattern.
  7. Note: This statement can be used in IoTDB Client and JDBC.
  • Show Specific Timeseries Statement with where clause
  1. SHOW TIMESERIES pathPattern? showWhereClause?
  2. showWhereClause
  3. : WHERE (property | containsExpression)
  4. ;
  5. containsExpression
  6. : name=ID OPERATOR_CONTAINS value=propertyValue
  7. ;
  8. Eg: show timeseries root.ln.** where unit='c'
  9. Eg: show timeseries root.ln.** where description contains 'test1'
  • Show Specific Timeseries Statement with where clause start from offset and limit the total number of result
  1. SHOW TIMESERIES pathPattern? showWhereClause? limitClause?
  2. showWhereClause
  3. : WHERE (property | containsExpression)
  4. ;
  5. containsExpression
  6. : name=ID OPERATOR_CONTAINS value=propertyValue
  7. ;
  8. limitClause
  9. : LIMIT INT offsetClause?
  10. | offsetClause? LIMIT INT
  11. ;
  12. Eg: show timeseries root.ln.** where unit='c'
  13. Eg: show timeseries root.ln.** where description contains 'test1'
  14. Eg: show timeseries root.ln.** where unit='c' limit 10 offset 10
  • Show Databases Statement
  1. SHOW DATABASES
  2. Eg: IoTDB > SHOW DATABASES
  3. Note: This statement can be used in IoTDB Client and JDBC.
  • Show Specific database Statement
  1. SHOW DATABASES <Path>
  2. Eg: IoTDB > SHOW DATABASES root.*
  3. Eg: IoTDB > SHOW DATABASES root.ln
  4. Note: The path can be full path or path pattern.
  5. Note: This statement can be used in IoTDB Client and JDBC.
  • Show Merge Status Statement
  1. SHOW MERGE INFO
  2. Eg: IoTDB > SHOW MERGE INFO
  3. Note: This statement can be used in IoTDB Client and JDBC.
  • Count Timeseries Statement
  1. COUNT TIMESERIES <Path>
  2. Eg: IoTDB > COUNT TIMESERIES root.**
  3. Eg: IoTDB > COUNT TIMESERIES root.ln.**
  4. Eg: IoTDB > COUNT TIMESERIES root.ln.*.*.status
  5. Eg: IoTDB > COUNT TIMESERIES root.ln.wf01.wt01.status
  6. Note: The path can be timeseries path or path pattern.
  7. Note: This statement can be used in IoTDB Client and JDBC.
  1. COUNT TIMESERIES <Path> GROUP BY LEVEL=<INTEGER>
  2. Eg: IoTDB > COUNT TIMESERIES root.** GROUP BY LEVEL=1
  3. Eg: IoTDB > COUNT TIMESERIES root.ln.** GROUP BY LEVEL=2
  4. Eg: IoTDB > COUNT TIMESERIES root.ln.wf01.* GROUP BY LEVEL=3
  5. Note: The path can be timeseries path or path pattern.
  6. Note: This statement can be used in IoTDB Client and JDBC.
  • Count Nodes Statement
  1. COUNT NODES <Path> LEVEL=<INTEGER>
  2. Eg: IoTDB > COUNT NODES root.** LEVEL=2
  3. Eg: IoTDB > COUNT NODES root.ln.** LEVEL=2
  4. Eg: IoTDB > COUNT NODES root.ln.* LEVEL=3
  5. Eg: IoTDB > COUNT NODES root.ln.wf01 LEVEL=3
  6. Note: The path can be full path or path pattern.
  7. Note: This statement can be used in IoTDB Client and JDBC.
  • Show All Devices Statement
  1. SHOW DEVICES (WITH DATABASE)? limitClause?
  2. Eg: IoTDB > SHOW DEVICES
  3. Eg: IoTDB > SHOW DEVICES WITH DATABASE
  4. Note: This statement can be used in IoTDB Client and JDBC.
  • Show Specific Devices Statement
  1. SHOW DEVICES <PathPattern> (WITH DATABASE)? limitClause?
  2. Eg: IoTDB > SHOW DEVICES root.**
  3. Eg: IoTDB > SHOW DEVICES root.ln.**
  4. Eg: IoTDB > SHOW DEVICES root.*.wf01
  5. Eg: IoTDB > SHOW DEVICES root.ln WITH DATABASE
  6. Eg: IoTDB > SHOW DEVICES root.*.wf01 WITH DATABASE
  7. Note: This statement can be used in IoTDB Client and JDBC.
  • Show Child Paths of Root Statement
  1. SHOW CHILD PATHS
  2. Eg: IoTDB > SHOW CHILD PATHS
  3. Note: This statement can be used in IoTDB Client and JDBC.
  • Show Child Paths Statement
  1. SHOW CHILD PATHS <PathPattern>
  2. Eg: IoTDB > SHOW CHILD PATHS root
  3. Eg: IoTDB > SHOW CHILD PATHS root.ln
  4. Eg: IoTDB > SHOW CHILD PATHS root.*.wf01
  5. Eg: IoTDB > SHOW CHILD PATHS root.ln.wf*
  6. Note: This statement can be used in IoTDB Client and JDBC.

Data Management Statement

  • Insert Record Statement
  1. INSERT INTO <PrefixPath> LPAREN TIMESTAMP COMMA <Sensor> [COMMA <Sensor>]* RPAREN VALUES LPAREN <TimeValue>, <PointValue> [COMMA <PointValue>]* RPAREN
  2. Sensor : Identifier
  3. Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,status) values(1509465600000,true)
  4. Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(NOW(), false)
  5. Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,temperature) VALUES(2017-11-01T00:17:00.000+08:00,24.22028)
  6. Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,status,temperature) VALUES (1509466680000,false,20.060787)
  7. Eg: IoTDB > INSERT INTO root.sg.d1(timestamp,(s1,s2),(s3,s4)) VALUES (1509466680000,(1.0,2),(NULL,4))
  8. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  9. Note: The order of Sensor and PointValue need one-to-one correspondence
  • Delete Record Statement
  1. DELETE FROM <PathPattern> [COMMA <PathPattern>]* [WHERE <WhereClause>]?
  2. WhereClause : <Condition> [(AND) <Condition>]*
  3. Condition : <TimeExpr> [(AND) <TimeExpr>]*
  4. TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
  5. Eg: DELETE FROM root.ln.wf01.wt01.temperature WHERE time > 2016-01-05T00:15:00+08:00 and time < 2017-11-1T00:05:00+08:00
  6. Eg: DELETE FROM root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature WHERE time < NOW()
  7. Eg: DELETE FROM root.ln.wf01.wt01.* WHERE time >= 1509466140000
  • Select Record Statement
  1. SELECT <SelectClause> FROM <FromClause> [WHERE <WhereClause>]?
  2. SelectClause : <SelectPath> (COMMA <SelectPath>)*
  3. SelectPath : <FUNCTION> LPAREN <Path> RPAREN | <Path>
  4. FUNCTION : COUNT , MIN_TIME’, MAX_TIME’, MIN_VALUE’, MAX_VALUE
  5. FromClause : <PrefixPath> (COMMA <PrefixPath>)?
  6. WhereClause : <Condition> [(AND | OR) <Condition>]*
  7. Condition : <Expression> [(AND | OR) <Expression>]*
  8. Expression : [NOT | !]? <TimeExpr> | [NOT | !]? <SensorExpr>
  9. TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
  10. RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS')
  11. RelativeTime : (now() | <TimeValue>) [(+|-) RelativeTimeDurationUnit]+
  12. SensorExpr : (<Timeseries> | <Path>) PrecedenceEqualOperator <PointValue>
  13. Eg: IoTDB > SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > 2017-11-1 0:13:00
  14. Eg. IoTDB > SELECT ** FROM root
  15. Eg. IoTDB > SELECT * FROM root.**
  16. Eg. IoTDB > SELECT * FROM root.** where time > now() - 5m
  17. Eg. IoTDB > SELECT * FROM root.ln.*.wf*
  18. Eg. IoTDB > SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
  19. Eg. IoTDB > SELECT MIN_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
  20. Eg. IoTDB > SELECT MAX_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature > 24
  21. Eg. IoTDB > SELECT MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature > 23
  22. Eg. IoTDB > SELECT MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
  23. Eg. IoTDB > SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25 GROUP BY LEVEL=1
  24. Note: the statement needs to satisfy this constraint: <Path>(SelectClause) + <PrefixPath>(FromClause) = <Timeseries>
  25. Note: If the <SensorExpr>(WhereClause) is started with <Path> and not with ROOT, the statement needs to satisfy this constraint: <PrefixPath>(FromClause) + <Path>(SensorExpr) = <Timeseries>
  26. Note: In Version 0.7.0, if <WhereClause> includes `OR`, time filter can not be used.
  27. Note: There must be a space on both sides of the plus and minus operator appearing in the time expression
  • Group By Statement
  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> GROUP BY <GroupByTimeClause>
  2. SelectClause : <Function> [COMMA < Function >]*
  3. Function : <AggregationFunction> LPAREN <Path> RPAREN
  4. FromClause : <PrefixPath>
  5. WhereClause : <Condition> [(AND | OR) <Condition>]*
  6. Condition : <Expression> [(AND | OR) <Expression>]*
  7. Expression : [NOT | !]? <TimeExpr> | [NOT | !]? <SensorExpr>
  8. TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
  9. RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS')
  10. RelativeTime : (now() | <TimeValue>) [(+|-) RelativeTimeDurationUnit]+
  11. SensorExpr : (<Timeseries> | <Path>) PrecedenceEqualOperator <PointValue>
  12. GroupByTimeClause : LPAREN <TimeInterval> COMMA <TimeUnit> (COMMA <TimeUnit>)? RPAREN
  13. TimeInterval: LSBRACKET <TimeValue> COMMA <TimeValue> RRBRACKET | LRBRACKET <TimeValue> COMMA <TimeValue> RSBRACKET
  14. TimeUnit : Integer <DurationUnit>
  15. DurationUnit : "ms" | "s" | "m" | "h" | "d" | "w" | "mo"
  16. Eg: SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 where temperature < 24 GROUP BY([1509465720000, 1509466380000), 5m)
  17. Eg: SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 where temperature < 24 GROUP BY((1509465720000, 1509466380000], 5m)
  18. Eg. SELECT COUNT (status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE time < 1509466500000 GROUP BY([1509465720000, 1509466380000), 5m, 10m)
  19. Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ([1509466140000, 1509466380000), 3m, 5ms)
  20. Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 3m, 5ms)
  21. Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 1mo)
  22. Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 1mo, 1mo)
  23. Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 1mo, 2mo)
  24. Note: the statement needs to satisfy this constraint: <Path>(SelectClause) + <PrefixPath>(FromClause) = <Timeseries>
  25. Note: If the <SensorExpr>(WhereClause) is started with <Path> and not with ROOT, the statement needs to satisfy this constraint: <PrefixPath>(FromClause) + <Path>(SensorExpr) = <Timeseries>
  26. Note: <TimeValue>(TimeInterval) needs to be greater than 0
  27. Note: First <TimeValue>(TimeInterval) in needs to be smaller than second <TimeValue>(TimeInterval)
  28. Note: <TimeUnit> needs to be greater than 0
  29. Note: Third <TimeUnit> if set shouldn't be smaller than second <TimeUnit>
  30. Note: If the second <DurationUnit> is "mo", the third <DurationUnit> need to be in month
  31. Note: If the third <DurationUnit> is "mo", the second <DurationUnit> can be in any unit
  • Fill Statement
  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> FILL <FillClause>
  2. SelectClause : <Path> [COMMA <Path>]*
  3. FromClause : < PrefixPath > [COMMA < PrefixPath >]*
  4. WhereClause : <WhereExpression>
  5. WhereExpression : TIME EQUAL <TimeValue>
  6. FillClause : LPAREN <TypeClause> [COMMA <TypeClause>]* RPAREN
  7. TypeClause : <Int32Clause> | <Int64Clause> | <FloatClause> | <DoubleClause> | <BoolClause> | <TextClause>
  8. Int32Clause: INT32 LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  9. Int64Clause: INT64 LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  10. FloatClause: FLOAT LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  11. DoubleClause: DOUBLE LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  12. BoolClause: BOOLEAN LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  13. TextClause: TEXT LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  14. PreviousClause : PREVIOUS [COMMA <ValidPreviousTime>]?
  15. LinearClause : LINEAR [COMMA <ValidPreviousTime> COMMA <ValidBehindTime>]?
  16. ValidPreviousTime, ValidBehindTime: <TimeUnit>
  17. TimeUnit : Integer <DurationUnit>
  18. DurationUnit : "ms" | "s" | "m" | "h" | "d" | "w"
  19. Eg: SELECT temperature FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL(float[previous, 1m])
  20. Eg: SELECT temperature,status FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL (float[linear, 1m, 1m], boolean[previous, 1m])
  21. Eg: SELECT temperature,status,hardware FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL (float[linear, 1m, 1m], boolean[previous, 1m], text[previous])
  22. Eg: SELECT temperature,status,hardware FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL (float[linear], boolean[previous, 1m], text[previous])
  23. Note: the statement needs to satisfy this constraint: <PrefixPath>(FromClause) + <Path>(SelectClause) = <Timeseries>
  24. Note: Integer in <TimeUnit> needs to be greater than 0
  • Group By Fill Statement
  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> GROUP BY <GroupByClause> (FILL <GROUPBYFillClause>)?
  2. GroupByClause : LPAREN <TimeInterval> COMMA <TimeUnit> RPAREN
  3. GROUPBYFillClause : LPAREN <TypeClause> RPAREN
  4. TypeClause : <AllClause> | <Int32Clause> | <Int64Clause> | <FloatClause> | <DoubleClause> | <BoolClause> | <TextClause>
  5. AllClause: ALL LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  6. Int32Clause: INT32 LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  7. Int64Clause: INT64 LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  8. FloatClause: FLOAT LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  9. DoubleClause: DOUBLE LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  10. BoolClause: BOOLEAN LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  11. TextClause: TEXT LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  12. PreviousClause : PREVIOUS
  13. PreviousUntilLastClause : PREVIOUSUNTILLAST
  14. Eg: SELECT last_value(temperature) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (float[PREVIOUS])
  15. Eg: SELECT last_value(temperature) FROM root.ln.wf01.wt01 GROUP BY((15, 100], 5m) FILL (float[PREVIOUS])
  16. Eg: SELECT last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (int32[PREVIOUSUNTILLAST])
  17. Eg: SELECT last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (int32[PREVIOUSUNTILLAST, 5m])
  18. Eg: SELECT last_value(temperature), last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (ALL[PREVIOUS])
  19. Eg: SELECT last_value(temperature), last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (ALL[PREVIOUS, 5m])
  20. Note: In group by fill, sliding step is not supported in group by clause
  21. Note: Now, only last_value aggregation function is supported in group by fill.
  22. Note: Linear fill is not supported in group by fill.
  • Order by time Statement
  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> GROUP BY <GroupByClause> (FILL <GROUPBYFillClause>)? orderByTimeClause?
  2. orderByTimeClause: order by time (asc | desc)?
  3. Eg: SELECT last_value(temperature) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (float[PREVIOUS]) order by time desc
  4. Eg: SELECT * from root.** order by time desc
  5. Eg: SELECT * from root.** order by time desc align by device
  6. Eg: SELECT * from root.** order by time desc disable align
  7. Eg: SELECT last * from root.** order by time desc
  • Limit Statement
  1. SELECT <SelectClause> FROM <FromClause> [WHERE <WhereClause>] [<LIMITClause>] [<SLIMITClause>]
  2. SelectClause : [<Path> | Function]+
  3. Function : <AggregationFunction> LPAREN <Path> RPAREN
  4. FromClause : <Path>
  5. WhereClause : <Condition> [(AND | OR) <Condition>]*
  6. Condition : <Expression> [(AND | OR) <Expression>]*
  7. Expression: [NOT|!]?<TimeExpr> | [NOT|!]?<SensorExpr>
  8. TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
  9. RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS')
  10. RelativeTime : (now() | <TimeValue>) [(+|-) RelativeTimeDurationUnit]+
  11. SensorExpr : (<Timeseries>|<Path>) PrecedenceEqualOperator <PointValue>
  12. LIMITClause : LIMIT <N> [OFFSETClause]?
  13. N : Integer
  14. OFFSETClause : OFFSET <OFFSETValue>
  15. OFFSETValue : Integer
  16. SLIMITClause : SLIMIT <SN> [SOFFSETClause]?
  17. SN : Integer
  18. SOFFSETClause : SOFFSET <SOFFSETValue>
  19. SOFFSETValue : Integer
  20. Eg: IoTDB > SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > 2017-11-1 0:13:00 LIMIT 3 OFFSET 2
  21. Eg. IoTDB > SELECT COUNT (status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE time < 1509466500000 GROUP BY([1509465720000, 1509466380000], 5m) LIMIT 3
  22. Note: N, OFFSETValue, SN and SOFFSETValue must be greater than 0.
  23. Note: The order of <LIMITClause> and <SLIMITClause> does not affect the grammatical correctness.
  24. Note: <FillClause> can not use <LIMITClause> but not <SLIMITClause>.
  • Align By Device Statement
  1. AlignbyDeviceClause : ALIGN BY DEVICE
  2. Rules:
  3. 1. Both uppercase and lowercase are ok.
  4. Correct example: select * from root.sg1.* align by device
  5. Correct example: select * from root.sg1.* ALIGN BY DEVICE
  6. 2. AlignbyDeviceClause can only be used at the end of a query statement.
  7. Correct example: select * from root.sg1.* where time > 10 align by device
  8. Wrong example: select * from root.sg1.* align by device where time > 10
  9. 3. The paths of the SELECT clause can only be single level. In other words, the paths of the SELECT clause can only be measurements or STAR, without DOT.
  10. Correct example: select s0,s1 from root.sg1.* align by device
  11. Correct example: select s0,s1 from root.sg1.d0, root.sg1.d1 align by device
  12. Correct example: select * from root.sg1.* align by device
  13. Correct example: select * from root.** align by device
  14. Correct example: select s0,s1,* from root.*.* align by device
  15. Wrong example: select d0.s1, d0.s2, d1.s0 from root.sg1 align by device
  16. Wrong example: select *.s0, *.s1 from root.* align by device
  17. Wrong example: select *.*.* from root align by device
  18. 4. The data types of the same measurement column should be the same across devices.
  19. Note that when it comes to aggregated paths, the data type of the measurement column will reflect
  20. the aggregation function rather than the original timeseries.
  21. Correct example: select s0 from root.sg1.d0,root.sg1.d1 align by device
  22. root.sg1.d0.s0 and root.sg1.d1.s0 are both INT32.
  23. Correct example: select count(s0) from root.sg1.d0,root.sg1.d1 align by device
  24. count(root.sg1.d0.s0) and count(root.sg1.d1.s0) are both INT64.
  25. Wrong example: select s0 from root.sg1.d0, root.sg2.d3 align by device
  26. root.sg1.d0.s0 is INT32 while root.sg2.d3.s0 is FLOAT.
  27. 5. The display principle of the result table is that all the columns (no matther whther a column has has existing data) will be shown, with nonexistent cells being null. Besides, the select clause support const column (e.g., 'a', '123' etc..).
  28. For example, "select s0,s1,s2,'abc',s1,s2 from root.sg.d0, root.sg.d1, root.sg.d2 align by device". Suppose that the actual existing timeseries are as follows:
  29. - root.sg.d0.s0
  30. - root.sg.d0.s1
  31. - root.sg.d1.s0
  32. Then you could expect a table like:
  33. | Time | Device | s0 | s1 | s2 | 'abc' | s1 | s2 |
  34. | --- | --- | ---| ---| null | 'abc' | ---| null |
  35. | 1 |root.sg.d0| 20 | 2.5| null | 'abc' | 2.5| null |
  36. | 2 |root.sg.d0| 23 | 3.1| null | 'abc' | 3.1| null |
  37. | ... | ... | ...| ...| null | 'abc' | ...| null |
  38. | 1 |root.sg.d1| 12 |null| null | 'abc' |null| null |
  39. | 2 |root.sg.d1| 19 |null| null | 'abc' |null| null |
  40. | ... | ... | ...| ...| null | 'abc' | ...| null |
  41. Note that the cells of measurement 's0' and device 'root.sg.d1' are all null.
  42. 6. The duplicated devices in the prefix paths are neglected.
  43. For example, "select s0,s1 from root.sg.d0,root.sg.d0,root.sg.d1 align by device" is equal to "select s0,s1 from root.sg.d0,root.sg.d1 align by device".
  44. For example. "select s0,s1 from root.sg.*,root.sg.d0 align by device" is equal to "select s0,s1 from root.sg.* align by device".
  45. 7. The duplicated measurements in the suffix paths are not neglected.
  46. For example, "select s0,s0,s1 from root.sg.* align by device" is not equal to "select s0,s1 from root.sg.* align by device".
  47. 8. Both time predicates and value predicates are allowed in Where Clause. The paths of the value predicates can be the leaf node or full path started with ROOT. And wildcard is not allowed here. For example:
  48. - select * from root.sg.* where time = 1 align by device
  49. - select * from root.sg.* where s0 < 100 align by device
  50. - select * from root.sg.* where time < 20 AND s0 > 50 align by device
  51. - select * from root.sg.d0 where root.sg.d0.s0 = 15 align by device
  52. 9. More correct examples:
  53. - select * from root.vehicle.* align by device
  54. - select s0,s0,s1 from root.vehicle.* align by device
  55. - select s0,s1 from root.vehicle.* limit 10 offset 1 align by device
  56. - select * from root.vehicle.* slimit 10 soffset 2 align by device
  57. - select * from root.vehicle.* where time > 10 align by device
  58. - select * from root.vehicle.* where time < 10 AND s0 > 25 align by device
  59. - select * from root.vehicle.* where root.vehicle.d0.s0>0 align by device
  60. - select count(*) from root.vehicle align by device
  61. - select sum(*) from root.vehicle.* GROUP BY (20ms,0,[2,50]) align by device
  62. - select * from root.vehicle.* where time = 3 Fill(int32[previous, 5ms]) align by device
  • Disable Align Statement
  1. Disable Align Clause: DISABLE ALIGN
  2. Rules:
  3. 1. Both uppercase and lowercase are ok.
  4. Correct example: select * from root.sg1.* disable align
  5. Correct example: select * from root.sg1.* DISABLE ALIGN
  6. 2. Disable Align Clause can only be used at the end of a query statement.
  7. Correct example: select * from root.sg1.* where time > 10 disable align
  8. Wrong example: select * from root.sg1.* disable align where time > 10
  9. 3. Disable Align Clause cannot be used with Aggregation, Fill Statements, Group By or Group By Device Statements, but can with Limit Statements.
  10. Correct example: select * from root.sg1.* limit 3 offset 2 disable align
  11. Correct example: select * from root.sg1.* slimit 3 soffset 2 disable align
  12. Wrong example: select count(s0),count(s1) from root.sg1.d1 disable align
  13. Wrong example: select * from root.vehicle.* where root.vehicle.d0.s0>0 disable align
  14. Wrong example: select * from root.vehicle.* align by device disable align
  15. 4. The display principle of the result table is that only when the column (or row) has existing data will the column (or row) be shown, with nonexistent cells being empty.
  16. You could expect a table like:
  17. | Time | root.sg.d0.s1 | Time | root.sg.d0.s2 | Time | root.sg.d1.s1 |
  18. | --- | --- | --- | --- | --- | --- |
  19. | 1 | 100 | 20 | 300 | 400 | 600 |
  20. | 2 | 300 | 40 | 800 | 700 | 900 |
  21. | 4 | 500 | | | 800 | 1000 |
  22. | | | | | 900 | 8000 |
  23. 5. More correct examples:
  24. - select * from root.vehicle.* disable align
  25. - select s0,s0,s1 from root.vehicle.* disable align
  26. - select s0,s1 from root.vehicle.* limit 10 offset 1 disable align
  27. - select * from root.vehicle.* slimit 10 soffset 2 disable align
  28. - select * from root.vehicle.* where time > 10 disable align
  • Select Last Record Statement

The LAST function returns the last time-value pair of the given timeseries. Currently filters are not supported in LAST queries.

  1. SELECT LAST <SelectClause> FROM <FromClause>
  2. Select Clause : <Path> [COMMA <Path>]*
  3. FromClause : < PrefixPath > [COMMA < PrefixPath >]*
  4. WhereClause : <TimeExpr> [(AND | OR) <TimeExpr>]*
  5. TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
  6. Eg. SELECT LAST s1 FROM root.sg.d1
  7. Eg. SELECT LAST s1, s2 FROM root.sg.d1
  8. Eg. SELECT LAST s1 FROM root.sg.d1, root.sg.d2
  9. Eg. SELECT LAST s1 FROM root.sg.d1 where time > 100
  10. Eg. SELECT LAST s1, s2 FROM root.sg.d1 where time >= 500
  11. Rules:
  12. 1. the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  13. 2. SELECT LAST only supports time filter that contains '>' or '>=' currently.
  14. 3. The result set of last query will always be displayed in a fixed three column table format.
  15. For example, "select last s1, s2 from root.sg.d1, root.sg.d2", the query result would be:
  16. | Time | Path | Value | dataType |
  17. | --- | ------------- |------ | -------- |
  18. | 5 | root.sg.d1.s1 | 100 | INT32 |
  19. | 2 | root.sg.d1.s2 | 400 | INT32 |
  20. | 4 | root.sg.d2.s1 | 250 | INT32 |
  21. | 9 | root.sg.d2.s2 | 600 | INT32 |
  22. 4. It is not supported to use "diable align" in LAST query.
  • As Statement

As statement assigns an alias to time seires queried in SELECT statement

  1. You can use as statement in all queries, but some rules are restricted about wildcard.
  2. 1. Raw data query
  3. select s1 as speed, s2 as temperature from root.sg.d1
  4. The result set will be like
  5. | Time | speed | temperature |
  6. | ... | ... | .... |
  7. 2. Aggregation query
  8. select count(s1) as s1_num, max_value(s2) as s2_max from root.sg.d1
  9. 3. Down-frequence query
  10. select count(s1) as s1_num from root.sg.d1 group by ([100,500), 80ms)
  11. 4. Align by device query
  12. select s1 as speed, s2 as temperature from root.sg.d1 align by device
  13. select count(s1) as s1_num, count(s2), count(s3) as s3_num from root.sg.d2 align by device
  14. 5. Last Record query
  15. select last s1 as speed, s2 from root.sg.d1
  16. Rules
  17. 1. In addition to Align by device queryeach AS statement has to corresponding to one time series exactly.
  18. E.g. select s1 as temperature from root.sg.*
  19. At this time if `root.sg.*` includes more than one devicethen an exception will be thrown
  20. 2. In align by device querythe prefix path that each AS statement corresponding to can includes multiple device, but the suffix path can only be single sensor.
  21. E.g. select s1 as temperature from root.sg.*
  22. In this situation, it will be show correctly even if multiple devices are selected.
  23. E.g. select * as temperature from root.sg.d1
  24. In this situation, it will throws an exception if * corresponds to multiple sensors.
  • Regexp Statement

Regexp Statement only supports regular expressions with Java standard library style on timeseries which is TEXT data type

  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause>
  2. Select Clause : <Path> [COMMA <Path>]*
  3. FromClause : < PrefixPath > [COMMA < PrefixPath >]*
  4. WhereClause : andExpression (OPERATOR_OR andExpression)*
  5. andExpression : predicate (OPERATOR_AND predicate)*
  6. predicate : (suffixPath | fullPath) REGEXP regularExpression
  7. regularExpression: Java standard regularexpression, like '^[a-z][0-9]$', [details](https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html)
  8. Eg. select s1 from root.sg.d1 where s1 regexp '^[0-9]*$'
  9. Eg. select s1, s2 FROM root.sg.d1 where s1 regexp '^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$' and s2 regexp '^\d{15}|\d{18}$'
  10. Eg. select * from root.sg.d1 where s1 regexp '^[a-zA-Z]\w{5,17}$'
  11. Eg. select * from root.sg.d1 where s1 regexp '^\d{4}-\d{1,2}-\d{1,2}' and time > 100
  • Like Statement

The usage of LIKE Statement similar with mysql, but only support timeseries which is TEXT data type

  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause>
  2. Select Clause : <Path> [COMMA <Path>]*
  3. FromClause : < PrefixPath > [COMMA < PrefixPath >]*
  4. WhereClause : andExpression (OPERATOR_OR andExpression)*
  5. andExpression : predicate (OPERATOR_AND predicate)*
  6. predicate : (suffixPath | fullPath) LIKE likeExpression
  7. likeExpression : string that may contains "%" or "_", while "%value" means a string that ends with the value, "value%" means a string starts with the value, "%value%" means string that contains values, and "_" represents any character.
  8. Eg. select s1 from root.sg.d1 where s1 like 'abc'
  9. Eg. select s1, s2 from root.sg.d1 where s1 like 'a%bc'
  10. Eg. select * from root.sg.d1 where s1 like 'abc_'
  11. Eg. select * from root.sg.d1 where s1 like 'abc\%' and time > 100
  12. In this situation, '\%' means '%' will be escaped
  13. The result set will be like:
  14. | Time | Path | Value |
  15. | --- | ------------ | ----- |
  16. | 200 | root.sg.d1.s1| abc% |

Database Management Statement

  • Create User
  1. CREATE USER <userName> <password>;
  2. userName:=identifier
  3. password:=string
  4. Eg: IoTDB > CREATE USER thulab 'pwd';
  • Delete User
  1. DROP USER <userName>;
  2. userName:=identifier
  3. Eg: IoTDB > DROP USER xiaoming;
  • Create Role
  1. CREATE ROLE <roleName>;
  2. roleName:=identifie
  3. Eg: IoTDB > CREATE ROLE admin;
  • Delete Role
  1. DROP ROLE <roleName>;
  2. roleName:=identifier
  3. Eg: IoTDB > DROP ROLE admin;
  • Grant User Privileges
  1. GRANT USER <userName> PRIVILEGES <privileges> ON <nodeName>;
  2. userName:=identifier
  3. nodeName:=identifier (DOT identifier)*
  4. privileges:= string (COMMA string)*
  5. Eg: IoTDB > GRANT USER tempuser PRIVILEGES DELETE_TIMESERIES on root.ln;
  • Grant Role Privileges
  1. GRANT ROLE <roleName> PRIVILEGES <privileges> ON <nodeName>;
  2. privileges:= string (COMMA string)*
  3. roleName:=identifier
  4. nodeName:=identifier (DOT identifier)*
  5. Eg: IoTDB > GRANT ROLE temprole PRIVILEGES DELETE_TIMESERIES ON root.ln;
  • Grant User Role
  1. GRANT <roleName> TO <userName>;
  2. roleName:=identifier
  3. userName:=identifier
  4. Eg: IoTDB > GRANT temprole TO tempuser;
  • Revoke User Privileges
  1. REVOKE USER <userName> PRIVILEGES <privileges> ON <nodeName>;
  2. privileges:= string (COMMA string)*
  3. userName:=identifier
  4. nodeName:=identifier (DOT identifier)*
  5. Eg: IoTDB > REVOKE USER tempuser PRIVILEGES DELETE_TIMESERIES on root.ln;
  • Revoke Role Privileges
  1. REVOKE ROLE <roleName> PRIVILEGES <privileges> ON <nodeName>;
  2. privileges:= string (COMMA string)*
  3. roleName:= identifier
  4. nodeName:=identifier (DOT identifier)*
  5. Eg: IoTDB > REVOKE ROLE temprole PRIVILEGES DELETE_TIMESERIES ON root.ln;
  • Revoke Role From User
  1. REVOKE <roleName> FROM <userName>;
  2. roleName:=identifier
  3. userName:=identifier
  4. Eg: IoTDB > REVOKE temprole FROM tempuser;
  • List Users
  1. LIST USER
  2. Eg: IoTDB > LIST USER
  • List Roles
  1. LIST ROLE
  2. Eg: IoTDB > LIST ROLE
  • List Privileges
  1. LIST PRIVILEGES USER <username> ON <path>;
  2. username:=identifier
  3. path=‘root (DOT identifier)*
  4. Eg: IoTDB > LIST PRIVILEGES USER sgcc_wirte_user ON root.sgcc;
  • List Privileges of Roles
  1. LIST ROLE PRIVILEGES <roleName>
  2. roleName:=identifier
  3. Eg: IoTDB > LIST ROLE PRIVILEGES actor;
  • List Privileges of Roles(On Specific Path)
  1. LIST PRIVILEGES ROLE <roleName> ON <path>;
  2. roleName:=identifier
  3. path=‘root (DOT identifier)*
  4. Eg: IoTDB > LIST PRIVILEGES ROLE wirte_role ON root.sgcc;
  • List Privileges of Users
  1. LIST USER PRIVILEGES <username> ;
  2. username:=identifier
  3. Eg: IoTDB > LIST USER PRIVILEGES tempuser;
  • List Roles of Users
  1. LIST ALL ROLE OF USER <username> ;
  2. username:=identifier
  3. Eg: IoTDB > LIST ALL ROLE OF USER tempuser;
  • List Users of Role
  1. LIST ALL USER OF ROLE <roleName>;
  2. roleName:=identifier
  3. Eg: IoTDB > LIST ALL USER OF ROLE roleuser;
  • Alter Password
  1. ALTER USER <username> SET PASSWORD <password>;
  2. roleName:=identifier
  3. password:=identifier
  4. Eg: IoTDB > ALTER USER tempuser SET PASSWORD 'newpwd';

Functions

  • COUNT

The COUNT function returns the value number of timeseries(one or more) non-null values selected by the SELECT statement. The result is a signed 64-bit integer. If there are no matching rows, COUNT () returns 0.

  1. SELECT COUNT(Path) (COMMA COUNT(Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • FIRST_VALUE(Rename from FIRST at V0.10.0)

The FIRST_VALUE function returns the first point value of the choosen timeseries(one or more).

  1. SELECT FIRST_VALUE (Path) (COMMA FIRST_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT FIRST_VALUE (status), FIRST_VALUE (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • LAST_VALUE

The LAST_VALUE function returns the last point value of the choosen timeseries(one or more).

  1. SELECT LAST_VALUE (Path) (COMMA LAST_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT LAST_VALUE (status), LAST_VALUE (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • MAX_TIME

The MAX_TIME function returns the maximum timestamp of the choosen timeseries(one or more). The result is a signed 64-bit integer, greater than 0.

  1. SELECT MAX_TIME (Path) (COMMA MAX_TIME (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT MAX_TIME(status), MAX_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • MAX_VALUE

The MAX_VALUE function returns the maximum value(lexicographically ordered) of the choosen timeseries (one or more).

  1. SELECT MAX_VALUE (Path) (COMMA MAX_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT MAX_VALUE(status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • EXTREME

The EXTREME function returns the extreme value(lexicographically ordered) of the choosen timeseries (one or more). extreme value: The value that has the maximum absolute value. If the maximum absolute value of a positive value and a negative value is equal, return the positive value.

  1. SELECT EXTREME (Path) (COMMA EXT (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT EXTREME(status), EXTREME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • AVG(Rename from MEAN at V0.9.0)

The AVG function returns the arithmetic mean value of the choosen timeseries over a specified period of time. The timeseries must be int32, int64, float, double type, and the other types are not to be calculated. The result is a double type number.

  1. SELECT AVG (Path) (COMMA AVG (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT AVG (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • MIN_TIME

The MIN_TIME function returns the minimum timestamp of the choosen timeseries(one or more). The result is a signed 64-bit integer, greater than 0.

  1. SELECT MIN_TIME (Path) (COMMA MIN_TIME (Path))*FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT MIN_TIME(status), MIN_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • MIN_VALUE

The MIN_VALUE function returns the minimum value(lexicographically ordered) of the choosen timeseries (one or more).

  1. SELECT MIN_VALUE (Path) (COMMA MIN_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT MIN_VALUE(status),MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • NOW

The NOW function returns the current timestamp. This function can be used in the data operation statement to represent time. The result is a signed 64-bit integer, greater than 0.

  1. NOW()
  2. Eg. INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(NOW(), false)
  3. Eg. DELETE FROM root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature WHERE time < NOW()
  4. Eg. SELECT * FROM root.** WHERE time < NOW()
  5. Eg. SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE time < NOW()
  • SUM

The SUM function returns the sum of the choosen timeseries (one or more) over a specified period of time. The timeseries must be int32, int64, float, double type, and the other types are not to be calculated. The result is a double type number.

  1. SELECT SUM(Path) (COMMA SUM(Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT SUM(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

TTL

IoTDB supports storage-level TTL settings, which means it is able to delete old data automatically and periodically. The benefit of using TTL is that hopefully you can control the total disk space usage and prevent the machine from running out of disks. Moreover, the query performance may downgrade as the total number of files goes up and the memory usage also increase as there are more files. Timely removing such files helps to keep at a high query performance level and reduce memory usage. The TTL operations in IoTDB are supported by the following three statements:

  • Set TTL
  1. SET TTL TO StorageGroupName TTLTime
  2. Eg. SET TTL TO root.group1 3600000
  3. This example means that for data in root.group1, only that of the latest 1 hour will remain, the
  4. older one is removed or made invisible.
  5. Note: TTLTime should be millisecond timestamp. When TTL is set, insertions that fall
  6. out of TTL will be rejected.
  • Unset TTL
  1. UNSET TTL TO StorageGroupName
  2. Eg. UNSET TTL TO root.group1
  3. This example means that data of all time will be accepted in this group.
  • Show TTL
  1. SHOW ALL TTL
  2. SHOW TTL ON StorageGroupNames
  3. Eg.1 SHOW ALL TTL
  4. This example will show TTLs of all databases.
  5. Eg.2 SHOW TTL ON root.group1,root.group2,root.group3
  6. This example will show TTLs of the specified 3 groups.
  7. Notice: databases without TTL will show a "null"

Notice: When you set TTL to some databases, data out of the TTL will be made invisible immediately, but because the data files may contain both out-dated and living data or the data files may be being used by queries, the physical removal of data is stale. If you increase or unset TTL just after setting it previously, some previously invisible data may be seen again, but the physically removed one is lost forever. In other words, different from delete statement, the atomicity of data deletion is not guaranteed for efficiency concerns. So we recommend that you do not change the TTL once it is set or at least do not reset it frequently, unless you are determined to suffer the unpredictability.

  • Delete Partition (experimental)
  1. DELETE PARTITION StorageGroupName INT(COMMA INT)*
  2. Eg DELETE PARTITION root.sg1 0,1,2
  3. This example will delete the first 3 time partitions of database root.sg1.

The partitionId can be found in data folders or converted using timestamp / partitionInterval.

Kill query

  • Show the list of queries in progress
  1. SHOW QUERY PROCESSLIST
  • Kill query
  1. KILL QUERY INT?
  2. E.g. KILL QUERY
  3. E.g. KILL QUERY 2

SET STSTEM TO READONLY / WRITABLE

Set IoTDB system to read-only or writable mode.

  1. IoTDB> SET SYSTEM TO READONLY
  2. IoTDB> SET SYSTEM TO WRITABLE

Identifiers

  1. QUOTE := '\'';
  2. DOT := '.';
  3. COLON : ':' ;
  4. COMMA := ',' ;
  5. SEMICOLON := ';' ;
  6. LPAREN := '(' ;
  7. RPAREN := ')' ;
  8. LBRACKET := '[';
  9. RBRACKET := ']';
  10. EQUAL := '=' | '==';
  11. NOTEQUAL := '<>' | '!=';
  12. LESSTHANOREQUALTO := '<=';
  13. LESSTHAN := '<';
  14. GREATERTHANOREQUALTO := '>=';
  15. GREATERTHAN := '>';
  16. DIVIDE := '/';
  17. PLUS := '+';
  18. MINUS := '-';
  19. STAR := '*';
  20. Letter := 'a'..'z' | 'A'..'Z';
  21. HexDigit := 'a'..'f' | 'A'..'F';
  22. Digit := '0'..'9';
  23. Boolean := TRUE | FALSE | 0 | 1 (case insensitive)
  1. StringLiteral := ( '\'' ( ~('\'') )* '\'';
  2. eg. 'abc'
  1. Integer := ('-' | '+')? Digit+;
  2. eg. 123
  3. eg. -222
  1. Float := ('-' | '+')? Digit+ DOT Digit+ (('e' | 'E') ('-' | '+')? Digit+)?;
  2. eg. 3.1415
  3. eg. 1.2E10
  4. eg. -1.33
  1. Identifier := (Letter | '_') (Letter | Digit | '_' | MINUS)*;
  2. eg. a123
  3. eg. _abc123

Literals

  1. PointValue : Integer | Float | StringLiteral | Boolean
  1. TimeValue : Integer | DateTime | ISO8601 | NOW()
  2. Note: Integer means timestamp type.
  3. DateTime :
  4. eg. 2016-11-16T16:22:33+08:00
  5. eg. 2016-11-16 16:22:33+08:00
  6. eg. 2016-11-16T16:22:33.000+08:00
  7. eg. 2016-11-16 16:22:33.000+08:00
  8. Note: DateTime Type can support several types, see Chapter 3 Datetime section for details.
  1. PrecedenceEqualOperator : EQUAL | NOTEQUAL | LESSTHANOREQUALTO | LESSTHAN | GREATERTHANOREQUALTO | GREATERTHAN
  1. Timeseries : ROOT [DOT \<LayerName\>]* DOT \<SensorName\>
  2. LayerName : Identifier
  3. SensorName : Identifier
  4. eg. root.ln.wf01.wt01.status
  5. eg. root.sgcc.wf03.wt01.temperature
  6. Note: Timeseries must be start with `root`(case insensitive) and end with sensor name.
  1. PrefixPath : ROOT (DOT \<LayerName\>)*
  2. LayerName : Identifier | STAR
  3. eg. root.sgcc
  4. eg. root.*
  1. Path: (ROOT | <LayerName>) (DOT <LayerName>)*
  2. LayerName: Identifier | STAR
  3. eg. root.ln.wf01.wt01.status
  4. eg. root.*.wf01.wt01.status
  5. eg. root.ln.wf01.wt01.*
  6. eg. *.wt01.*
  7. eg. *