into_clause is used to write data into the specified measurement, which is not currently supported.timezone_clause is used to convert timestamps into the local time of the specified time zone in the query result, which is currently supported.sql_order_by_clause is a newly added clause for CTSDB, which allows you to use SQL-style expressions to sort query results.InfluxDB OSS | TencentDB for CTSDB 3.0 |
select_stmt = "SELECT" fields from_clause [into_clause] [ where_clause ] [ group_by_clause ] [ order_by_clause ] [ limit_clause ] [ offset_clause ] [ slimit_clause ] [ soffset_clause ] [ timezone_clause ] | select_stmt = "SELECT" fields from_clause [ where_clause ] [ group_by_clause ] [ order_by_clause ] [ limit_clause ] [ offset_clause ] [ slimit_clause ] [ soffset_clause ] [ sql_order_by_clause ] |
SELECT_clause FROM ( SELECT_clause FROM ( SELECT_statement ) [...] ) [...] | Fully compatible |
Category of Data Queries | Query Statement |
Querying all data | select * from car |
Fetching partial data with pagination | select * from car limit 3 offset 2 |
Using aggregate functions as parameters of complex expressions | select (max(speed) + max(temp) - min(speed)) * count(speed) / 20 % 5 as f1, floor(min(speed)) & ceil(max(temp)) | round(min(speed)) ^ round(max(temp)) as f2, sqrt(pow(abs(max(speed)*min(speed)), 2)) as f3 from car group by time(3s), type fill(none) |
Performing aggregation calculations | select count(speed), mean(speed), count(temp), percentile(temp, 50) from car group by time(3s), type fill(none) limit 1 offset 1 slimit 2 soffset 1 |
Mixing a Selectors with field, group by time intervals | select max(speed)*6, speed*10 from car where time <= 2000000000ns group by time(1s) |
Mixing a Selectors with field, group by tag | select max(speed), pow(speed, temp/100.0) from car group by type |
Only fields, group by tag | select *, temp, sqrt(pow(abs(max(speed)), 3)) FROM car group by city |
InfluxDB OSS | CTSDB | Semantics |
with_tag_clause = "WITH KEY" ( "=" tag_key | "!=" tag_key | "=~" regex_lit | "IN (" tag_keys ")" ) . | Supported | This query semantics specifies one or more tag keys through a regular expression. For details, see Regular expressions. WITH KEY is a keyword used to indicate that the following clause will contain one or more tag keys and values. =, !=, =~ and IN: These are operators applicable for matching tag keys and values. =, !=, and =~ represent equality, inequality, and regular expression matching respectively. The IN operator is used to specify that the value of a tag key should be one from the given list. tag_key: The name of the tag key used for matching. regex_lit: The value used for matching the tag key. tag_keys: The value used to specify multiple tag keys to match. Example: SELECT * FROM http_requests_total WITH KEY (method != 'POST' AND method =~ 'PUT.*') | status_code IN ('200', '404') |
with_measurement_clause = "WITH MEASUREMENT" ( "=" measurement | "=~" regex_lit ) . | | This semantics uses the WITH MEASUREMENT clause to filter specified measurements, where regex_lit indicates the measurements to be matched. |
where_clause = "WHERE" expr. | | |
var_ref = measurement . | | Represents a variable reference that associates the variable with measurements. |
user_name = identifier . | | It defines a field named user_name whose value is identifier. |
unary_expr = "(" expr ")" | var_ref | time_lit | string_lit | int_lit | float_lit | bool_lit | duration_lit | regex_lit . | | It is the expression of unary_expr, which can consist of the following sub-expressions: (expr): represents an expression surrounded by brackets, where expr is another expression. var_ref: represents a variable reference used to refer to a measurement, field, or tag in InfluxDB. time_lit: represents a time literal used to represent a timestamp. string_lit: represents a string literal used to represent text data. int_lit: represents an integer literal used to represent integer data. float_lit: represents a floating-point literal used to represent floating-point data. bool_lit: represents a Boolean literal used to represent true or false. duration_lit: represents a time period literal used to indicate duration. regex_lit: represents a regular expression literal used to match patterns in text data. |
to_clause = "TO" user_name . | | Represents that when querying data in InfluxDB, the system sends the query result to a specified user. The user_name parameter refers to the name of the user who receives the query result. |
timezone_clause = tz(string_lit) . | Supported | It is used for timestamp data in CTSDB to specify the time zone information of the timestamp. For example, the following specifies data with the time zone information set to Asia/Shanghai. SELECT time, temperature FROM sensor_data WHERE time >= '2023-07-10T00:00:00.000Z' AND time < '2023-07-11T00:00:00.000Z' timezone_clause = tz('Asia/Shanghai'); |
tag_keys = tag_key { "," tag_key } . | Supported | It specifies a list of tag keys to be returned in the query results. The comma represents the separator between tag keys. The following query statement only returns the data whose value of tag tag3 is equal to value3 and whose timestamp is within the past hour. It will return values for the two tag keys tag1 and tag2 only. SELECT * FROM measurement1 WHERE tag3='value3' AND time > now() - 1h TAGS tag_keys=tag1,tag2 |
tag_key = identifier . | | Represents that the tag key consists of an identifier. Tags are metadata for each time series stored in InfluxDB, consisting of key-value pairs. You can use identifiers to name tag keys. For example: measurement 1, tag 1=value 1, tag 2=value 2, field 1=1, field 2=2 |
subscription_name = identifier . | | Represents that the subscription name consists of an identifier. |
soffset_clause = "SOFFSET" int_lit . | | soffset_clause is a syntactical structure used to specify the offset when querying time series data in InfluxDB. It consists of SOFFSET and an integer literal int_lit. For example: SELECT * FROM mymeasurement WHERE time > '2023-05-01T00:00:00Z' AND time < '2023-05-31T00:00:00Z' SOFFSET 10 |
slimit_clause = "SLIMIT" int_lit . | | slimit_clause is a syntax structure used to specify the limit on the number of returned results when querying time series data in InfluxDB. It consists of SLIMIT and an integer literal int_lit, can only be used in SELECT statements, and should be placed at the end of the query statement. For example: SELECT * FROM mymeasurement WHERE time > '2023-05-01T00:00:00Z' AND time < '2023-05-31T00:00:00Z' SLIMIT 10 |
series_id = int_lit . | | series_id is a syntactical structure used to specify the data series ID when querying time series data in InfluxDB. It consists of an integer literal int_lit. By using series_id, you can query a data series with a specified ID, but it can only be used in SELECT statements and should be placed at the end of the query statement. For example, querying the data series with ID 1234: SELECT * FROM mymeasurement WHERE series_id = 1234 |
retention_policy_shard_group_duration = "SHARD DURATION" duration_lit . | Not supported | - |
retention_policy_replication = "REPLICATION" int_lit . | Not supported | - |
retention_policy_option = retention_policy_duration | retention_policy_replication | retention_policy_shard_group_duration | "DEFAULT" . | Not supported | - |
retention_policy_name = "NAME" identifier . | Not supported | - |
retention_policy_duration = "DURATION" duration_lit . | Not supported | - |
retention_policy = identifier . | Not supported | - |
query_name = identifier . | Supported | query_name is a syntactical structure used to name query statements. The following uses the SELECT statement to query all data points in the measurement named mymeasurement within a specific time range, and uses GROUP BY to group the results. Then, the query results are stored in a query named mycount using INTO. SELECT COUNT(*) FROM mymeasurement WHERE time > '2023-05-01T00:00:00Z' AND time < '2023-05-31T00:00:00Z' GROUP BY time(1h) INTO mycount |
query_id = int_lit . | Supported | query_id is an identifier used to query named queries in InfluxDB. It consists of an integer literal int_lit. For example: SELECT * FROM 1234 |
privilege = "ALL" [ "PRIVILEGES" ] | "READ" | "WRITE" . | Not supported | - |
policy_name = identifier . | Not supported | - |
password = string_lit . | Supported | password is a syntactical structure used to specify a password when connecting to InfluxDB. It consists of a string literal string_lit. By using password, you can specify a password when connecting to InfluxDB for authentication. For example, using the influx command to connect to an InfluxDB instance named myinfluxdb.example.com, and specifying the username as myuser and the password as mypassword. The example is as follows: influx -username myuser -password 'mypassword' -host myinfluxdb.example.com -port 8086 |
order_by_clause = "ORDER BY" sort_fields . sort_fields = sort_field { "," sort_field } . sort_field = field_key [ ASC | DESC ] . | order_by_clause = ORDER BY time [ ASC | DESC ] sql_order_by_clause = SQLORDER BY {sql_order_expr [ ASC | DESC ] } [ ,...n ] SQLLIMIT N SQLOFFSET N] sql_order_expr = {alias | expr | position} | The ORDER BY clause is used to sort the query results according to the specified column. The ORDER BY clause should be followed by a sorting field, usually time, which is the default timestamp column for all measurements in InfluxDB. You can choose to sort in ascending (ASC) or descending (DESC) order. For example: SELECT * FROM mymeasurement WHERE time > '2023-05-01T00:00:00Z' AND time < '2023-05-31T00:00:00Z' ORDER BY time DESCIn addition to the ORDER BY clause of InfluxQL, there is also a similar SQLORDER BY clause with SQL syntax. It allows you to sort the query result using SQL-style expressions, and supports LIMIT and OFFSET clauses. For example, the following is an example using the SQLORDER BY clause: SELECT * FROM mymeasurement SQLORDER BY value DESC, time ASC SQLLIMIT 10 SQLOFFSET 20 |
on_cluse = "ON" db_name . | Supported | The ON clause is used to specify the target database of query operations. It is usually used for cross-database queries or performing queries in an InfluxDB instance with multiple databases. A database name should follow the ON clause. For example: SELECT * FROM mymeasurement ON mydatabase WHERE time > '2023-05-01T00:00:00Z' AND time < '2023-05-31T00:00:00Z' |
offset_clause = "OFFSET" int_lit . | | The OFFSET clause is used to specify the offset of the query result set. It is usually used together with the LIMIT clause to limit the size of the query result set and specify the offset from which to start returning results. An integer value should follow the OFFSET clause. For example: SELECT * FROM mymeasurement WHERE time > '2023-05-01T00:00:00Z' AND time < '2023-05-31T00:00:00Z' LIMIT 10 OFFSET 20 Note: The OFFSET clause should be placed after the LIMIT clause. If the OFFSET clause is omitted, the default offset is 0. If the size of the query result set is less than the specified offset, an empty result set is returned. |
measurements = measurement { "," measurement } . | | measurements is a list composed of multiple measurement names, used to specify the target measurements of query operations. It is usually used to perform query operations across multiple measurements. The syntax structure of measurements consists of one or more measurements, each representing a measurement name. For example, use a SELECT statement to query all data points in the specific time range from two measurements named measurement1 and measurement2. The execution statement is as follows: SELECT * FROM measurement1, measurement2 WHERE time > '2023-05-01T00:00:00Z' AND time < '2023-05-31T00:00:00Z' |
measurement_name = identifier | regex_lit . | measurement_name = identifier | measurement_name refers to a measurement name used to identify a set of data stored in InfluxDB. It is an identifier consisting of one or more letters, digits, or underscores and should start with a letter. |
measurement = measurement_name | ( policy_name "." measurement_name ) | ( db_name "." [ policy_name ] "." measurement_name ) . | measurement = measurement_name | measurement refers to a measurement, which is a data storage unit consisting of a measurement name, fields and tags. Each measurement contains one or more fields and zero or more tags for describing the features and attributes of the data. The syntax structure of measurement consists of a measurement_name, which indicates the name of the measurement. |
limit_clause = "LIMIT" int_lit . | Supported | limit_clause is used to limit the number of data points returned in the query result. It consists of the keyword LIMIT and an integer value, which represents the number of data points to be returned. |
into_clause = "INTO" ( measurement | back_ref ). | Not supported | - |
host = string_lit . | Supported | host refers to a host name used to identify the host to which the stored data in InfluxDB belongs. It is a string composed of a series of characters for uniquely identifying a host. |
groupby_clause = "GROUP BY" dimensions fill(fill_option). | | GROUP BY is used to group the query result by the specified dimension. The syntax structure of groupby_clause consists of the following components: "GROUP BY": keyword. It indicates grouping by the specified dimensions. dimensions: one or more dimensions, separated by commas. Dimensions can be fields or tag names in a measurement. fill(fill_option): an optional fill option used to specify how to handle missing data points. The following example uses a SELECT statement to query all data points in the measurement named my_measurement within a specific time range, groups the data points by the location tag, and finally calculates the average value of the data points in each group. SELECT mean(value) FROM my_measurement WHERE time > '2023-05-01T00:00:00Z' AND time < '2023-05-31T00:00:00Z' GROUP BY location |
from_clause = "FROM" measurements . | | FROM is used to specify the data source for the query, namely the measurement name. |
fill_option = "null" | "none" | "previous" | int_lit | float_lit | "linear" . | fill_option = "none" . | fill_option is used to specify how to handle missing data points in the query result. fill_option can be one of the following three options: fill(null): Fill missing data points with null. fill(previous): Fill missing data points with the value of the previous data point. fill(none): Ignore missing data points directly without filling them. |
fields = field { "," field } . | Supported | fields is used to specify the list of fields to be queried, which can consist of one or more fields, separated by commas. If you need to query all fields, you can use the wildcard "*". field: one or more field names, separated by commas. { "," field }: an optional repeated part, used to specify multiple field names. |
field_key = identifier . | | field_key is used to specify the field name in the measurement. identifier is an identifier used to specify the field name in the measurement. |
field = expr [ alias ] . | | field is used to specify a field in the query result. The syntax structure of field consists of the following components: expr: an expression used to calculate values in the query result. [ alias ]: an optional alias used to specify a name for a field in the query result. |
expr = unary_expr { binary_op unary_expr } . | | expr is used to represent an expression, which can be a constant, an identifier, or a complex expression consisting of operators and operands. The syntax structure of expr consists of the following components: unary_expr: a unary expression that can be a constant, an identifier, or an expression composed of a unary operator and an operand. { binary_op unary_expr }: an optional repeated part used to specify multiple binary operators and operands. |
dimensions = dimension { "," dimension } . | | dimensions is used to specify one or more dimensions in the query result. The syntax structure of dimensions consists of the following components: dimension: a dimension, used to specify a dimension in the query result. { "," dimension }: an optional repeated part, used to specify multiple dimensions. The following example uses a SELECT statement to query all data points in the measurement named my_measurement within a specific time range and calculate the average of the temperature field. We also use the GROUP BY clause to specify two dimensions, namely location and device, which means the query result will be grouped based on these two dimensions. SELECT mean(temperature) FROM my_measurement WHERE time > '2023-05-01T00:00:00Z' AND time < '2023-05-31T00:00:00Z' GROUP BY location, device |
dimension = expr . | | dimension is used to specify a dimension in the query result. expr refers to an expression used to calculate values in the query result. |
db_name = identifier . | | db_name is used to specify the database name in the measurement. identifier is an identifier used to specify the field name in the measurement. |
binary_op = "+" | "-" | "*" | "/" | "%" | "&" | "|" | "^" | "AND" | "OR" | "=" | "!=" | "<>" | "<" | "<=" | ">" | ">=" . | | Represents binary operators. These operators include the plus sign, minus sign, multiplication sign, division sign, modulo operation, bitwise AND, bitwise OR, bitwise XOR, logical AND, logical OR, equal to, not equal to, less than or equal to, greater than or equal to, less than, and greater than. These operators are used to operate on two values and return a result. |
back_ref = ( policy_name ".:MEASUREMENT" ) | ( db_name "." [ policy_name ] ".:MEASUREMENT" ) . | Not supported | - |
alias = "AS" identifier . | Supported | This semantics is used to create an alias. The alias consists of two parts: AS and identifier. AS is a keyword, and the identifier is used to represent the alias. SELECT mean(temperature) AS avg_temp, mean(humidity) AS avg_humid FROM weather; |
Feedback