doc: primary key document
This commit is contained in:
parent
e8af63c81e
commit
8e3452c72d
|
@ -25,7 +25,7 @@ create_definition:
|
|||
col_name column_definition
|
||||
|
||||
column_definition:
|
||||
type_name [comment 'string_value']
|
||||
type_name [comment 'string_value'] [PRIMARY KEY]
|
||||
|
||||
table_options:
|
||||
table_option ...
|
||||
|
@ -41,11 +41,12 @@ table_option: {
|
|||
**More explanations**
|
||||
|
||||
1. The first column of a table MUST be of type TIMESTAMP. It is automatically set as the primary key.
|
||||
2. The maximum length of the table name is 192 bytes.
|
||||
3. The maximum length of each row is 48k(64k since version 3.0.5.0) bytes, please note that the extra 2 bytes used by each BINARY/NCHAR/GEOMETRY column are also counted.
|
||||
4. The name of the subtable can only consist of characters from the English alphabet, digits and underscore. Table names can't start with a digit. Table names are case insensitive.
|
||||
5. The maximum length in bytes must be specified when using BINARY/NCHAR/GEOMETRY types.
|
||||
6. Escape character "\`" can be used to avoid the conflict between table names and reserved keywords, above rules will be bypassed when using escape character on table names, but the upper limit for the name length is still valid. The table names specified using escape character are case sensitive.
|
||||
2. In addition to the timestamp primary key column, an additional primary key column can be specified using the PRIMARY KEY keyword. The second column specified as the primary key must be of type integer or string (varchar).
|
||||
3. The maximum length of the table name is 192 bytes.
|
||||
4. The maximum length of each row is 48k(64k since version 3.0.5.0) bytes, please note that the extra 2 bytes used by each BINARY/NCHAR/GEOMETRY column are also counted.
|
||||
5. The name of the subtable can only consist of characters from the English alphabet, digits and underscore. Table names can't start with a digit. Table names are case insensitive.
|
||||
6. The maximum length in bytes must be specified when using BINARY/NCHAR/GEOMETRY types.
|
||||
7. Escape character "\`" can be used to avoid the conflict between table names and reserved keywords, above rules will be bypassed when using escape character on table names, but the upper limit for the name length is still valid. The table names specified using escape character are case sensitive.
|
||||
For example \`aBc\` and \`abc\` are different table names but `abc` and `aBc` are same table names because they are both converted to `abc` internally.
|
||||
Only ASCII visible characters can be used with escape character.
|
||||
|
||||
|
@ -107,6 +108,7 @@ You can perform the following modifications on existing tables:
|
|||
2. DROP COLUMN: deletes a column from the supertable.
|
||||
3. MODIFY COLUMN: changes the length of the data type specified for the column. Note that you can only specify a length greater than the current length.
|
||||
4. RENAME COLUMN: renames a specified column in the table.
|
||||
5. The primary key column a table cannot be modified or added or deleted using ADD/DROP COLUMN.
|
||||
|
||||
### Add a Column
|
||||
|
||||
|
|
|
@ -147,6 +147,7 @@ Modifications to the table schema of a supertable take effect on all subtables w
|
|||
- DROP TAG: deletes a tag from the supertable. When you delete a tag from a supertable, it is automatically deleted from all subtables within the supertable.
|
||||
- MODIFY TAG: modifies the definition of a tag in the supertable. You can use this keyword to change the length of a BINARY or NCHAR tag column. Note that you can only specify a length greater than the current length.
|
||||
- RENAME TAG: renames a specified tag in the supertable. When you rename a tag in a supertable, it is automatically renamed in all subtables within the supertable.
|
||||
- Like odinary tables, the primary key of a supertable cannot be modified or added or deleted using ADD/DROP COLUMN.
|
||||
|
||||
### Add a Column
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ INSERT INTO
|
|||
```
|
||||
|
||||
6. However, an INSERT statement that writes data to multiple subtables can succeed for some tables and fail for others. This situation is caused because vnodes perform write operations independently of each other. One vnode failing to write data does not affect the ability of other vnodes to write successfully.
|
||||
7. The primary key column value must be specified and cannot be NULL.
|
||||
|
||||
**Normal Syntax**
|
||||
1. The USING clause automatically creates the specified subtable if it does not exist. If it's unknown whether the table already exists, the table can be created automatically while inserting using the SQL statement below. To use this functionality, a STable must be used as template and tag values must be provided. Any tags that you do not specify will be assigned a null value.
|
||||
|
|
|
@ -503,38 +503,38 @@ TO_CHAR(ts, format_str_literal)
|
|||
|
||||
**Supported Formats**
|
||||
|
||||
| **Format** | **Comment**| **example** |
|
||||
| --- | --- | --- |
|
||||
|AM,am,PM,pm| Meridiem indicator(without periods) | 07:00:00am|
|
||||
|A.M.,a.m.,P.M.,p.m.| Meridiem indicator(with periods)| 07:00:00a.m.|
|
||||
|YYYY,yyyy|year, 4 or more digits| 2023-10-10|
|
||||
|YYY,yyy| year, last 3 digits| 023-10-10|
|
||||
|YY,yy| year, last 2 digits| 23-10-10|
|
||||
|Y,y| year, last digit| 3-10-10|
|
||||
|MONTH|full uppercase of month| 2023-JANUARY-01|
|
||||
|Month|full capitalized month| 2023-January-01|
|
||||
|month|full lowercase of month| 2023-january-01|
|
||||
|MON| abbreviated uppercase of month(3 char)| JAN, SEP|
|
||||
|Mon| abbreviated capitalized month| Jan, Sep|
|
||||
|mon|abbreviated lowercase of month| jan, sep|
|
||||
|MM,mm|month number 01-12|2023-01-01|
|
||||
|DD,dd|month day, 01-31||
|
||||
|DAY|full uppercase of week day|MONDAY|
|
||||
|Day|full capitalized week day|Monday|
|
||||
|day|full lowercase of week day|monday|
|
||||
|DY|abbreviated uppercase of week day|MON|
|
||||
|Dy|abbreviated capitalized week day|Mon|
|
||||
|dy|abbreviated lowercase of week day|mon|
|
||||
|DDD|year day, 001-366||
|
||||
|D,d|week day number, 1-7, Sunday(1) to Saturday(7)||
|
||||
|HH24,hh24|hour of day, 00-23|2023-01-30 23:59:59|
|
||||
|hh12,HH12, hh, HH| hour of day, 01-12|2023-01-30 12:59:59PM|
|
||||
|MI,mi|minute, 00-59||
|
||||
|SS,ss|second, 00-59||
|
||||
|MS,ms|milli second, 000-999||
|
||||
|US,us|micro second, 000000-999999||
|
||||
|NS,ns|nano second, 000000000-999999999||
|
||||
|TZH,tzh|time zone hour|2023-01-30 11:59:59PM +08|
|
||||
| **Format** | **Comment** | **example** |
|
||||
| ------------------- | ---------------------------------------------- | ------------------------- |
|
||||
| AM,am,PM,pm | Meridiem indicator(without periods) | 07:00:00am |
|
||||
| A.M.,a.m.,P.M.,p.m. | Meridiem indicator(with periods) | 07:00:00a.m. |
|
||||
| YYYY,yyyy | year, 4 or more digits | 2023-10-10 |
|
||||
| YYY,yyy | year, last 3 digits | 023-10-10 |
|
||||
| YY,yy | year, last 2 digits | 23-10-10 |
|
||||
| Y,y | year, last digit | 3-10-10 |
|
||||
| MONTH | full uppercase of month | 2023-JANUARY-01 |
|
||||
| Month | full capitalized month | 2023-January-01 |
|
||||
| month | full lowercase of month | 2023-january-01 |
|
||||
| MON | abbreviated uppercase of month(3 char) | JAN, SEP |
|
||||
| Mon | abbreviated capitalized month | Jan, Sep |
|
||||
| mon | abbreviated lowercase of month | jan, sep |
|
||||
| MM,mm | month number 01-12 | 2023-01-01 |
|
||||
| DD,dd | month day, 01-31 | |
|
||||
| DAY | full uppercase of week day | MONDAY |
|
||||
| Day | full capitalized week day | Monday |
|
||||
| day | full lowercase of week day | monday |
|
||||
| DY | abbreviated uppercase of week day | MON |
|
||||
| Dy | abbreviated capitalized week day | Mon |
|
||||
| dy | abbreviated lowercase of week day | mon |
|
||||
| DDD | year day, 001-366 | |
|
||||
| D,d | week day number, 1-7, Sunday(1) to Saturday(7) | |
|
||||
| HH24,hh24 | hour of day, 00-23 | 2023-01-30 23:59:59 |
|
||||
| hh12,HH12, hh, HH | hour of day, 01-12 | 2023-01-30 12:59:59PM |
|
||||
| MI,mi | minute, 00-59 | |
|
||||
| SS,ss | second, 00-59 | |
|
||||
| MS,ms | milli second, 000-999 | |
|
||||
| US,us | micro second, 000000-999999 | |
|
||||
| NS,ns | nano second, 000000000-999999999 | |
|
||||
| TZH,tzh | time zone hour | 2023-01-30 11:59:59PM +08 |
|
||||
|
||||
**More explanations**:
|
||||
- The output format of `Month`, `Day` are left aligined, like`2023-OCTOBER -01`, `2023-SEPTEMBER-01`, `September` is the longest, no paddings. Week days are slimilar.
|
||||
|
@ -955,6 +955,7 @@ FIRST(expr)
|
|||
- FIRST(\*) can be used to get the first non-null value of all columns; When querying a super table and multiResultFunctionStarReturnTags is set to 0 (default), FIRST(\*) only returns columns of super table; When set to 1, returns columns and tags of the super table.
|
||||
- NULL will be returned if all the values of the specified column are all NULL
|
||||
- A result will NOT be returned if all the columns in the result set are all NULL
|
||||
- For a table with composite primary key, the data with the smallest primary key value is returned.
|
||||
|
||||
### INTERP
|
||||
|
||||
|
@ -988,6 +989,7 @@ ignore_null_values: {
|
|||
- `INTERP` can be applied to supertable by interpolating primary key sorted data of all its childtables. It can also be used with `partition by tbname` when applied to supertable to generate interpolation on each single timeline.
|
||||
- Pseudocolumn `_irowts` can be used along with `INTERP` to return the timestamps associated with interpolation points(support after version 3.0.2.0).
|
||||
- Pseudocolumn `_isfilled` can be used along with `INTERP` to indicate whether the results are original records or data points generated by interpolation algorithm(support after version 3.0.3.0).
|
||||
- For a table with composite primary key, onley the data with the smallest primary key value is used to generate interpolation.
|
||||
|
||||
**Example**
|
||||
|
||||
|
@ -1017,6 +1019,7 @@ LAST(expr)
|
|||
- LAST(\*) can be used to get the last non-NULL value of all columns; When querying a super table and multiResultFunctionStarReturnTags is set to 0 (default), LAST(\*) only returns columns of super table; When set to 1, returns columns and tags of the super table.
|
||||
- If the values of a column in the result set are all NULL, NULL is returned for that column; if all columns in the result are all NULL, no result will be returned.
|
||||
- When it's used on a STable, if there are multiple values with the timestamp in the result set, one of them will be returned randomly and it's not guaranteed that the same value is returned if the same query is run multiple times.
|
||||
- For a table with composite primary key, the data with the largest primary key value is returned.
|
||||
|
||||
|
||||
### LAST_ROW
|
||||
|
@ -1038,6 +1041,7 @@ LAST_ROW(expr)
|
|||
- LAST_ROW(\*) can be used to get the last value of all columns; When querying a super table and multiResultFunctionStarReturnTags is set to 0 (default), LAST_ROW(\*) only returns columns of super table; When set to 1, returns columns and tags of the super table.
|
||||
- When it's used on a STable, if there are multiple values with the timestamp in the result set, one of them will be returned randomly and it's not guaranteed that the same value is returned if the same query is run multiple times.
|
||||
- Can't be used with `INTERVAL`.
|
||||
- Like `LAST`, the data with the largest primary key value is returned for a table with composite primary key.
|
||||
|
||||
### MAX
|
||||
|
||||
|
@ -1144,7 +1148,7 @@ TOP(expr, k)
|
|||
UNIQUE(expr)
|
||||
```
|
||||
|
||||
**Description**: The values that occur the first time in the specified column. The effect is similar to `distinct` keyword.
|
||||
**Description**: The values that occur the first time in the specified column. The effect is similar to `distinct` keyword. For a table with composite primary key, only the data with the smallest primary key value is returned.
|
||||
|
||||
**Return value type**:Same as the data type of the column being operated upon
|
||||
|
||||
|
@ -1190,7 +1194,7 @@ ignore_negative: {
|
|||
}
|
||||
```
|
||||
|
||||
**Description**: The derivative of a specific column. The time rage can be specified by parameter `time_interval`, the minimum allowed time range is 1 second (1s); the value of `ignore_negative` can be 0 or 1, 1 means negative values are ignored.
|
||||
**Description**: The derivative of a specific column. The time rage can be specified by parameter `time_interval`, the minimum allowed time range is 1 second (1s); the value of `ignore_negative` can be 0 or 1, 1 means negative values are ignored. For tables with composite primary key, the data with the smallest primary key value is used to calculate the derivative.
|
||||
|
||||
**Return value type**: DOUBLE
|
||||
|
||||
|
@ -1213,7 +1217,7 @@ ignore_negative: {
|
|||
}
|
||||
```
|
||||
|
||||
**Description**: The different of each row with its previous row for a specific column. `ignore_negative` can be specified as 0 or 1, the default value is 1 if it's not specified. `1` means negative values are ignored.
|
||||
**Description**: The different of each row with its previous row for a specific column. `ignore_negative` can be specified as 0 or 1, the default value is 1 if it's not specified. `1` means negative values are ignored. For tables with composite primary key, the data with the smallest primary key value is used to calculate the difference.
|
||||
|
||||
**Return value type**:Same as the data type of the column being operated upon
|
||||
|
||||
|
@ -1233,7 +1237,7 @@ ignore_negative: {
|
|||
IRATE(expr)
|
||||
```
|
||||
|
||||
**Description**: instantaneous rate on a specific column. The last two samples in the specified time range are used to calculate instantaneous rate. If the last sample value is smaller, then only the last sample value is used instead of the difference between the last two sample values.
|
||||
**Description**: instantaneous rate on a specific column. The last two samples in the specified time range are used to calculate instantaneous rate. If the last sample value is smaller, then only the last sample value is used instead of the difference between the last two sample values. For tables with composite primary key, the data with the smallest primary key value is used to calculate the rate.
|
||||
|
||||
**Return value type**: DOUBLE
|
||||
|
||||
|
@ -1323,7 +1327,7 @@ STATEDURATION(expr, oper, val, unit)
|
|||
TWA(expr)
|
||||
```
|
||||
|
||||
**Description**: Time weighted average on a specific column within a time range
|
||||
**Description**: Time weighted average on a specific column within a time range. For tables with composite primary key, the data with the smallest primary key value is used to calculate the average.
|
||||
|
||||
**Return value type**: DOUBLE
|
||||
|
||||
|
|
|
@ -11,13 +11,14 @@ Because stream processing is built in to TDengine, you are no longer reliant on
|
|||
## Create a Stream
|
||||
|
||||
```sql
|
||||
CREATE STREAM [IF NOT EXISTS] stream_name [stream_options] INTO stb_name SUBTABLE(expression) AS subquery
|
||||
CREATE STREAM [IF NOT EXISTS] stream_name [stream_options] INTO stb_name[(field1_name, filed2_name [PRIMARY KEY], ...)] [TAGS (create_definition [, create_definition] ...)] SUBTABLE(expression) AS subquery
|
||||
stream_options: {
|
||||
TRIGGER [AT_ONCE | WINDOW_CLOSE | MAX_DELAY time]
|
||||
WATERMARK time
|
||||
IGNORE EXPIRED [0|1]
|
||||
DELETE_MARK time
|
||||
FILL_HISTORY [0|1]
|
||||
IGNORE UPDATE [0|1]
|
||||
}
|
||||
|
||||
```
|
||||
|
@ -32,7 +33,7 @@ subquery: SELECT [DISTINCT] select_list
|
|||
[window_clause]
|
||||
```
|
||||
|
||||
Session windows, state windows, and sliding windows are supported. When you configure a session or state window for a supertable, you must use PARTITION BY TBNAME.
|
||||
Session windows, state windows, and sliding windows are supported. When you configure a session or state window for a supertable, you must use PARTITION BY TBNAME. If the source table has a composite primary key, state windows, event windows, and count windows are not supported.
|
||||
|
||||
Subtable Clause defines the naming rules of auto-created subtable, you can see more details in below part: Partitions of Stream.
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ where:
|
|||
- `tag_set` will be used as tags, with format like `<tag_key>=<tag_value>,<tag_key>=<tag_value>` Enter a space between `tag_set` and `field_set`.
|
||||
- `field_set`will be used as data columns, with format like `<field_key>=<field_value>,<field_key>=<field_value>` Enter a space between `field_set` and `timestamp`.
|
||||
- `timestamp` is the primary key timestamp corresponding to this row of data
|
||||
- schemaless writing does not support writing data to tables with a second primary key column.
|
||||
|
||||
All data in tag_set is automatically converted to the NCHAR data type and does not require double quotes (").
|
||||
|
||||
|
@ -38,24 +39,24 @@ In the schemaless writing data line protocol, each data item in the field_set ne
|
|||
- If there are double quotes on both sides and a B/b prefix, it means VARBINARY type. Hexadecimal start with \x or string can be used in double quotes. For example `B"\x98f46e"` `B"hello"`.
|
||||
- Spaces, equals sign (=), comma (,), double quote ("), and backslash (\\) need to be escaped with a backslash (\\) in front. (All refer to the ASCII character). The rules are as follows:
|
||||
|
||||
| **Serial number** | **Element** | **Escape characters** |
|
||||
| -------- | ----------- | ----------------------------- |
|
||||
| 1 | Measurement | Comma, Space |
|
||||
| 2 | Tag key | Comma, Equals Sign, Space |
|
||||
| 3 | Tag value | Comma, Equals Sign, Space |
|
||||
| 4 | Field key | Comma, Equals Sign, Space |
|
||||
| 5 | Field value | Double quote, Backslash |
|
||||
| **Serial number** | **Element** | **Escape characters** |
|
||||
| ----------------- | ----------- | ------------------------- |
|
||||
| 1 | Measurement | Comma, Space |
|
||||
| 2 | Tag key | Comma, Equals Sign, Space |
|
||||
| 3 | Tag value | Comma, Equals Sign, Space |
|
||||
| 4 | Field key | Comma, Equals Sign, Space |
|
||||
| 5 | Field value | Double quote, Backslash |
|
||||
|
||||
With two contiguous backslashes, the first is interpreted as an escape character. Examples of backslash escape rules are as follows:
|
||||
|
||||
| **Serial number** | **Backslashes** | **Interpreted as** |
|
||||
| -------- | ----------- | ----------------------------- |
|
||||
| 1 | \ | \ |
|
||||
| 2 | \\\\ | \ |
|
||||
| 3 | \\\\\\ | \\\\ |
|
||||
| 4 | \\\\\\\\ | \\\\ |
|
||||
| 5 | \\\\\\\\\\ | \\\\\\ |
|
||||
| 6 | \\\\\\\\\\\\ | \\\\\\ |
|
||||
| **Serial number** | **Backslashes** | **Interpreted as** |
|
||||
| ----------------- | --------------- | ------------------ |
|
||||
| 1 | \ | \ |
|
||||
| 2 | \\\\ | \ |
|
||||
| 3 | \\\\\\ | \\\\ |
|
||||
| 4 | \\\\\\\\ | \\\\ |
|
||||
| 5 | \\\\\\\\\\ | \\\\\\ |
|
||||
| 6 | \\\\\\\\\\\\ | \\\\\\ |
|
||||
|
||||
- Numeric types will be distinguished from data types by the suffix.
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ create_subtable_clause: {
|
|||
}
|
||||
|
||||
create_definition:
|
||||
col_name column_type
|
||||
col_name column_type [PRIMARY KEY]
|
||||
|
||||
table_options:
|
||||
table_option ...
|
||||
|
@ -38,12 +38,13 @@ table_option: {
|
|||
|
||||
**使用说明**
|
||||
|
||||
1. 表的第一个字段必须是 TIMESTAMP,并且系统自动将其设为主键;
|
||||
2. 表名最大长度为 192;
|
||||
3. 表的每行长度不能超过 48KB(从 3.0.5.0 版本开始为 64KB);(注意:每个 BINARY/NCHAR/GEOMETRY 类型的列还会额外占用 2 个字节的存储位置)
|
||||
4. 子表名只能由字母、数字和下划线组成,且不能以数字开头,不区分大小写
|
||||
5. 使用数据类型 BINARY/NCHAR/GEOMETRY,需指定其最长的字节数,如 BINARY(20),表示 20 字节;
|
||||
6. 为了兼容支持更多形式的表名,TDengine 引入新的转义符 "\`",可以让表名与关键词不冲突,同时不受限于上述表名称合法性约束检查。但是同样具有长度限制要求。使用转义字符以后,不再对转义字符中的内容进行大小写统一。
|
||||
1. 表的第一个字段必须是 TIMESTAMP,并且系统自动将其设为主键。
|
||||
2. 除时间戳主键列之外,还可以通过 PRIAMRY KEY 关键字指定第二列为额外的主键列。被指定为主键列的第二列必须为整型或字符串类型(varchar)。
|
||||
3. 表名最大长度为 192。
|
||||
4. 表的每行长度不能超过 48KB(从 3.0.5.0 版本开始为 64KB);(注意:每个 BINARY/NCHAR/GEOMETRY 类型的列还会额外占用 2 个字节的存储位置)。
|
||||
5. 子表名只能由字母、数字和下划线组成,且不能以数字开头,不区分大小写。
|
||||
6. 使用数据类型 BINARY/NCHAR/GEOMETRY,需指定其最长的字节数,如 BINARY(20),表示 20 字节。
|
||||
7. 为了兼容支持更多形式的表名,TDengine 引入新的转义符 "\`",可以让表名与关键词不冲突,同时不受限于上述表名称合法性约束检查。但是同样具有长度限制要求。使用转义字符以后,不再对转义字符中的内容进行大小写统一,
|
||||
例如:\`aBc\` 和 \`abc\` 是不同的表名,但是 abc 和 aBc 是相同的表名。
|
||||
|
||||
**参数说明**
|
||||
|
@ -106,6 +107,7 @@ alter_table_option: {
|
|||
2. DROP COLUMN:删除列。
|
||||
3. MODIFY COLUMN:修改列定义,如果数据列的类型是可变长类型,那么可以使用此指令修改其宽度,只能改大,不能改小。
|
||||
4. RENAME COLUMN:修改列名称。
|
||||
5. 普通表的主键列不能被修改,也不能通过 ADD/DROP COLUMN 来添加/删除主键列。
|
||||
|
||||
### 增加列
|
||||
|
||||
|
|
|
@ -148,6 +148,7 @@ alter_table_option: {
|
|||
- DROP TAG:删除超级表的一个标签。从超级表删除某个标签后,该超级表下的所有子表也会自动删除该标签。
|
||||
- MODIFY TAG:修改超级表的一个标签的列宽度。标签的类型只能是 nchar 和 binary,使用此指令可以修改其宽度,只能改大,不能改小。
|
||||
- RENAME TAG:修改超级表的一个标签的名称。从超级表修改某个标签名后,该超级表下的所有子表也会自动更新该标签名。
|
||||
- 与普通表一样,超级表的主键列不允许被修改,也不允许通过 ADD/DROP COLUMN 来添加或删除主键列。
|
||||
|
||||
### 增加列
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ INSERT INTO
|
|||
INSERT INTO d1001 USING meters TAGS('Beijing.Chaoyang', 2) VALUES('a');
|
||||
```
|
||||
6. 对于向多个子表插入数据的情况,依然会有部分数据写入失败,部分数据写入成功的情况。这是因为多个子表可能分布在不同的 VNODE 上,客户端将 INSERT 语句完整解析后,将数据发往各个涉及的 VNODE 上,每个 VNODE 独立进行写入操作。如果某个 VNODE 因为某些原因(比如网络问题或磁盘故障)导致写入失败,并不会影响其他 VNODE 节点的写入。
|
||||
7. 主键列值必须指定且不能为 NULL。
|
||||
|
||||
**正常语法说明**
|
||||
|
||||
|
|
|
@ -503,38 +503,38 @@ TO_CHAR(ts, format_str_literal)
|
|||
|
||||
**支持的格式**
|
||||
|
||||
| **格式** | **说明**| **例子** |
|
||||
| --- | --- | --- |
|
||||
|AM,am,PM,pm| 无点分隔的上午下午 | 07:00:00am|
|
||||
|A.M.,a.m.,P.M.,p.m.| 有点分隔的上午下午| 07:00:00a.m.|
|
||||
|YYYY,yyyy|年, 4个及以上数字| 2023-10-10|
|
||||
|YYY,yyy| 年, 最后3位数字| 023-10-10|
|
||||
|YY,yy| 年, 最后2位数字| 23-10-10|
|
||||
|Y,y|年, 最后一位数字| 3-10-10|
|
||||
|MONTH|月, 全大写| 2023-JANUARY-01|
|
||||
|Month|月, 首字母大写| 2023-January-01|
|
||||
|month|月, 全小写| 2023-january-01|
|
||||
|MON| 月, 缩写, 全大写(三个字符)| JAN, SEP|
|
||||
|Mon| 月, 缩写, 首字母大写| Jan, Sep|
|
||||
|mon|月, 缩写, 全小写| jan, sep|
|
||||
|MM,mm|月, 数字 01-12|2023-01-01|
|
||||
|DD,dd|月日, 01-31||
|
||||
|DAY|周日, 全大写|MONDAY|
|
||||
|Day|周日, 首字符大写|Monday|
|
||||
|day|周日, 全小写|monday|
|
||||
|DY|周日, 缩写, 全大写|MON|
|
||||
|Dy|周日, 缩写, 首字符大写|Mon|
|
||||
|dy|周日, 缩写, 全小写|mon|
|
||||
|DDD|年日, 001-366||
|
||||
|D,d|周日, 数字, 1-7, Sunday(1) to Saturday(7)||
|
||||
|HH24,hh24|小时, 00-23|2023-01-30 23:59:59|
|
||||
|hh12,HH12, hh, HH| 小时, 01-12|2023-01-30 12:59:59PM|
|
||||
|MI,mi|分钟, 00-59||
|
||||
|SS,ss|秒, 00-59||
|
||||
|MS,ms|毫秒, 000-999||
|
||||
|US,us|微秒, 000000-999999||
|
||||
|NS,ns|纳秒, 000000000-999999999||
|
||||
|TZH,tzh|时区小时|2023-01-30 11:59:59PM +08|
|
||||
| **格式** | **说明** | **例子** |
|
||||
| ------------------- | ----------------------------------------- | ------------------------- |
|
||||
| AM,am,PM,pm | 无点分隔的上午下午 | 07:00:00am |
|
||||
| A.M.,a.m.,P.M.,p.m. | 有点分隔的上午下午 | 07:00:00a.m. |
|
||||
| YYYY,yyyy | 年, 4个及以上数字 | 2023-10-10 |
|
||||
| YYY,yyy | 年, 最后3位数字 | 023-10-10 |
|
||||
| YY,yy | 年, 最后2位数字 | 23-10-10 |
|
||||
| Y,y | 年, 最后一位数字 | 3-10-10 |
|
||||
| MONTH | 月, 全大写 | 2023-JANUARY-01 |
|
||||
| Month | 月, 首字母大写 | 2023-January-01 |
|
||||
| month | 月, 全小写 | 2023-january-01 |
|
||||
| MON | 月, 缩写, 全大写(三个字符) | JAN, SEP |
|
||||
| Mon | 月, 缩写, 首字母大写 | Jan, Sep |
|
||||
| mon | 月, 缩写, 全小写 | jan, sep |
|
||||
| MM,mm | 月, 数字 01-12 | 2023-01-01 |
|
||||
| DD,dd | 月日, 01-31 | |
|
||||
| DAY | 周日, 全大写 | MONDAY |
|
||||
| Day | 周日, 首字符大写 | Monday |
|
||||
| day | 周日, 全小写 | monday |
|
||||
| DY | 周日, 缩写, 全大写 | MON |
|
||||
| Dy | 周日, 缩写, 首字符大写 | Mon |
|
||||
| dy | 周日, 缩写, 全小写 | mon |
|
||||
| DDD | 年日, 001-366 | |
|
||||
| D,d | 周日, 数字, 1-7, Sunday(1) to Saturday(7) | |
|
||||
| HH24,hh24 | 小时, 00-23 | 2023-01-30 23:59:59 |
|
||||
| hh12,HH12, hh, HH | 小时, 01-12 | 2023-01-30 12:59:59PM |
|
||||
| MI,mi | 分钟, 00-59 | |
|
||||
| SS,ss | 秒, 00-59 | |
|
||||
| MS,ms | 毫秒, 000-999 | |
|
||||
| US,us | 微秒, 000000-999999 | |
|
||||
| NS,ns | 纳秒, 000000000-999999999 | |
|
||||
| TZH,tzh | 时区小时 | 2023-01-30 11:59:59PM +08 |
|
||||
|
||||
**使用说明**:
|
||||
- `Month`, `Day`等的输出格式是左对齐的, 右侧添加空格, 如`2023-OCTOBER -01`, `2023-SEPTEMBER-01`, 9月是月份中英文字母数最长的, 因此9月没有空格. 星期类似.
|
||||
|
@ -957,6 +957,7 @@ FIRST(expr)
|
|||
- 如果要返回各个列的首个(时间戳最小)非 NULL 值,可以使用 FIRST(\*);查询超级表,且multiResultFunctionStarReturnTags设置为 0 (默认值) 时,FIRST(\*)只返回超级表的普通列;设置为 1 时,返回超级表的普通列和标签列。
|
||||
- 如果结果集中的某列全部为 NULL 值,则该列的返回结果也是 NULL;
|
||||
- 如果结果集中所有列全部为 NULL 值,则不返回结果。
|
||||
- 对于存在复合主键的表的查询,若最小时间戳的数据有多条,则只有对应的复合主键最小的数据被返回。
|
||||
|
||||
### INTERP
|
||||
|
||||
|
@ -989,6 +990,7 @@ ignore_null_values: {
|
|||
- INTERP 作用于超级表时, 会将该超级表下的所有子表数据按照主键列排序后进行插值计算,也可以搭配 PARTITION BY tbname 使用,将结果强制规约到单个时间线。
|
||||
- INTERP 可以与伪列 _irowts 一起使用,返回插值点所对应的时间戳(3.0.2.0版本以后支持)。
|
||||
- INTERP 可以与伪列 _isfilled 一起使用,显示返回结果是否为原始记录或插值算法产生的数据(3.0.3.0版本以后支持)。
|
||||
- INTERP 对于带复合主键的表的查询,若存在相同时间戳的数据,则只有对应的复合主键最小的数据参与运算。
|
||||
|
||||
### LAST
|
||||
|
||||
|
@ -1009,6 +1011,7 @@ LAST(expr)
|
|||
- 如果要返回各个列的最后(时间戳最大)一个非 NULL 值,可以使用 LAST(\*);查询超级表,且multiResultFunctionStarReturnTags设置为 0 (默认值) 时,LAST(\*)只返回超级表的普通列;设置为 1 时,返回超级表的普通列和标签列。
|
||||
- 如果结果集中的某列全部为 NULL 值,则该列的返回结果也是 NULL;如果结果集中所有列全部为 NULL 值,则不返回结果。
|
||||
- 在用于超级表时,时间戳完全一样且同为最大的数据行可能有多个,那么会从中随机返回一条,而并不保证多次运行所挑选的数据行必然一致。
|
||||
- 对于存在复合主键的表的查询,若最大时间戳的数据有多条,则只有对应的复合主键最大的数据被返回。
|
||||
|
||||
|
||||
### LAST_ROW
|
||||
|
@ -1029,6 +1032,7 @@ LAST_ROW(expr)
|
|||
- 如果要返回各个列的最后一条记录(时间戳最大),可以使用 LAST_ROW(\*);查询超级表,且multiResultFunctionStarReturnTags设置为 0 (默认值) 时,LAST_ROW(\*)只返回超级表的普通列;设置为 1 时,返回超级表的普通列和标签列。
|
||||
- 在用于超级表时,时间戳完全一样且同为最大的数据行可能有多个,那么会从中随机返回一条,而并不保证多次运行所挑选的数据行必然一致。
|
||||
- 不能与 INTERVAL 一起使用。
|
||||
- 与 LAST 函数一样,对于存在复合主键的表的查询,若最大时间戳的数据有多条,则只有对应的复合主键最大的数据被返回。
|
||||
|
||||
### MAX
|
||||
|
||||
|
@ -1135,7 +1139,7 @@ TOP(expr, k)
|
|||
UNIQUE(expr)
|
||||
```
|
||||
|
||||
**功能说明**:返回该列数据首次出现的值。该函数功能与 distinct 相似。
|
||||
**功能说明**:返回该列数据首次出现的值。该函数功能与 distinct 相似。对于存在复合主键的表的查询,若最小时间戳的数据有多条,则只有对应的复合主键最小的数据被返回。
|
||||
|
||||
**返回数据类型**:同应用的字段。
|
||||
|
||||
|
@ -1181,7 +1185,7 @@ ignore_negative: {
|
|||
}
|
||||
```
|
||||
|
||||
**功能说明**:统计表中某列数值的单位变化率。其中单位时间区间的长度可以通过 time_interval 参数指定,最小可以是 1 秒(1s);ignore_negative 参数的值可以是 0 或 1,为 1 时表示忽略负值。
|
||||
**功能说明**:统计表中某列数值的单位变化率。其中单位时间区间的长度可以通过 time_interval 参数指定,最小可以是 1 秒(1s);ignore_negative 参数的值可以是 0 或 1,为 1 时表示忽略负值。对于存在复合主键的表的查询,若时间戳相同的数据存在多条,则只有对应的复合主键最小的数据参与运算。
|
||||
|
||||
**返回数据类型**:DOUBLE。
|
||||
|
||||
|
@ -1204,7 +1208,7 @@ ignore_negative: {
|
|||
}
|
||||
```
|
||||
|
||||
**功能说明**:统计表中某列的值与前一行对应值的差。 ignore_negative 取值为 0|1 , 可以不填,默认值为 0. 不忽略负值。ignore_negative 为 1 时表示忽略负数。
|
||||
**功能说明**:统计表中某列的值与前一行对应值的差。 ignore_negative 取值为 0|1 , 可以不填,默认值为 0. 不忽略负值。ignore_negative 为 1 时表示忽略负数。对于你存在复合主键的表的查询,若时间戳相同的数据存在多条,则只有对应的复合主键最小的数据参与运算。
|
||||
|
||||
**返回数据类型**:同应用字段。
|
||||
|
||||
|
@ -1224,7 +1228,7 @@ ignore_negative: {
|
|||
IRATE(expr)
|
||||
```
|
||||
|
||||
**功能说明**:计算瞬时增长率。使用时间区间中最后两个样本数据来计算瞬时增长速率;如果这两个值呈递减关系,那么只取最后一个数用于计算,而不是使用二者差值。
|
||||
**功能说明**:计算瞬时增长率。使用时间区间中最后两个样本数据来计算瞬时增长速率;如果这两个值呈递减关系,那么只取最后一个数用于计算,而不是使用二者差值。对于存在复合主键的表的查询,若时间戳相同的数据存在多条,则只有对应的复合主键最小的数据参与运算。
|
||||
|
||||
**返回数据类型**:DOUBLE。
|
||||
|
||||
|
@ -1314,7 +1318,7 @@ STATEDURATION(expr, oper, val, unit)
|
|||
TWA(expr)
|
||||
```
|
||||
|
||||
**功能说明**:时间加权平均函数。统计表中某列在一段时间内的时间加权平均。
|
||||
**功能说明**:时间加权平均函数。统计表中某列在一段时间内的时间加权平均。对于存在复合主键的表的查询,若时间戳相同的数据存在多条,则只有对应的复合主键最小的数据参与运算。
|
||||
|
||||
**返回数据类型**:DOUBLE。
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ description: 流式计算的相关 SQL 的详细语法
|
|||
## 创建流式计算
|
||||
|
||||
```sql
|
||||
CREATE STREAM [IF NOT EXISTS] stream_name [stream_options] INTO stb_name[(field1_name, ...)] [TAGS (create_definition [, create_definition] ...)] SUBTABLE(expression) AS subquery
|
||||
CREATE STREAM [IF NOT EXISTS] stream_name [stream_options] INTO stb_name[(field1_name, filed2_name [PRIMARY KEY], ...)] [TAGS (create_definition [, create_definition] ...)] SUBTABLE(expression) AS subquery
|
||||
stream_options: {
|
||||
TRIGGER [AT_ONCE | WINDOW_CLOSE | MAX_DELAY time]
|
||||
WATERMARK time
|
||||
|
@ -30,9 +30,9 @@ subquery: SELECT select_list
|
|||
[window_clause]
|
||||
```
|
||||
|
||||
支持会话窗口、状态窗口、滑动窗口、事件窗口和计数窗口,其中,状态窗口、事件窗口和计数窗口搭配超级表时必须与partition by tbname一起使用
|
||||
支持会话窗口、状态窗口、滑动窗口、事件窗口和计数窗口,其中,状态窗口、事件窗口和计数窗口搭配超级表时必须与partition by tbname一起使用。对于数据源表是复合主键的流,不支持状态窗口、事件窗口、计数窗口的计算。
|
||||
|
||||
stb_name 是保存计算结果的超级表的表名,如果该超级表不存在,会自动创建;如果已存在,则检查列的schema信息。详见 写入已存在的超级表
|
||||
stb_name 是保存计算结果的超级表的表名,如果该超级表不存在,会自动创建;如果已存在,则检查列的schema信息。详见 写入已存在的超级表。
|
||||
|
||||
TAGS 子句定义了流计算中创建TAG的规则,可以为每个partition对应的子表生成自定义的TAG值,详见 自定义TAG
|
||||
```sql
|
||||
|
|
|
@ -28,6 +28,7 @@ measurement,tag_set field_set timestamp
|
|||
- tag_set 将作为标签数据,其格式形如 `<tag_key>=<tag_value>,<tag_key>=<tag_value>`,也即可以使用英文逗号来分隔多个标签数据。它与 field_set 之间使用一个半角空格来分隔。
|
||||
- field_set 将作为普通列数据,其格式形如 `<field_key>=<field_value>,<field_key>=<field_value>`,同样是使用英文逗号来分隔多个普通列的数据。它与 timestamp 之间使用一个半角空格来分隔。
|
||||
- timestamp 即本行数据对应的主键时间戳。
|
||||
- 无模式写入不支持含第二主键列的表的数据写入。
|
||||
|
||||
tag_set 中的所有的数据自动转化为 nchar 数据类型,并不需要使用双引号(")。
|
||||
|
||||
|
|
Loading…
Reference in New Issue