diff --git a/src/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md b/src/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md index bfcb44b69..b8469018e 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md +++ b/src/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md @@ -53,10 +53,6 @@ This command is used to create a database. **Examples:** ```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// Sets TTL to 1 year. CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -73,7 +69,7 @@ USE **Example:** ```SQL -USE database1 +USE database1; ``` ### 1.3 View the Current Database @@ -89,16 +85,10 @@ SHOW CURRENT_DATABASE **Example:** ```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE database1; - -IoTDB> SHOW CURRENT_DATABASE; +USE database1; +SHOW CURRENT_DATABASE; +``` +```shell +---------------+ |CurrentDatabase| +---------------+ @@ -106,6 +96,7 @@ IoTDB> SHOW CURRENT_DATABASE; +---------------+ ``` + ### 1.4 View All Databases Displays all databases and their properties. @@ -131,15 +122,9 @@ SHOW DATABASES (DETAILS)? **Examples:** ```SQL -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -| database1| INF| 1| 1| 604800000| -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details +SHOW DATABASES DETAILS; +``` +```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum|DataRegionGroupNum| +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -186,5 +171,5 @@ DROP DATABASE (IF EXISTS)? **Example:** ```SQL -DROP DATABASE IF EXISTS database1 +DROP DATABASE IF EXISTS database1; ``` diff --git a/src/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md b/src/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md index 49b16dd01..2ac3e52fd 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md +++ b/src/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md @@ -53,10 +53,6 @@ This command is used to create a database. **Examples:** ```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// Sets TTL to 1 year. CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -73,7 +69,7 @@ USE **Example:** ```SQL -USE database1 +USE database1; ``` ### 1.3 View the Current Database @@ -89,16 +85,10 @@ SHOW CURRENT_DATABASE **Example:** ```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE database1; - -IoTDB> SHOW CURRENT_DATABASE; +USE database1; +SHOW CURRENT_DATABASE; +``` +```shell +---------------+ |CurrentDatabase| +---------------+ @@ -106,6 +96,7 @@ IoTDB> SHOW CURRENT_DATABASE; +---------------+ ``` + ### 1.4 View All Databases Displays all databases and their properties. @@ -131,15 +122,9 @@ SHOW DATABASES (DETAILS)? **Examples:** ```SQL -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -| database1| INF| 1| 1| 604800000| -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details +SHOW DATABASES DETAILS; +``` +```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum|DataRegionGroupNum| +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -186,5 +171,5 @@ DROP DATABASE (IF EXISTS)? **Example:** ```SQL -DROP DATABASE IF EXISTS database1 +DROP DATABASE IF EXISTS database1; ``` diff --git a/src/UserGuide/Master/Table/Basic-Concept/Delete-Data.md b/src/UserGuide/Master/Table/Basic-Concept/Delete-Data.md index 86a9492e7..b3fb9b9af 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/Delete-Data.md +++ b/src/UserGuide/Master/Table/Basic-Concept/Delete-Data.md @@ -69,34 +69,21 @@ The [Example Data page](../Reference/Sample-Data.md)page provides SQL statements #### 1.2.1 Delet All Data from a Table ```SQL -# Whole table deletion -DELETE FROM table1 +DELETE FROM table1; ``` #### 1.2.2 Delete Data within a Specific Time Range ```SQL -# Single time interval deletion -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - -# Multi time interval deletion -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` #### 1.2.3 Deleting Data for a Specific Device ```SQL -# Device-specific deletion -# Identifier conditions only support the '=' operator -DELETE FROM table1 WHERE device_id='101' and model_id = 'B' - -# Device-specific deletion with time interval DELETE FROM table1 WHERE time >= 2024-11-27 16:39:00 and time <= 2024-11-29 16:42:00 - AND device_id='101' and model_id = 'B' - -# Device-type-specific deletion -DELETE FROM table1 WHERE model_id = 'B' + AND device_id='101' and model_id = 'B'; ``` ## 2. Device Deletion @@ -117,5 +104,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? ### 2.2 Example ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md b/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md index 23789deec..aeccefc2c 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md +++ b/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md @@ -47,7 +47,7 @@ If TTL is specified when creating a table using SQL, the table’s TTL takes pre Example 1: Setting TTL during table creation: ```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600) +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600); ``` Example 2: Changing TTL for an existing table: @@ -59,9 +59,9 @@ ALTER TABLE tableB SET PROPERTIES TTL=3600; **Example 3:** If TTL is not specified or set to the default value, it will inherit the database's TTL. By default, the database TTL is `'INF'` (infinite): ```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("site" string id, "temperature" int32) -ALTER TABLE tableB set properties TTL=DEFAULT +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT); +CREATE TABLE test3 ("site" string id, "temperature" int32); +ALTER TABLE tableB set properties TTL=DEFAULT; ``` ### 2.2 Set TTL for Databases @@ -71,25 +71,25 @@ Tables without explicit TTL settings inherit the TTL of their database. Refer to Example 4: A database with TTL=3600000 creates tables inheriting this TTL: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32); ``` Example 5: A database without a TTL setting creates tables without TTL: ```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) +CREATE DATABASE db; +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32); ``` Example 6: Setting a table with no TTL explicitly (TTL=INF) in a database with a configured TTL: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF'); ``` ## 3. Remove TTL @@ -97,7 +97,7 @@ CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') To cancel a TTL setting, modify the table's TTL to 'INF'. Note that IoTDB does not currently support modifying the TTL of a database. ```SQL -ALTER TABLE tableB set properties TTL='INF' +ALTER TABLE tableB set properties TTL='INF'; ``` ## 4. View TTL Information @@ -109,7 +109,7 @@ Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for database Example Output: ```SQL -IoTDB> show databases +IoTDB> show databases; +---------+-------+-----------------------+---------------------+---------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| +---------+-------+-----------------------+---------------------+---------------------+ @@ -117,14 +117,14 @@ IoTDB> show databases | test2| 300| 1| 1| 604800000| +---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details +IoTDB> show databases details; +---------+-------+-----------------------+---------------------+---------------------+-----+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| +---------+-------+-----------------------+---------------------+---------------------+-----+ |test_prop| 300| 1| 3| 100000|TABLE| | test2| 300| 1| 1| 604800000| TREE| +---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables +IoTDB> show tables; +---------+-------+ |TableName|TTL(ms)| +---------+-------+ @@ -133,7 +133,7 @@ IoTDB> show tables | flower| INF| +---------+-------+ -IoTDB> show tables details +IoTDB> show tables details; +---------+-------+----------+ |TableName|TTL(ms)| Status| +---------+-------+----------+ diff --git a/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md b/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md index c29379e6b..de696fa1d 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md +++ b/src/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md @@ -47,7 +47,7 @@ If TTL is specified when creating a table using SQL, the table’s TTL takes pre Example 1: Setting TTL during table creation: ```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600) +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600); ``` Example 2: Changing TTL for an existing table: @@ -59,9 +59,9 @@ ALTER TABLE tableB SET PROPERTIES TTL=3600; **Example 3:** If TTL is not specified or set to the default value, it will inherit the database's TTL. By default, the database TTL is `'INF'` (infinite): ```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("site" string id, "temperature" int32) -ALTER TABLE tableB set properties TTL=DEFAULT +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT); +CREATE TABLE test3 ("site" string id, "temperature" int32); +ALTER TABLE tableB set properties TTL=DEFAULT; ``` ### 2.2 Set TTL for Databases @@ -71,25 +71,25 @@ Tables without explicit TTL settings inherit the TTL of their database. Refer to Example 4: A database with TTL=3600000 creates tables inheriting this TTL: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32); ``` Example 5: A database without a TTL setting creates tables without TTL: ```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) +CREATE DATABASE db; +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32); ``` Example 6: Setting a table with no TTL explicitly (TTL=INF) in a database with a configured TTL: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF'); ``` ## 3. Remove TTL @@ -97,7 +97,7 @@ CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') To cancel a TTL setting, modify the table's TTL to 'INF'. Note that IoTDB does not currently support modifying the TTL of a database. ```SQL -ALTER TABLE tableB set properties TTL='INF' +ALTER TABLE tableB set properties TTL='INF'; ``` ## 4. View TTL Information @@ -109,7 +109,7 @@ Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for database Example Output: ```SQL -IoTDB> show databases +IoTDB> show databases; +---------+-------+-----------------------+---------------------+---------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| +---------+-------+-----------------------+---------------------+---------------------+ @@ -117,14 +117,14 @@ IoTDB> show databases | test2| 300| 1| 1| 604800000| +---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details +IoTDB> show databases details; +---------+-------+-----------------------+---------------------+---------------------+-----+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| +---------+-------+-----------------------+---------------------+---------------------+-----+ |test_prop| 300| 1| 3| 100000|TABLE| | test2| 300| 1| 1| 604800000| TREE| +---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables +IoTDB> show tables; +---------+-------+ |TableName|TTL(ms)| +---------+-------+ @@ -133,7 +133,7 @@ IoTDB> show tables | flower| INF| +---------+-------+ -IoTDB> show tables details +IoTDB> show tables details; +---------+-------+----------+ |TableName|TTL(ms)| Status| +---------+-------+----------+ diff --git a/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md index d02429708..05642e030 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md +++ b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md @@ -107,21 +107,6 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); - - -CREATE TABLE if not exists tableB (); - -CREATE TABLE tableC ( - "Site" STRING TAG, - "Temperature" int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); - - -- Custom time column: named time_test, located in the second column of the table. - CREATE TABLE table1 ( - region STRING TAG, - time_user_defined TIMESTAMP TIME, - temperature FLOAT FIELD - ); ``` Note: If your terminal does not support multi-line paste (e.g., Windows CMD), please reformat the SQL statement into a single line before execution. @@ -147,16 +132,6 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? **Examples:** -```SQL -show tables from database1; -``` -```shell -+---------+---------------+ -|TableName| TTL(ms)| -+---------+---------------+ -| table1| 31536000000| -+---------+---------------+ -``` ```sql show tables details from database1; ``` @@ -187,25 +162,6 @@ Used to view column names, data types, categories, and states of a table. **Examples:** -```SQL -desc table1; -``` -```shell -+------------+---------+---------+ -| ColumnName| DataType| Category| -+------------+---------+---------+ -| time|TIMESTAMP| TIME| -| region| STRING| TAG| -| plant_id| STRING| TAG| -| device_id| STRING| TAG| -| model_id| STRING|ATTRIBUTE| -| maintenance| STRING|ATTRIBUTE| -| temperature| FLOAT| FIELD| -| humidity| FLOAT| FIELD| -| status| BOOLEAN| FIELD| -|arrival_time|TIMESTAMP| FIELD| -+------------+---------+---------+ -``` ```sql desc table1 details; ``` @@ -254,7 +210,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -284,10 +239,17 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col **Example:** +add column ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +set TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +set comment +```SQL COMMENT ON TABLE table1 IS 'table1'; COMMENT ON COLUMN table1.a IS null; ``` @@ -306,5 +268,4 @@ DROP TABLE (IF EXISTS)? ```SQL DROP TABLE table1; -DROP TABLE database1.table1; ``` \ No newline at end of file diff --git a/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md index 668521cea..f2e1bb2cd 100644 --- a/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md +++ b/src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md @@ -107,21 +107,6 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); - - -CREATE TABLE if not exists tableB (); - -CREATE TABLE tableC ( - "Site" STRING TAG, - "Temperature" int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); - - -- Custom time column: named time_test, located in the second column of the table. - CREATE TABLE table1 ( - region STRING TAG, - time_user_defined TIMESTAMP TIME, - temperature FLOAT FIELD - ); ``` Note: If your terminal does not support multi-line paste (e.g., Windows CMD), please reformat the SQL statement into a single line before execution. @@ -147,16 +132,6 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? **Examples:** -```SQL -show tables from database1; -``` -```shell -+---------+---------------+ -|TableName| TTL(ms)| -+---------+---------------+ -| table1| 31536000000| -+---------+---------------+ -``` ```sql show tables details from database1; ``` @@ -187,25 +162,6 @@ Used to view column names, data types, categories, and states of a table. **Examples:** -```SQL -desc table1; -``` -```shell -+------------+---------+---------+ -| ColumnName| DataType| Category| -+------------+---------+---------+ -| time|TIMESTAMP| TIME| -| region| STRING| TAG| -| plant_id| STRING| TAG| -| device_id| STRING| TAG| -| model_id| STRING|ATTRIBUTE| -| maintenance| STRING|ATTRIBUTE| -| temperature| FLOAT| FIELD| -| humidity| FLOAT| FIELD| -| status| BOOLEAN| FIELD| -|arrival_time|TIMESTAMP| FIELD| -+------------+---------+---------+ -``` ```sql desc table1 details; ``` @@ -289,12 +245,22 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col **Example:** +add column ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +set TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +set comment +```SQL COMMENT ON TABLE table1 IS 'table1'; COMMENT ON COLUMN table1.a IS null; +``` +alter column datatype +```SQL ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE; ``` @@ -338,7 +304,7 @@ In total, there are 6 unique tag combinations in the table, corresponding to 6 i ### Complete Calculation Example for Single-Table Measurement Points 1. Query the number of devices ```sql -IoTDB:database1> count devices from table1 +IoTDB:database1> count devices from table1; +--------------+ |count(devices)| +--------------+ diff --git a/src/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md b/src/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md index 6e7de7623..272fc5c4e 100644 --- a/src/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md +++ b/src/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md @@ -34,18 +34,18 @@ INSERT INTO [(COLUMN_NAME[, COLUMN_NAME]*)]? VALUES (COLUMN_VALUE[, **Example 1: Specified Columns Insertion** ```SQL -INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:38:00', 91.0) +INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:38:00', 91.0); ``` **Example 2: NULL Value Insertion** +Equivalent to the example above ```SQL -# Equivalent to the example above -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null); ``` **Example 3: Multi-row Insertion** @@ -54,13 +54,13 @@ INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, tem INSERT INTO table1 VALUES ('2025-11-26 13:37:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('2025-11-26 13:38:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25') +('2025-11-26 13:38:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25'); INSERT INTO table1 (region, plant_id, device_id, model_id, maintenance, time, temperature, humidity, status, arrival_time) VALUES ('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:37:00', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25') +('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25'); ``` **Example 4: Query Write-back** @@ -91,7 +91,7 @@ updateAssignment **Example:** ```SQL -update table1 set b = a where substring(a, 1, 1) like '%' +update table1 set b = a where substring(a, 1, 1) like '%'; ``` ## 3. Data Deletion @@ -125,32 +125,35 @@ ID_CONDITION: **Example 1: Full Table Deletion** ```SQL -DELETE FROM table1 +DELETE FROM table1; ``` **Example 2: Time-range Deletion** +Single time range ```SQL --- Single time range -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - --- Multiple time ranges -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00; +``` +Multiple time ranges +```sql +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` **Example 3: Device-Specific Deletion** +Delete data for specific device ```SQL --- Delete data for specific device DELETE FROM table1 WHERE device_id='101' AND model_id = 'B'; - --- Delete data for device within time range +``` +Delete data for device within time range +```sql DELETE FROM table1 WHERE time >= '2024-11-27 16:39:00' AND time <= '2024-11-29 16:42:00' AND device_id='101' AND model_id = 'B'; - --- Delete data for specific device model +``` +Delete data for specific device model +```sql DELETE FROM table1 WHERE model_id = 'B'; ``` @@ -165,5 +168,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? **Example: Delete specified device and all associated data** ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` diff --git a/src/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md b/src/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md index 74163386d..fc9593436 100644 --- a/src/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md +++ b/src/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md @@ -34,18 +34,18 @@ INSERT INTO [(COLUMN_NAME[, COLUMN_NAME]*)]? VALUES (COLUMN_VALUE[, **Example 1: Specified Columns Insertion** ```SQL -INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:38:00', 91.0) +INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:38:00', 91.0); ``` **Example 2: NULL Value Insertion** +Equivalent to the example above ```SQL -# Equivalent to the example above -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null); ``` **Example 3: Multi-row Insertion** @@ -54,13 +54,13 @@ INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, tem INSERT INTO table1 VALUES ('2025-11-26 13:37:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('2025-11-26 13:38:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25') +('2025-11-26 13:38:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25'); INSERT INTO table1 (region, plant_id, device_id, model_id, maintenance, time, temperature, humidity, status, arrival_time) VALUES ('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:37:00', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25') +('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25'); ``` **Example 4: Query Write-back** @@ -91,7 +91,7 @@ updateAssignment **Example:** ```SQL -update table1 set b = a where substring(a, 1, 1) like '%' +update table1 set b = a where substring(a, 1, 1) like '%'; ``` ## 3. Data Deletion @@ -125,32 +125,35 @@ ID_CONDITION: **Example 1: Full Table Deletion** ```SQL -DELETE FROM table1 +DELETE FROM table1; ``` **Example 2: Time-range Deletion** +Single time range ```SQL --- Single time range -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - --- Multiple time ranges -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00; +``` +Multiple time ranges +```sql +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` **Example 3: Device-Specific Deletion** +Delete data for specific device ```SQL --- Delete data for specific device DELETE FROM table1 WHERE device_id='101' AND model_id = 'B'; - --- Delete data for device within time range +``` +Delete data for device within time range +```sql DELETE FROM table1 WHERE time >= '2024-11-27 16:39:00' AND time <= '2024-11-29 16:42:00' AND device_id='101' AND model_id = 'B'; - --- Delete data for specific device model +``` +Delete data for specific device model +```sql DELETE FROM table1 WHERE model_id = 'B'; ``` @@ -165,5 +168,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? **Example: Delete specified device and all associated data** ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` diff --git a/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md b/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md index 156b68990..566eecd6c 100644 --- a/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md +++ b/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md @@ -211,8 +211,10 @@ CREATE TABLE tableC ( "Site" STRING TAG, "Temperature" int32 FIELD COMMENT 'temperature' ) with (TTL=DEFAULT); - - -- Custom time column: named time_test, located in the second column of the table. (Support from V2.0.8) + ``` + +Custom time column: named time_test, located in the second column of the table. (Support from V2.0.8) +```sql CREATE TABLE table1 ( region STRING TAG, time_user_defined TIMESTAMP TIME, @@ -323,7 +325,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -346,14 +347,22 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col **Examples:** +add column ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +set TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +set comment +```SQL COMMENT ON TABLE table1 IS 'table1'; COMMENT ON COLUMN table1.a IS null; ``` + ### 2.6 Drop Table **Syntax:** diff --git a/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md b/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md index 3847f6b4c..7b6107b4e 100644 --- a/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md +++ b/src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md @@ -211,8 +211,10 @@ CREATE TABLE tableC ( "Site" STRING TAG, "Temperature" int32 FIELD COMMENT 'temperature' ) with (TTL=DEFAULT); - - -- Custom time column: named time_test, located in the second column of the table. (Support from V2.0.8.2) + ``` + +Custom time column: named time_test, located in the second column of the table. (Support from V2.0.8.2) + ```sql CREATE TABLE table1 ( region STRING TAG, time_user_defined TIMESTAMP TIME, @@ -323,7 +325,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -347,12 +348,22 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col **Examples:** +add column ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +set TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +set comment +```SQL COMMENT ON TABLE table1 IS 'table1'; COMMENT ON COLUMN table1.a IS null; +``` +alter column datatype +```SQL ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE; ``` diff --git a/src/UserGuide/Master/Table/SQL-Manual/Select-Clause_apache.md b/src/UserGuide/Master/Table/SQL-Manual/Select-Clause_apache.md index d308e58fb..3c70e6776 100644 --- a/src/UserGuide/Master/Table/SQL-Manual/Select-Clause_apache.md +++ b/src/UserGuide/Master/Table/SQL-Manual/Select-Clause_apache.md @@ -274,13 +274,18 @@ Total line number = 18 It costs 0.189s ``` - ### 3.2 Columns Function 1. Without combining expressions + +Query data from columns whose names start with 'm' ```sql --- Query data from columns whose names start with 'm' IoTDB:database1> select columns('^m.*') from table1 limit 5 +``` + +Results: + +```sql +--------+-----------+ |model_id|maintenance| +--------+-----------+ @@ -290,15 +295,27 @@ IoTDB:database1> select columns('^m.*') from table1 limit 5 | C| 90| | C| 90| +--------+-----------+ +``` - --- Query columns whose names start with 'o' - throw an exception if no columns match +Query columns whose names start with 'o' - throw an exception if no columns match +```sql IoTDB:database1> select columns('^o.*') from table1 limit 5 -Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*' +``` + +Results: +```sql +Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*' +``` --- Query data from columns whose names start with 'm' and rename them with 'series_' prefix +Query data from columns whose names start with 'm' and rename them with 'series_' prefix +```sql IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 +``` + +Results: + +```sql +---------------+------------------+ |series_model_id|series_maintenance| +---------------+------------------+ @@ -313,9 +330,15 @@ IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 2. With Expression Combination - Single COLUMNS Function + +Query the minimum value of all columns ```sql --- Query the minimum value of all columns IoTDB:database1> select min(columns(*)) from table1 +``` + +Results: + +```sql +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ | _col0_time|_col1_region|_col2_plant_id|_col3_device_id|_col4_model_id|_col5_maintenance|_col6_temperature|_col7_humidity|_col8_status| _col9_arrival_time| +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ @@ -327,33 +350,56 @@ IoTDB:database1> select min(columns(*)) from table1 > Usage Restriction: When multiple COLUMNS functions appear in the same expression, their parameters must be identical. +Query the sum of minimum and maximum values for columns starting with 'h' ```sql --- Query the sum of minimum and maximum values for columns starting with 'h' IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1 +``` + +Results: + +```sql +--------------+ |_col0_humidity| +--------------+ | 79.899994| +--------------+ +``` --- Error Case: Non-Identical COLUMNS Functions +Error Case: Non-Identical COLUMNS Functions +```sql IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1 +``` + +Results: + +```sql Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Multiple different COLUMNS in the same expression are not supported ``` - Multiple COLUMNS Functions in Different Expressions +Query minimum of 'h'-columns and maximum of 'h'-columns separately ```sql --- Query minimum of 'h'-columns and maximum of 'h'-columns separately IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1 +``` + +Results: + +```sql +--------------+--------------+ |_col0_humidity|_col1_humidity| +--------------+--------------+ | 34.8| 45.1| +--------------+--------------+ - --- Query minimum of 'h'-columns and maximum of 'te'-columns +``` +Query minimum of 'h'-columns and maximum of 'te'-columns +```sql IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 +``` + +Results: + +```sql +--------------+-----------------+ |_col0_humidity|_col1_temperature| +--------------+-----------------+ @@ -363,9 +409,14 @@ IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 3. In Where Clause +Query data where all 'h'-columns must be > 40 (equivalent to) ```sql --- Query data where all 'h'-columns must be > 40 (equivalent to) IoTDB:database1> select * from table1 where columns('^h.*') > 40 +``` + +Results: + +```sql +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -373,9 +424,16 @@ IoTDB:database1> select * from table1 where columns('^h.*') > 40 |2024-11-28T09:00:00.000+08:00| 上海| 3001| 100| C| 90| null| 40.9| true| null| |2024-11-28T11:00:00.000+08:00| 上海| 3001| 100| C| 90| 88.0| 45.1| true|2024-11-28T11:00:12.000+08:00| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ +``` ---Alternative syntax +Alternative syntax +```sql IoTDB:database1> select * from table1 where humidity > 40 +``` + +Results: + +```sql +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ diff --git a/src/UserGuide/Master/Table/SQL-Manual/Select-Clause_timecho.md b/src/UserGuide/Master/Table/SQL-Manual/Select-Clause_timecho.md index 75c5cd5c1..a489f8a90 100644 --- a/src/UserGuide/Master/Table/SQL-Manual/Select-Clause_timecho.md +++ b/src/UserGuide/Master/Table/SQL-Manual/Select-Clause_timecho.md @@ -281,7 +281,12 @@ It costs 0.189s **Example 1: Directly querying Object type data** ```sql -IoTDB:database1> SELECT s1 FROM table1 WHERE device_id = 'tag1' +IoTDB:database1> SELECT s1 FROM table1 WHERE device_id = 'tag1'; +``` + +Results: + +```sql +------------+ | s1| +------------+ @@ -295,6 +300,11 @@ It costs 0.428s ```sql IoTDB:database1> SELECT read_object(s1) FROM table1 WHERE device_id = 'tag1' +``` + +Results: + +```sql +------------+ | _col0| +------------+ @@ -308,9 +318,15 @@ It costs 0.188s ### 3.2 Columns Function 1. Without combining expressions + +Query data from columns whose names start with 'm' +```sql +IoTDB:database1> select columns('^m.*') from table1 limit 5; +``` + +Results: + ```sql --- Query data from columns whose names start with 'm' -IoTDB:database1> select columns('^m.*') from table1 limit 5 +--------+-----------+ |model_id|maintenance| +--------+-----------+ @@ -320,15 +336,27 @@ IoTDB:database1> select columns('^m.*') from table1 limit 5 | C| 90| | C| 90| +--------+-----------+ +``` + +Query columns whose names start with 'o' - throw an exception if no columns match +```sql +IoTDB:database1> select columns('^o.*') from table1 limit 5; +``` +Results: --- Query columns whose names start with 'o' - throw an exception if no columns match -IoTDB:database1> select columns('^o.*') from table1 limit 5 +```sql Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*' +``` +Query data from columns whose names start with 'm' and rename them with 'series_' prefix +```sql +IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5; +``` --- Query data from columns whose names start with 'm' and rename them with 'series_' prefix -IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 +Results: + +```sql +---------------+------------------+ |series_model_id|series_maintenance| +---------------+------------------+ @@ -343,9 +371,15 @@ IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 2. With Expression Combination - Single COLUMNS Function + +Query the minimum value of all columns ```sql --- Query the minimum value of all columns IoTDB:database1> select min(columns(*)) from table1 +``` + +Results: + +```sql +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ | _col0_time|_col1_region|_col2_plant_id|_col3_device_id|_col4_model_id|_col5_maintenance|_col6_temperature|_col7_humidity|_col8_status| _col9_arrival_time| +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ @@ -357,33 +391,57 @@ IoTDB:database1> select min(columns(*)) from table1 > Usage Restriction: When multiple COLUMNS functions appear in the same expression, their parameters must be identical. +Query the sum of minimum and maximum values for columns starting with 'h' ```sql --- Query the sum of minimum and maximum values for columns starting with 'h' IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1 +``` + +Results: + +```sql +--------------+ |_col0_humidity| +--------------+ | 79.899994| +--------------+ +``` --- Error Case: Non-Identical COLUMNS Functions +Error Case: Non-Identical COLUMNS Functions +```sql IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1 +``` + +Results: + +```sql Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Multiple different COLUMNS in the same expression are not supported ``` - Multiple COLUMNS Functions in Different Expressions +Query minimum of 'h'-columns and maximum of 'h'-columns separately ```sql --- Query minimum of 'h'-columns and maximum of 'h'-columns separately IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1 +``` + +Results: + +```sql +--------------+--------------+ |_col0_humidity|_col1_humidity| +--------------+--------------+ | 34.8| 45.1| +--------------+--------------+ +``` --- Query minimum of 'h'-columns and maximum of 'te'-columns +Query minimum of 'h'-columns and maximum of 'te'-columns +```sql IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 +``` + +Results: + +```sql +--------------+-----------------+ |_col0_humidity|_col1_temperature| +--------------+-----------------+ @@ -393,9 +451,14 @@ IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 3. In Where Clause +Query data where all 'h'-columns must be > 40 (equivalent to) ```sql --- Query data where all 'h'-columns must be > 40 (equivalent to) IoTDB:database1> select * from table1 where columns('^h.*') > 40 +``` + +Results: + +```sql +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -403,9 +466,16 @@ IoTDB:database1> select * from table1 where columns('^h.*') > 40 |2024-11-28T09:00:00.000+08:00| 上海| 3001| 100| C| 90| null| 40.9| true| null| |2024-11-28T11:00:00.000+08:00| 上海| 3001| 100| C| 90| 88.0| 45.1| true|2024-11-28T11:00:12.000+08:00| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ +``` ---Alternative syntax +Alternative syntax +```sql IoTDB:database1> select * from table1 where humidity > 40 +``` + +Results: + +```sql +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ diff --git a/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md index bfcb44b69..b8469018e 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md @@ -53,10 +53,6 @@ This command is used to create a database. **Examples:** ```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// Sets TTL to 1 year. CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -73,7 +69,7 @@ USE **Example:** ```SQL -USE database1 +USE database1; ``` ### 1.3 View the Current Database @@ -89,16 +85,10 @@ SHOW CURRENT_DATABASE **Example:** ```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE database1; - -IoTDB> SHOW CURRENT_DATABASE; +USE database1; +SHOW CURRENT_DATABASE; +``` +```shell +---------------+ |CurrentDatabase| +---------------+ @@ -106,6 +96,7 @@ IoTDB> SHOW CURRENT_DATABASE; +---------------+ ``` + ### 1.4 View All Databases Displays all databases and their properties. @@ -131,15 +122,9 @@ SHOW DATABASES (DETAILS)? **Examples:** ```SQL -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -| database1| INF| 1| 1| 604800000| -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details +SHOW DATABASES DETAILS; +``` +```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum|DataRegionGroupNum| +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -186,5 +171,5 @@ DROP DATABASE (IF EXISTS)? **Example:** ```SQL -DROP DATABASE IF EXISTS database1 +DROP DATABASE IF EXISTS database1; ``` diff --git a/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md index 49b16dd01..2ac3e52fd 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md @@ -53,10 +53,6 @@ This command is used to create a database. **Examples:** ```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// Sets TTL to 1 year. CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -73,7 +69,7 @@ USE **Example:** ```SQL -USE database1 +USE database1; ``` ### 1.3 View the Current Database @@ -89,16 +85,10 @@ SHOW CURRENT_DATABASE **Example:** ```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE database1; - -IoTDB> SHOW CURRENT_DATABASE; +USE database1; +SHOW CURRENT_DATABASE; +``` +```shell +---------------+ |CurrentDatabase| +---------------+ @@ -106,6 +96,7 @@ IoTDB> SHOW CURRENT_DATABASE; +---------------+ ``` + ### 1.4 View All Databases Displays all databases and their properties. @@ -131,15 +122,9 @@ SHOW DATABASES (DETAILS)? **Examples:** ```SQL -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -| database1| INF| 1| 1| 604800000| -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details +SHOW DATABASES DETAILS; +``` +```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum|DataRegionGroupNum| +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -186,5 +171,5 @@ DROP DATABASE (IF EXISTS)? **Example:** ```SQL -DROP DATABASE IF EXISTS database1 +DROP DATABASE IF EXISTS database1; ``` diff --git a/src/UserGuide/latest-Table/Basic-Concept/Delete-Data.md b/src/UserGuide/latest-Table/Basic-Concept/Delete-Data.md index 86a9492e7..b3fb9b9af 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Delete-Data.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Delete-Data.md @@ -69,34 +69,21 @@ The [Example Data page](../Reference/Sample-Data.md)page provides SQL statements #### 1.2.1 Delet All Data from a Table ```SQL -# Whole table deletion -DELETE FROM table1 +DELETE FROM table1; ``` #### 1.2.2 Delete Data within a Specific Time Range ```SQL -# Single time interval deletion -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - -# Multi time interval deletion -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` #### 1.2.3 Deleting Data for a Specific Device ```SQL -# Device-specific deletion -# Identifier conditions only support the '=' operator -DELETE FROM table1 WHERE device_id='101' and model_id = 'B' - -# Device-specific deletion with time interval DELETE FROM table1 WHERE time >= 2024-11-27 16:39:00 and time <= 2024-11-29 16:42:00 - AND device_id='101' and model_id = 'B' - -# Device-type-specific deletion -DELETE FROM table1 WHERE model_id = 'B' + AND device_id='101' and model_id = 'B'; ``` ## 2. Device Deletion @@ -117,5 +104,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? ### 2.2 Example ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md index 23789deec..aeccefc2c 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md +++ b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md @@ -47,7 +47,7 @@ If TTL is specified when creating a table using SQL, the table’s TTL takes pre Example 1: Setting TTL during table creation: ```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600) +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600); ``` Example 2: Changing TTL for an existing table: @@ -59,9 +59,9 @@ ALTER TABLE tableB SET PROPERTIES TTL=3600; **Example 3:** If TTL is not specified or set to the default value, it will inherit the database's TTL. By default, the database TTL is `'INF'` (infinite): ```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("site" string id, "temperature" int32) -ALTER TABLE tableB set properties TTL=DEFAULT +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT); +CREATE TABLE test3 ("site" string id, "temperature" int32); +ALTER TABLE tableB set properties TTL=DEFAULT; ``` ### 2.2 Set TTL for Databases @@ -71,25 +71,25 @@ Tables without explicit TTL settings inherit the TTL of their database. Refer to Example 4: A database with TTL=3600000 creates tables inheriting this TTL: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32); ``` Example 5: A database without a TTL setting creates tables without TTL: ```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) +CREATE DATABASE db; +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32); ``` Example 6: Setting a table with no TTL explicitly (TTL=INF) in a database with a configured TTL: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF'); ``` ## 3. Remove TTL @@ -97,7 +97,7 @@ CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') To cancel a TTL setting, modify the table's TTL to 'INF'. Note that IoTDB does not currently support modifying the TTL of a database. ```SQL -ALTER TABLE tableB set properties TTL='INF' +ALTER TABLE tableB set properties TTL='INF'; ``` ## 4. View TTL Information @@ -109,7 +109,7 @@ Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for database Example Output: ```SQL -IoTDB> show databases +IoTDB> show databases; +---------+-------+-----------------------+---------------------+---------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| +---------+-------+-----------------------+---------------------+---------------------+ @@ -117,14 +117,14 @@ IoTDB> show databases | test2| 300| 1| 1| 604800000| +---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details +IoTDB> show databases details; +---------+-------+-----------------------+---------------------+---------------------+-----+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| +---------+-------+-----------------------+---------------------+---------------------+-----+ |test_prop| 300| 1| 3| 100000|TABLE| | test2| 300| 1| 1| 604800000| TREE| +---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables +IoTDB> show tables; +---------+-------+ |TableName|TTL(ms)| +---------+-------+ @@ -133,7 +133,7 @@ IoTDB> show tables | flower| INF| +---------+-------+ -IoTDB> show tables details +IoTDB> show tables details; +---------+-------+----------+ |TableName|TTL(ms)| Status| +---------+-------+----------+ diff --git a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md index c29379e6b..de696fa1d 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md +++ b/src/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md @@ -47,7 +47,7 @@ If TTL is specified when creating a table using SQL, the table’s TTL takes pre Example 1: Setting TTL during table creation: ```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600) +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=3600); ``` Example 2: Changing TTL for an existing table: @@ -59,9 +59,9 @@ ALTER TABLE tableB SET PROPERTIES TTL=3600; **Example 3:** If TTL is not specified or set to the default value, it will inherit the database's TTL. By default, the database TTL is `'INF'` (infinite): ```SQL -CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("site" string id, "temperature" int32) -ALTER TABLE tableB set properties TTL=DEFAULT +CREATE TABLE test3 ("site" string id, "temperature" int32) with (TTL=DEFAULT); +CREATE TABLE test3 ("site" string id, "temperature" int32); +ALTER TABLE tableB set properties TTL=DEFAULT; ``` ### 2.2 Set TTL for Databases @@ -71,25 +71,25 @@ Tables without explicit TTL settings inherit the TTL of their database. Refer to Example 4: A database with TTL=3600000 creates tables inheriting this TTL: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32); ``` Example 5: A database without a TTL setting creates tables without TTL: ```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) +CREATE DATABASE db; +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32); ``` Example 6: Setting a table with no TTL explicitly (TTL=INF) in a database with a configured TTL: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF'); ``` ## 3. Remove TTL @@ -97,7 +97,7 @@ CREATE TABLE test3 ("site" string id, "temperature" int32) with (ttl='INF') To cancel a TTL setting, modify the table's TTL to 'INF'. Note that IoTDB does not currently support modifying the TTL of a database. ```SQL -ALTER TABLE tableB set properties TTL='INF' +ALTER TABLE tableB set properties TTL='INF'; ``` ## 4. View TTL Information @@ -109,7 +109,7 @@ Use the SHOW DATABASES and SHOW TABLES commands to view TTL details for database Example Output: ```SQL -IoTDB> show databases +IoTDB> show databases; +---------+-------+-----------------------+---------------------+---------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| +---------+-------+-----------------------+---------------------+---------------------+ @@ -117,14 +117,14 @@ IoTDB> show databases | test2| 300| 1| 1| 604800000| +---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details +IoTDB> show databases details; +---------+-------+-----------------------+---------------------+---------------------+-----+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| +---------+-------+-----------------------+---------------------+---------------------+-----+ |test_prop| 300| 1| 3| 100000|TABLE| | test2| 300| 1| 1| 604800000| TREE| +---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables +IoTDB> show tables; +---------+-------+ |TableName|TTL(ms)| +---------+-------+ @@ -133,7 +133,7 @@ IoTDB> show tables | flower| INF| +---------+-------+ -IoTDB> show tables details +IoTDB> show tables details; +---------+-------+----------+ |TableName|TTL(ms)| Status| +---------+-------+----------+ diff --git a/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md index d02429708..05642e030 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md @@ -107,21 +107,6 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); - - -CREATE TABLE if not exists tableB (); - -CREATE TABLE tableC ( - "Site" STRING TAG, - "Temperature" int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); - - -- Custom time column: named time_test, located in the second column of the table. - CREATE TABLE table1 ( - region STRING TAG, - time_user_defined TIMESTAMP TIME, - temperature FLOAT FIELD - ); ``` Note: If your terminal does not support multi-line paste (e.g., Windows CMD), please reformat the SQL statement into a single line before execution. @@ -147,16 +132,6 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? **Examples:** -```SQL -show tables from database1; -``` -```shell -+---------+---------------+ -|TableName| TTL(ms)| -+---------+---------------+ -| table1| 31536000000| -+---------+---------------+ -``` ```sql show tables details from database1; ``` @@ -187,25 +162,6 @@ Used to view column names, data types, categories, and states of a table. **Examples:** -```SQL -desc table1; -``` -```shell -+------------+---------+---------+ -| ColumnName| DataType| Category| -+------------+---------+---------+ -| time|TIMESTAMP| TIME| -| region| STRING| TAG| -| plant_id| STRING| TAG| -| device_id| STRING| TAG| -| model_id| STRING|ATTRIBUTE| -| maintenance| STRING|ATTRIBUTE| -| temperature| FLOAT| FIELD| -| humidity| FLOAT| FIELD| -| status| BOOLEAN| FIELD| -|arrival_time|TIMESTAMP| FIELD| -+------------+---------+---------+ -``` ```sql desc table1 details; ``` @@ -254,7 +210,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -284,10 +239,17 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col **Example:** +add column ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +set TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +set comment +```SQL COMMENT ON TABLE table1 IS 'table1'; COMMENT ON COLUMN table1.a IS null; ``` @@ -306,5 +268,4 @@ DROP TABLE (IF EXISTS)? ```SQL DROP TABLE table1; -DROP TABLE database1.table1; ``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md index 668521cea..f2e1bb2cd 100644 --- a/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md +++ b/src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md @@ -107,21 +107,6 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); - - -CREATE TABLE if not exists tableB (); - -CREATE TABLE tableC ( - "Site" STRING TAG, - "Temperature" int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); - - -- Custom time column: named time_test, located in the second column of the table. - CREATE TABLE table1 ( - region STRING TAG, - time_user_defined TIMESTAMP TIME, - temperature FLOAT FIELD - ); ``` Note: If your terminal does not support multi-line paste (e.g., Windows CMD), please reformat the SQL statement into a single line before execution. @@ -147,16 +132,6 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? **Examples:** -```SQL -show tables from database1; -``` -```shell -+---------+---------------+ -|TableName| TTL(ms)| -+---------+---------------+ -| table1| 31536000000| -+---------+---------------+ -``` ```sql show tables details from database1; ``` @@ -187,25 +162,6 @@ Used to view column names, data types, categories, and states of a table. **Examples:** -```SQL -desc table1; -``` -```shell -+------------+---------+---------+ -| ColumnName| DataType| Category| -+------------+---------+---------+ -| time|TIMESTAMP| TIME| -| region| STRING| TAG| -| plant_id| STRING| TAG| -| device_id| STRING| TAG| -| model_id| STRING|ATTRIBUTE| -| maintenance| STRING|ATTRIBUTE| -| temperature| FLOAT| FIELD| -| humidity| FLOAT| FIELD| -| status| BOOLEAN| FIELD| -|arrival_time|TIMESTAMP| FIELD| -+------------+---------+---------+ -``` ```sql desc table1 details; ``` @@ -289,12 +245,22 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col **Example:** +add column ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +set TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +set comment +```SQL COMMENT ON TABLE table1 IS 'table1'; COMMENT ON COLUMN table1.a IS null; +``` +alter column datatype +```SQL ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE; ``` @@ -338,7 +304,7 @@ In total, there are 6 unique tag combinations in the table, corresponding to 6 i ### Complete Calculation Example for Single-Table Measurement Points 1. Query the number of devices ```sql -IoTDB:database1> count devices from table1 +IoTDB:database1> count devices from table1; +--------------+ |count(devices)| +--------------+ diff --git a/src/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md b/src/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md index 6e7de7623..272fc5c4e 100644 --- a/src/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md +++ b/src/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md @@ -34,18 +34,18 @@ INSERT INTO [(COLUMN_NAME[, COLUMN_NAME]*)]? VALUES (COLUMN_VALUE[, **Example 1: Specified Columns Insertion** ```SQL -INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:38:00', 91.0) +INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:38:00', 91.0); ``` **Example 2: NULL Value Insertion** +Equivalent to the example above ```SQL -# Equivalent to the example above -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null); ``` **Example 3: Multi-row Insertion** @@ -54,13 +54,13 @@ INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, tem INSERT INTO table1 VALUES ('2025-11-26 13:37:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('2025-11-26 13:38:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25') +('2025-11-26 13:38:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25'); INSERT INTO table1 (region, plant_id, device_id, model_id, maintenance, time, temperature, humidity, status, arrival_time) VALUES ('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:37:00', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25') +('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25'); ``` **Example 4: Query Write-back** @@ -91,7 +91,7 @@ updateAssignment **Example:** ```SQL -update table1 set b = a where substring(a, 1, 1) like '%' +update table1 set b = a where substring(a, 1, 1) like '%'; ``` ## 3. Data Deletion @@ -125,32 +125,35 @@ ID_CONDITION: **Example 1: Full Table Deletion** ```SQL -DELETE FROM table1 +DELETE FROM table1; ``` **Example 2: Time-range Deletion** +Single time range ```SQL --- Single time range -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - --- Multiple time ranges -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00; +``` +Multiple time ranges +```sql +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` **Example 3: Device-Specific Deletion** +Delete data for specific device ```SQL --- Delete data for specific device DELETE FROM table1 WHERE device_id='101' AND model_id = 'B'; - --- Delete data for device within time range +``` +Delete data for device within time range +```sql DELETE FROM table1 WHERE time >= '2024-11-27 16:39:00' AND time <= '2024-11-29 16:42:00' AND device_id='101' AND model_id = 'B'; - --- Delete data for specific device model +``` +Delete data for specific device model +```sql DELETE FROM table1 WHERE model_id = 'B'; ``` @@ -165,5 +168,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? **Example: Delete specified device and all associated data** ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` diff --git a/src/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md b/src/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md index 74163386d..fc9593436 100644 --- a/src/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md +++ b/src/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md @@ -34,18 +34,18 @@ INSERT INTO [(COLUMN_NAME[, COLUMN_NAME]*)]? VALUES (COLUMN_VALUE[, **Example 1: Specified Columns Insertion** ```SQL -INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:38:00', 91.0) +INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:38:00', 91.0); ``` **Example 2: NULL Value Insertion** +Equivalent to the example above ```SQL -# Equivalent to the example above -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null); ``` **Example 3: Multi-row Insertion** @@ -54,13 +54,13 @@ INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, tem INSERT INTO table1 VALUES ('2025-11-26 13:37:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('2025-11-26 13:38:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25') +('2025-11-26 13:38:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25'); INSERT INTO table1 (region, plant_id, device_id, model_id, maintenance, time, temperature, humidity, status, arrival_time) VALUES ('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:37:00', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25') +('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25'); ``` **Example 4: Query Write-back** @@ -91,7 +91,7 @@ updateAssignment **Example:** ```SQL -update table1 set b = a where substring(a, 1, 1) like '%' +update table1 set b = a where substring(a, 1, 1) like '%'; ``` ## 3. Data Deletion @@ -125,32 +125,35 @@ ID_CONDITION: **Example 1: Full Table Deletion** ```SQL -DELETE FROM table1 +DELETE FROM table1; ``` **Example 2: Time-range Deletion** +Single time range ```SQL --- Single time range -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - --- Multiple time ranges -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00; +``` +Multiple time ranges +```sql +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` **Example 3: Device-Specific Deletion** +Delete data for specific device ```SQL --- Delete data for specific device DELETE FROM table1 WHERE device_id='101' AND model_id = 'B'; - --- Delete data for device within time range +``` +Delete data for device within time range +```sql DELETE FROM table1 WHERE time >= '2024-11-27 16:39:00' AND time <= '2024-11-29 16:42:00' AND device_id='101' AND model_id = 'B'; - --- Delete data for specific device model +``` +Delete data for specific device model +```sql DELETE FROM table1 WHERE model_id = 'B'; ``` @@ -165,5 +168,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? **Example: Delete specified device and all associated data** ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` diff --git a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md index 156b68990..566eecd6c 100644 --- a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md +++ b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md @@ -211,8 +211,10 @@ CREATE TABLE tableC ( "Site" STRING TAG, "Temperature" int32 FIELD COMMENT 'temperature' ) with (TTL=DEFAULT); - - -- Custom time column: named time_test, located in the second column of the table. (Support from V2.0.8) + ``` + +Custom time column: named time_test, located in the second column of the table. (Support from V2.0.8) +```sql CREATE TABLE table1 ( region STRING TAG, time_user_defined TIMESTAMP TIME, @@ -323,7 +325,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -346,14 +347,22 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col **Examples:** +add column ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +set TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +set comment +```SQL COMMENT ON TABLE table1 IS 'table1'; COMMENT ON COLUMN table1.a IS null; ``` + ### 2.6 Drop Table **Syntax:** diff --git a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md index 3847f6b4c..7b6107b4e 100644 --- a/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md +++ b/src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md @@ -211,8 +211,10 @@ CREATE TABLE tableC ( "Site" STRING TAG, "Temperature" int32 FIELD COMMENT 'temperature' ) with (TTL=DEFAULT); - - -- Custom time column: named time_test, located in the second column of the table. (Support from V2.0.8.2) + ``` + +Custom time column: named time_test, located in the second column of the table. (Support from V2.0.8.2) + ```sql CREATE TABLE table1 ( region STRING TAG, time_user_defined TIMESTAMP TIME, @@ -323,7 +325,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -347,12 +348,22 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col **Examples:** +add column ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +set TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +set comment +```SQL COMMENT ON TABLE table1 IS 'table1'; COMMENT ON COLUMN table1.a IS null; +``` +alter column datatype +```SQL ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE; ``` diff --git a/src/UserGuide/latest-Table/SQL-Manual/Select-Clause_apache.md b/src/UserGuide/latest-Table/SQL-Manual/Select-Clause_apache.md index 3ca612e94..3c70e6776 100644 --- a/src/UserGuide/latest-Table/SQL-Manual/Select-Clause_apache.md +++ b/src/UserGuide/latest-Table/SQL-Manual/Select-Clause_apache.md @@ -277,9 +277,15 @@ It costs 0.189s ### 3.2 Columns Function 1. Without combining expressions + +Query data from columns whose names start with 'm' ```sql --- Query data from columns whose names start with 'm' IoTDB:database1> select columns('^m.*') from table1 limit 5 +``` + +Results: + +```sql +--------+-----------+ |model_id|maintenance| +--------+-----------+ @@ -289,15 +295,27 @@ IoTDB:database1> select columns('^m.*') from table1 limit 5 | C| 90| | C| 90| +--------+-----------+ +``` - --- Query columns whose names start with 'o' - throw an exception if no columns match +Query columns whose names start with 'o' - throw an exception if no columns match +```sql IoTDB:database1> select columns('^o.*') from table1 limit 5 -Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*' +``` + +Results: +```sql +Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*' +``` --- Query data from columns whose names start with 'm' and rename them with 'series_' prefix +Query data from columns whose names start with 'm' and rename them with 'series_' prefix +```sql IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 +``` + +Results: + +```sql +---------------+------------------+ |series_model_id|series_maintenance| +---------------+------------------+ @@ -312,9 +330,15 @@ IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 2. With Expression Combination - Single COLUMNS Function + +Query the minimum value of all columns ```sql --- Query the minimum value of all columns IoTDB:database1> select min(columns(*)) from table1 +``` + +Results: + +```sql +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ | _col0_time|_col1_region|_col2_plant_id|_col3_device_id|_col4_model_id|_col5_maintenance|_col6_temperature|_col7_humidity|_col8_status| _col9_arrival_time| +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ @@ -326,33 +350,56 @@ IoTDB:database1> select min(columns(*)) from table1 > Usage Restriction: When multiple COLUMNS functions appear in the same expression, their parameters must be identical. +Query the sum of minimum and maximum values for columns starting with 'h' ```sql --- Query the sum of minimum and maximum values for columns starting with 'h' IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1 +``` + +Results: + +```sql +--------------+ |_col0_humidity| +--------------+ | 79.899994| +--------------+ +``` --- Error Case: Non-Identical COLUMNS Functions +Error Case: Non-Identical COLUMNS Functions +```sql IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1 +``` + +Results: + +```sql Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Multiple different COLUMNS in the same expression are not supported ``` - Multiple COLUMNS Functions in Different Expressions +Query minimum of 'h'-columns and maximum of 'h'-columns separately ```sql --- Query minimum of 'h'-columns and maximum of 'h'-columns separately IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1 +``` + +Results: + +```sql +--------------+--------------+ |_col0_humidity|_col1_humidity| +--------------+--------------+ | 34.8| 45.1| +--------------+--------------+ - --- Query minimum of 'h'-columns and maximum of 'te'-columns +``` +Query minimum of 'h'-columns and maximum of 'te'-columns +```sql IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 +``` + +Results: + +```sql +--------------+-----------------+ |_col0_humidity|_col1_temperature| +--------------+-----------------+ @@ -362,9 +409,14 @@ IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 3. In Where Clause +Query data where all 'h'-columns must be > 40 (equivalent to) ```sql --- Query data where all 'h'-columns must be > 40 (equivalent to) IoTDB:database1> select * from table1 where columns('^h.*') > 40 +``` + +Results: + +```sql +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -372,9 +424,16 @@ IoTDB:database1> select * from table1 where columns('^h.*') > 40 |2024-11-28T09:00:00.000+08:00| 上海| 3001| 100| C| 90| null| 40.9| true| null| |2024-11-28T11:00:00.000+08:00| 上海| 3001| 100| C| 90| 88.0| 45.1| true|2024-11-28T11:00:12.000+08:00| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ +``` ---Alternative syntax +Alternative syntax +```sql IoTDB:database1> select * from table1 where humidity > 40 +``` + +Results: + +```sql +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ diff --git a/src/UserGuide/latest-Table/SQL-Manual/Select-Clause_timecho.md b/src/UserGuide/latest-Table/SQL-Manual/Select-Clause_timecho.md index 75c5cd5c1..a489f8a90 100644 --- a/src/UserGuide/latest-Table/SQL-Manual/Select-Clause_timecho.md +++ b/src/UserGuide/latest-Table/SQL-Manual/Select-Clause_timecho.md @@ -281,7 +281,12 @@ It costs 0.189s **Example 1: Directly querying Object type data** ```sql -IoTDB:database1> SELECT s1 FROM table1 WHERE device_id = 'tag1' +IoTDB:database1> SELECT s1 FROM table1 WHERE device_id = 'tag1'; +``` + +Results: + +```sql +------------+ | s1| +------------+ @@ -295,6 +300,11 @@ It costs 0.428s ```sql IoTDB:database1> SELECT read_object(s1) FROM table1 WHERE device_id = 'tag1' +``` + +Results: + +```sql +------------+ | _col0| +------------+ @@ -308,9 +318,15 @@ It costs 0.188s ### 3.2 Columns Function 1. Without combining expressions + +Query data from columns whose names start with 'm' +```sql +IoTDB:database1> select columns('^m.*') from table1 limit 5; +``` + +Results: + ```sql --- Query data from columns whose names start with 'm' -IoTDB:database1> select columns('^m.*') from table1 limit 5 +--------+-----------+ |model_id|maintenance| +--------+-----------+ @@ -320,15 +336,27 @@ IoTDB:database1> select columns('^m.*') from table1 limit 5 | C| 90| | C| 90| +--------+-----------+ +``` + +Query columns whose names start with 'o' - throw an exception if no columns match +```sql +IoTDB:database1> select columns('^o.*') from table1 limit 5; +``` +Results: --- Query columns whose names start with 'o' - throw an exception if no columns match -IoTDB:database1> select columns('^o.*') from table1 limit 5 +```sql Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*' +``` +Query data from columns whose names start with 'm' and rename them with 'series_' prefix +```sql +IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5; +``` --- Query data from columns whose names start with 'm' and rename them with 'series_' prefix -IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 +Results: + +```sql +---------------+------------------+ |series_model_id|series_maintenance| +---------------+------------------+ @@ -343,9 +371,15 @@ IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 2. With Expression Combination - Single COLUMNS Function + +Query the minimum value of all columns ```sql --- Query the minimum value of all columns IoTDB:database1> select min(columns(*)) from table1 +``` + +Results: + +```sql +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ | _col0_time|_col1_region|_col2_plant_id|_col3_device_id|_col4_model_id|_col5_maintenance|_col6_temperature|_col7_humidity|_col8_status| _col9_arrival_time| +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ @@ -357,33 +391,57 @@ IoTDB:database1> select min(columns(*)) from table1 > Usage Restriction: When multiple COLUMNS functions appear in the same expression, their parameters must be identical. +Query the sum of minimum and maximum values for columns starting with 'h' ```sql --- Query the sum of minimum and maximum values for columns starting with 'h' IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1 +``` + +Results: + +```sql +--------------+ |_col0_humidity| +--------------+ | 79.899994| +--------------+ +``` --- Error Case: Non-Identical COLUMNS Functions +Error Case: Non-Identical COLUMNS Functions +```sql IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1 +``` + +Results: + +```sql Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Multiple different COLUMNS in the same expression are not supported ``` - Multiple COLUMNS Functions in Different Expressions +Query minimum of 'h'-columns and maximum of 'h'-columns separately ```sql --- Query minimum of 'h'-columns and maximum of 'h'-columns separately IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1 +``` + +Results: + +```sql +--------------+--------------+ |_col0_humidity|_col1_humidity| +--------------+--------------+ | 34.8| 45.1| +--------------+--------------+ +``` --- Query minimum of 'h'-columns and maximum of 'te'-columns +Query minimum of 'h'-columns and maximum of 'te'-columns +```sql IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 +``` + +Results: + +```sql +--------------+-----------------+ |_col0_humidity|_col1_temperature| +--------------+-----------------+ @@ -393,9 +451,14 @@ IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 3. In Where Clause +Query data where all 'h'-columns must be > 40 (equivalent to) ```sql --- Query data where all 'h'-columns must be > 40 (equivalent to) IoTDB:database1> select * from table1 where columns('^h.*') > 40 +``` + +Results: + +```sql +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -403,9 +466,16 @@ IoTDB:database1> select * from table1 where columns('^h.*') > 40 |2024-11-28T09:00:00.000+08:00| 上海| 3001| 100| C| 90| null| 40.9| true| null| |2024-11-28T11:00:00.000+08:00| 上海| 3001| 100| C| 90| 88.0| 45.1| true|2024-11-28T11:00:12.000+08:00| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ +``` ---Alternative syntax +Alternative syntax +```sql IoTDB:database1> select * from table1 where humidity > 40 +``` + +Results: + +```sql +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md index e5234cfad..6acfe7e9a 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_apache.md @@ -55,10 +55,6 @@ **示例:** ```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -75,7 +71,7 @@ USE **示例:** ```SQL -USE database1 +USE database1; ``` ### 1.3 查看当前数据库 @@ -91,16 +87,10 @@ SHOW CURRENT_DATABASE **示例:** ```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE database1; - -IoTDB> SHOW CURRENT_DATABASE; +USE database1; +SHOW CURRENT_DATABASE; +``` +```shell +---------------+ |CurrentDatabase| +---------------+ @@ -133,15 +123,9 @@ SHOW DATABASES (DETAILS)? **示例:** ```SQL -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -| database1| INF| 1| 1| 604800000| -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details +SHOW DATABASES DETAILS; +``` +```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum|DataRegionGroupNum| +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -188,5 +172,5 @@ DROP DATABASE (IF EXISTS)? **示例:** ```SQL -DROP DATABASE IF EXISTS database1 +DROP DATABASE IF EXISTS database1; ``` diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md index a29b198da..43b014c57 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management_timecho.md @@ -55,10 +55,6 @@ **示例:** ```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -75,7 +71,7 @@ USE **示例:** ```SQL -USE database1 +USE database1; ``` ### 1.3 查看当前数据库 @@ -91,16 +87,10 @@ SHOW CURRENT_DATABASE **示例:** ```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE database1; - -IoTDB> SHOW CURRENT_DATABASE; +USE database1; +SHOW CURRENT_DATABASE; +``` +```shell +---------------+ |CurrentDatabase| +---------------+ @@ -133,15 +123,9 @@ SHOW DATABASES (DETAILS)? **示例:** ```SQL -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -| database1| INF| 1| 1| 604800000| -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details +SHOW DATABASES DETAILS; +``` +```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum|DataRegionGroupNum| +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -188,5 +172,5 @@ DROP DATABASE (IF EXISTS)? **示例:** ```SQL -DROP DATABASE IF EXISTS database1 +DROP DATABASE IF EXISTS database1; ``` diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Delete-Data.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Delete-Data.md index 9772b59a8..e056bf0f9 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/Delete-Data.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Delete-Data.md @@ -67,34 +67,21 @@ ID_CONDITION: #### 1.2.1 删除全表数据 ```SQL -# 全表删除 -DELETE FROM table1 +DELETE FROM table1; ``` #### 1.2.2 删除一段时间范围 ```SQL -# 单时间段删除 -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - -# 多时间段删除 -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` #### 1.2.3 删除指定设备 ```SQL -# 删除指定设备 -# 标识条件只支持 = 运算符 -DELETE FROM table1 WHERE device_id='101' and model_id = 'B' - -# 删除指定设备的时间段 DELETE FROM table1 WHERE time >= 2024-11-27 16:39:00 and time <= 2024-11-29 16:42:00 - AND device_id='101' and model_id = 'B' - -# 删除指定类型的设备 -DELETE FROM table1 WHERE model_id = 'B' + AND device_id='101' and model_id = 'B'; ``` ## 2. 设备删除 @@ -112,5 +99,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? ### 2.2 示例 ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md b/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md index 77b59ba13..706b46477 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_apache.md @@ -45,7 +45,7 @@ IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系 示例1:创建表时设置 TTL ```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600) +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600); ``` 示例2:更改表语句设置TTL: @@ -57,9 +57,9 @@ ALTER TABLE tableB SET PROPERTIES TTL=3600; 示例3:不指定TTL或设为默认值,它将与数据库的TTL相同,默认情况下是'INF'(无穷大): ```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("场站" string id, "温度" int32) -ALTER TABLE tableB set properties TTL=DEFAULT +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT); +CREATE TABLE test3 ("场站" string id, "温度" int32); +ALTER TABLE tableB set properties TTL=DEFAULT; ``` ### 2.2 为数据库设置 TTL @@ -69,25 +69,25 @@ ALTER TABLE tableB set properties TTL=DEFAULT 示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32); ``` 示例5:数据库不设置ttl,将生成一个没有ttl的表: ```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) +CREATE DATABASE db; +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32); ``` 示例6:数据库设置了ttl,但想显式设置没有TTL的表,可以将TTL设置为'INF': ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF'); ``` ## 3. 取消 TTL @@ -95,7 +95,7 @@ CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') 取消 TTL 设置,可以修改表的 TTL 设置为 'INF'。目前,IoTDB 不支持修改数据库的 TTL。 ```SQL -ALTER TABLE tableB set properties TTL='INF' +ALTER TABLE tableB set properties TTL='INF'; ``` ## 4. 查看 TTL 信息 @@ -105,7 +105,7 @@ ALTER TABLE tableB set properties TTL='INF' > 注意,树模型数据库的TTL也将显示。 ```SQL -IoTDB> show databases +IoTDB> show databases; +---------+-------+-----------------------+---------------------+---------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| +---------+-------+-----------------------+---------------------+---------------------+ @@ -113,14 +113,15 @@ IoTDB> show databases | test2| 300| 1| 1| 604800000| +---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details +IoTDB> show databases details; +---------+-------+-----------------------+---------------------+---------------------+-----+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| +---------+-------+-----------------------+---------------------+---------------------+-----+ |test_prop| 300| 1| 3| 100000|TABLE| | test2| 300| 1| 1| 604800000| TREE| +---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables + +IoTDB> show tables; +---------+-------+ |TableName|TTL(ms)| +---------+-------+ @@ -129,7 +130,7 @@ IoTDB> show tables | flower| INF| +---------+-------+ -IoTDB> show tables details +IoTDB> show tables details; +---------+-------+----------+ |TableName|TTL(ms)| Status| +---------+-------+----------+ diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md b/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md index 6c145ef83..3e6cb9778 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/TTL-Delete-Data_timecho.md @@ -45,7 +45,7 @@ IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系 示例1:创建表时设置 TTL ```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600) +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600); ``` 示例2:更改表语句设置TTL: @@ -57,9 +57,9 @@ ALTER TABLE tableB SET PROPERTIES TTL=3600; 示例3:不指定TTL或设为默认值,它将与数据库的TTL相同,默认情况下是'INF'(无穷大): ```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("场站" string id, "温度" int32) -ALTER TABLE tableB set properties TTL=DEFAULT +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT); +CREATE TABLE test3 ("场站" string id, "温度" int32); +ALTER TABLE tableB set properties TTL=DEFAULT; ``` ### 2.2 为数据库设置 TTL @@ -69,25 +69,25 @@ ALTER TABLE tableB set properties TTL=DEFAULT 示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32); ``` 示例5:数据库不设置ttl,将生成一个没有ttl的表: ```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) +CREATE DATABASE db; +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32); ``` 示例6:数据库设置了ttl,但想显式设置没有TTL的表,可以将TTL设置为'INF': ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF'); ``` ## 3. 取消 TTL @@ -95,7 +95,7 @@ CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') 取消 TTL 设置,可以修改表的 TTL 设置为 'INF'。目前,IoTDB 不支持修改数据库的 TTL。 ```SQL -ALTER TABLE tableB set properties TTL='INF' +ALTER TABLE tableB set properties TTL='INF'; ``` ## 4. 查看 TTL 信息 @@ -105,7 +105,7 @@ ALTER TABLE tableB set properties TTL='INF' > 注意,树模型数据库的TTL也将显示。 ```SQL -IoTDB> show databases +IoTDB> show databases; +---------+-------+-----------------------+---------------------+---------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| +---------+-------+-----------------------+---------------------+---------------------+ @@ -113,14 +113,15 @@ IoTDB> show databases | test2| 300| 1| 1| 604800000| +---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details +IoTDB> show databases details; +---------+-------+-----------------------+---------------------+---------------------+-----+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| +---------+-------+-----------------------+---------------------+---------------------+-----+ |test_prop| 300| 1| 3| 100000|TABLE| | test2| 300| 1| 1| 604800000| TREE| +---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables + +IoTDB> show tables; +---------+-------+ |TableName|TTL(ms)| +---------+-------+ @@ -129,7 +130,7 @@ IoTDB> show tables | flower| INF| +---------+-------+ -IoTDB> show tables details +IoTDB> show tables details; +---------+-------+----------+ |TableName|TTL(ms)| Status| +---------+-------+----------+ diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md index 7d8a9a5b3..d2ad37671 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md @@ -106,20 +106,6 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); - -CREATE TABLE if not exists tableB (); - -CREATE TABLE tableC ( - station STRING TAG, - temperature int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); - - -- 自定义时间列:命名为time_test, 位于表的第二列 - CREATE TABLE table1 ( - region STRING TAG, - time_user_defined TIMESTAMP TIME, - temperature FLOAT FIELD - ); ``` 注意:若您使用的终端不支持多行粘贴(例如 Windows CMD),请将 SQL 语句调整为单行格式后再执行。 @@ -144,19 +130,9 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? - `PRE_DELETE`:表示表正在删除中或删除失败,此类表将永久不可用。 **示例:** - -```sql -show tables from database1; -``` -```shell -+---------+---------------+ -|TableName| TTL(ms)| -+---------+---------------+ -| table1| 31536000000| -+---------+---------------+ -``` + ```sql -show tables details from database1; +SHOW TABLES DETAILS FROM database1; ``` ```shell +---------------+-----------+------+-------+ @@ -184,27 +160,8 @@ show tables details from database1; **示例:** -```SQL -desc table1; -``` -```shell -+------------+---------+---------+ -| ColumnName| DataType| Category| -+------------+---------+---------+ -| time|TIMESTAMP| TIME| -| region| STRING| TAG| -| plant_id| STRING| TAG| -| device_id| STRING| TAG| -| model_id| STRING|ATTRIBUTE| -| maintenance| STRING|ATTRIBUTE| -| temperature| FLOAT| FIELD| -| humidity| FLOAT| FIELD| -| status| BOOLEAN| FIELD| -|arrival_time|TIMESTAMP| FIELD| -+------------+---------+---------+ -``` ```sql -desc table1 details; +DESC table1 DETAILS; ``` ```shell +------------+---------+---------+------+------------+ @@ -242,7 +199,7 @@ SHOW CREATE TABLE **示例:** ```SQL -show create table table1; +SHOW CREATE TABLE table1; ``` ```shell +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ @@ -250,7 +207,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -281,11 +237,24 @@ COMMENT ON COLUMN tableName.column IS 'column_comment'; **示例:** +表 table1 增加 tag 列 a ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; +``` +表 table1 增加 field 列 b +```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +修改表 table1 的 TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +表 table1 增加注释 +```SQL COMMENT ON TABLE table1 IS 'table1'; +``` +表 table1 的 a 列去掉注释 +```SQL COMMENT ON COLUMN table1.a IS null; ``` @@ -303,5 +272,4 @@ DROP TABLE (IF EXISTS)? ; ```SQL DROP TABLE table1; -DROP TABLE database1.table1; ``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md index 65a6502b8..c2dca4beb 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md @@ -105,20 +105,6 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); - -CREATE TABLE if not exists tableB (); - -CREATE TABLE tableC ( - station STRING TAG, - temperature int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); - - -- 自定义时间列:命名为time_test, 位于表的第二列 - CREATE TABLE table1 ( - region STRING TAG, - time_user_defined TIMESTAMP TIME, - temperature FLOAT FIELD - ); ``` 注意:若您使用的终端不支持多行粘贴(例如 Windows CMD),请将 SQL 语句调整为单行格式后再执行。 @@ -144,16 +130,6 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? **示例:** -```SQL -show tables from database1; -``` -```shell -+---------+---------------+ -|TableName| TTL(ms)| -+---------+---------------+ -| table1| 31536000000| -+---------+---------------+ -``` ```sql show tables details from database1; ``` @@ -183,25 +159,6 @@ show tables details from database1; **示例:** -```SQL -desc table1; -``` -```shell -+------------+---------+---------+ -| ColumnName| DataType| Category| -+------------+---------+---------+ -| time|TIMESTAMP| TIME| -| region| STRING| TAG| -| plant_id| STRING| TAG| -| device_id| STRING| TAG| -| model_id| STRING|ATTRIBUTE| -| maintenance| STRING|ATTRIBUTE| -| temperature| FLOAT| FIELD| -| humidity| FLOAT| FIELD| -| status| BOOLEAN| FIELD| -|arrival_time|TIMESTAMP| FIELD| -+------------+---------+---------+ -``` ```sql desc table1 details; ``` @@ -250,7 +207,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -299,12 +255,28 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column **示例:** +表 table1 增加 tag 列 a ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; +``` +表 table1 增加 field 列 b +```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +修改表 table1 的 TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +表 table1 增加注释 +```SQL COMMENT ON TABLE table1 IS 'table1'; +``` +表 table1 的 a 列去掉注释 +```SQL COMMENT ON COLUMN table1.a IS null; +``` +修改表 table1 的 b 列的数据类型 +```SQL ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE; ``` @@ -322,7 +294,6 @@ DROP TABLE (IF EXISTS)? ```SQL DROP TABLE table1; -DROP TABLE database1.table1; ``` @@ -351,14 +322,14 @@ device 的唯一标识由全部 tag 列组合而成,只要 region(区域)+ 1. 查询 device 数量 ```sql -IoTDB:database1> count devices from table1 +count devices from table1; +``` +```shell +--------------+ |count(devices)| +--------------+ | 6| +--------------+ -Total line number = 1 -It costs 0.019s ``` 2. 计算单表测点数量 diff --git a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md index e84f1fef3..235c70758 100644 --- a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md +++ b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md @@ -34,18 +34,18 @@ INSERT INTO [(COLUMN_NAME[, COLUMN_NAME]*)]? VALUES (COLUMN_VALUE[, **示例一:指定列写入** ```SQL -INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('北京', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('北京', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('北京', '1001', '100', '2025-11-26 13:38:00', 91.0) +INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('北京', '1001', '100', '2025-11-26 13:38:00', 91.0); ``` **示例二:空值写入** +上述部分列写入等价于如下的带空值写入 ```SQL -# 上述部分列写入等价于如下的带空值写入 -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null); ``` **示例三:多行写入** @@ -54,13 +54,13 @@ INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, tem INSERT INTO table1 VALUES ('2025-11-26 13:37:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('2025-11-26 13:38:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25') +('2025-11-26 13:38:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25'); INSERT INTO table1 (region, plant_id, device_id, model_id, maintenance, time, temperature, humidity, status, arrival_time) VALUES ('北京', '1001', '100', 'A', '180', '2025-11-26 13:37:00', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('北京', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25') +('北京', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25'); ``` **示例四:查询写回** @@ -90,7 +90,7 @@ updateAssignment **示例:** ```SQL -update table1 set b = a where substring(a, 1, 1) like '%' +update table1 set b = a where substring(a, 1, 1) like '%'; ``` ## 3. 数据删除 @@ -123,34 +123,37 @@ ID_CONDITION: **示例一: 删除全表数据** +全表删除 ```SQL --- 全表删除 -DELETE FROM table1 +DELETE FROM table1; ``` **示例二:删除一段时间范围内的数据** +单时间段数据删除 ```SQL --- 单时间段数据删除 -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - --- 多时间段数据删除 -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00; +``` +多时间段数据删除 +```SQL +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` **示例三:删除指定设备的数据** +删除指定设备的数据 ```SQL --- 删除指定设备的数据 -DELETE FROM table1 WHERE device_id='101' and model_id = 'B' - --- 删除指定设备及时间段的数据 +DELETE FROM table1 WHERE device_id='101' and model_id = 'B'; +``` +删除指定设备及时间段的数据 +```SQL DELETE FROM table1 WHERE time >= 2024-11-27 16:39:00 and time <= 2024-11-29 16:42:00 - AND device_id='101' and model_id = 'B' - --- 删除指定类型设备的数据 -DELETE FROM table1 WHERE model_id = 'B' + AND device_id='101' and model_id = 'B'; +``` +删除指定类型设备的数据 +```SQL +DELETE FROM table1 WHERE model_id = 'B'; ``` ## 4. 设备删除 @@ -164,5 +167,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? **示例:删除指定设备及其相关的所有数据** ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` diff --git a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md index 2b33cf13b..df4b0fcc0 100644 --- a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md +++ b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md @@ -34,18 +34,18 @@ INSERT INTO [(COLUMN_NAME[, COLUMN_NAME]*)]? VALUES (COLUMN_VALUE[, **示例一:指定列写入** ```SQL -INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('北京', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('北京', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('北京', '1001', '100', '2025-11-26 13:38:00', 91.0) +INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('北京', '1001', '100', '2025-11-26 13:38:00', 91.0); ``` **示例二:空值写入** +上述部分列写入等价于如下的带空值写入 ```SQL -# 上述部分列写入等价于如下的带空值写入 -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null); ``` **示例三:多行写入** @@ -54,13 +54,13 @@ INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, tem INSERT INTO table1 VALUES ('2025-11-26 13:37:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('2025-11-26 13:38:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25') +('2025-11-26 13:38:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25'); INSERT INTO table1 (region, plant_id, device_id, model_id, maintenance, time, temperature, humidity, status, arrival_time) VALUES ('北京', '1001', '100', 'A', '180', '2025-11-26 13:37:00', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('北京', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25') +('北京', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25'); ``` **示例四:查询写回** @@ -90,7 +90,7 @@ updateAssignment **示例:** ```SQL -update table1 set b = a where substring(a, 1, 1) like '%' +update table1 set b = a where substring(a, 1, 1) like '%'; ``` ## 3. 数据删除 @@ -123,34 +123,37 @@ ID_CONDITION: **示例一: 删除全表数据** +全表删除 ```SQL --- 全表删除 -DELETE FROM table1 +DELETE FROM table1; ``` **示例二:删除一段时间范围内的数据** +单时间段数据删除 ```SQL --- 单时间段数据删除 -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - --- 多时间段数据删除 -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00; +``` +多时间段数据删除 +```SQL +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` **示例三:删除指定设备的数据** +删除指定设备的数据 +```SQL +DELETE FROM table1 WHERE device_id='101' and model_id = 'B'; +``` +删除指定设备及时间段的数据 ```SQL --- 删除指定设备的数据 -DELETE FROM table1 WHERE device_id='101' and model_id = 'B' - --- 删除指定设备及时间段的数据 DELETE FROM table1 WHERE time >= 2024-11-27 16:39:00 and time <= 2024-11-29 16:42:00 - AND device_id='101' and model_id = 'B' - --- 删除指定类型设备的数据 -DELETE FROM table1 WHERE model_id = 'B' + AND device_id='101' and model_id = 'B'; +``` +删除指定类型设备的数据 +```SQL +DELETE FROM table1 WHERE model_id = 'B'; ``` ## 4. 设备删除 @@ -164,5 +167,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? **示例:删除指定设备及其相关的所有数据** ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` diff --git a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md index 6eb4883c6..9ed7c6aa9 100644 --- a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md +++ b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_apache.md @@ -35,11 +35,14 @@ CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? **示例:** +创建一个名为 database1 的数据库, 数据库的 TTL 时间默认永久。 ```SQL CREATE DATABASE database1; CREATE DATABASE IF NOT EXISTS database1; +``` --- 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年; +创建一个名为 database1 的数据库,并将数据库的 TTL 时间设置为1年。 +```SQL CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -67,6 +70,7 @@ SHOW CURRENT_DATABASE; **示例:** +未执行过 `use`语句指定数据库 ```SQL SHOW CURRENT_DATABASE; ``` @@ -77,6 +81,7 @@ SHOW CURRENT_DATABASE; | null| +---------------+ ``` +执行 `use`语句指定数据库 database1 ```sql USE database1; SHOW CURRENT_DATABASE; @@ -101,8 +106,9 @@ SHOW DATABASES (DETAILS)? **示例:** +查看所有数据库 ```SQL -show databases; +SHOW DATABASES; ``` ```shell +------------------+-------+-----------------------+---------------------+---------------------+ @@ -112,8 +118,10 @@ show databases; |information_schema| INF| null| null| null| +------------------+-------+-----------------------+---------------------+---------------------+ ``` + +查看所有数据库详情 ```sql -show databases details; +SHOW DATABASES DETAILS; ``` ```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -134,6 +142,7 @@ ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignmen **示例:** +修改数据库 database1 的 TTL 时间为1年 ```SQL ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; ``` @@ -148,6 +157,7 @@ DROP DATABASE (IF EXISTS)? ; **示例:** +删除数据库 database1 ```SQL DROP DATABASE IF EXISTS database1; ``` @@ -191,6 +201,7 @@ comment **示例:** +创建表 table1 并将表的 TTL 设置为1年 ```SQL CREATE TABLE table1 ( time TIMESTAMP TIME, @@ -204,21 +215,30 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); +``` +创建空表 tableB +```SQL CREATE TABLE if not exists tableB (); +``` +创建表 tableC +```SQL CREATE TABLE tableC ( station STRING TAG, temperature int32 FIELD COMMENT 'temperature' ) with (TTL=DEFAULT); - --- 自定义时间列:命名为time_test, 位于表的第二列 (V2.0.8 起支持) +``` + +创建表 table1 并自定义时间列:命名为time_test, 位于表的第二列 (V2.0.8 起支持) +```SQL CREATE TABLE table1 ( region STRING TAG, time_user_defined TIMESTAMP TIME, temperature FLOAT FIELD ); ``` + 注意:若您使用的终端不支持多行粘贴(例如 Windows CMD),请将 SQL 语句调整为单行格式后再执行。 ### 2.2 查看表 @@ -231,6 +251,7 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? **示例:** +查看数据库 database1 下的所有表 ```SQL show tables from database1; ``` @@ -241,6 +262,8 @@ show tables from database1; | table1| 31536000000| +---------+---------------+ ``` + +查看数据库 database1 下的所有表及其属性信息 ```sql show tables details from database1; ``` @@ -262,6 +285,7 @@ show tables details from database1; **示例:** +查看表 table1 的列信息 ```SQL desc table1; ``` @@ -281,6 +305,7 @@ desc table1; |arrival_time|TIMESTAMP| FIELD| +------------+---------+---------+ ``` +查看表 table1 的列详细信息 ```sql desc table1 details; ``` @@ -311,6 +336,7 @@ SHOW CREATE TABLE **示例:** +查看表 table1 的创建信息 ```SQL show create table table1; ``` @@ -320,7 +346,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -342,11 +367,24 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column **示例:** +表 table1 增加 tag 列 a ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; +``` +表 table1 增加 field 列 b +```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +修改表 table1 的 TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +表 table1 增加注释 +```SQL COMMENT ON TABLE table1 IS 'table1'; +``` +表 table1 的 a 列去掉注释 +```SQL COMMENT ON COLUMN table1.a IS null; ``` diff --git a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md index dccbd6acf..662677066 100644 --- a/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md +++ b/src/zh/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md @@ -35,11 +35,14 @@ CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? **示例:** +创建一个名为 database1 的数据库, 数据库的 TTL 时间默认永久。 ```SQL CREATE DATABASE database1; CREATE DATABASE IF NOT EXISTS database1; +``` --- 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年; +创建一个名为 database1 的数据库,并将数据库的 TTL 时间设置为1年。 +```SQL CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -67,6 +70,7 @@ SHOW CURRENT_DATABASE; **示例:** +未执行过 `use`语句指定数据库 ```SQL SHOW CURRENT_DATABASE; ``` @@ -77,6 +81,7 @@ SHOW CURRENT_DATABASE; | null| +---------------+ ``` +执行 `use`语句指定数据库 database1 ```sql USE database1; SHOW CURRENT_DATABASE; @@ -101,8 +106,9 @@ SHOW DATABASES (DETAILS)? **示例:** +查看所有数据库 ```SQL -show databases; +SHOW DATABASES; ``` ```shell +------------------+-------+-----------------------+---------------------+---------------------+ @@ -112,8 +118,10 @@ show databases; |information_schema| INF| null| null| null| +------------------+-------+-----------------------+---------------------+---------------------+ ``` + +查看所有数据库详情 ```sql -show databases details; +SHOW DATABASES DETAILS; ``` ```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -134,6 +142,7 @@ ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignmen **示例:** +修改数据库 database1 的 TTL 时间为1年 ```SQL ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; ``` @@ -148,6 +157,7 @@ DROP DATABASE (IF EXISTS)? ; **示例:** +删除数据库 database1 ```SQL DROP DATABASE IF EXISTS database1; ``` @@ -191,6 +201,7 @@ comment **示例:** +创建表 table1 并将表的 TTL 设置为1年 ```SQL CREATE TABLE table1 ( time TIMESTAMP TIME, @@ -204,21 +215,30 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); +``` +创建空表 tableB +```SQL CREATE TABLE if not exists tableB (); +``` +创建表 tableC +```SQL CREATE TABLE tableC ( station STRING TAG, temperature int32 FIELD COMMENT 'temperature' ) with (TTL=DEFAULT); - --- 自定义时间列:命名为time_test, 位于表的第二列 (V2.0.8.2 起支持) +``` + +创建表 table1 并自定义时间列:命名为time_test, 位于表的第二列 (V2.0.8 起支持) +```SQL CREATE TABLE table1 ( region STRING TAG, time_user_defined TIMESTAMP TIME, temperature FLOAT FIELD ); ``` + 注意:若您使用的终端不支持多行粘贴(例如 Windows CMD),请将 SQL 语句调整为单行格式后再执行。 ### 2.2 查看表 @@ -231,6 +251,7 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? **示例:** +查看数据库 database1 下的所有表 ```SQL show tables from database1; ``` @@ -241,6 +262,8 @@ show tables from database1; | table1| 31536000000| +---------+---------------+ ``` + +查看数据库 database1 下的所有表及其属性信息 ```sql show tables details from database1; ``` @@ -262,6 +285,7 @@ show tables details from database1; **示例:** +查看表 table1 的列信息 ```SQL desc table1; ``` @@ -281,6 +305,7 @@ desc table1; |arrival_time|TIMESTAMP| FIELD| +------------+---------+---------+ ``` +查看表 table1 的列详细信息 ```sql desc table1 details; ``` @@ -311,6 +336,7 @@ SHOW CREATE TABLE **示例:** +查看表 table1 的创建信息 ```SQL show create table table1; ``` @@ -320,7 +346,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -344,12 +369,28 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col **示例:** +表 table1 增加 tag 列 a ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; +``` +表 table1 增加 field 列 b +```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +修改表 table1 的 TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +表 table1 增加注释 +```SQL COMMENT ON TABLE table1 IS 'table1'; +``` +表 table1 的 a 列去掉注释 +```SQL COMMENT ON COLUMN table1.a IS null; +``` +修改表 table1 的 b 列的数据类型 +```SQL ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE; ``` diff --git a/src/zh/UserGuide/Master/Table/SQL-Manual/Select-Clause_apache.md b/src/zh/UserGuide/Master/Table/SQL-Manual/Select-Clause_apache.md index ae6473613..c1aecba1b 100644 --- a/src/zh/UserGuide/Master/Table/SQL-Manual/Select-Clause_apache.md +++ b/src/zh/UserGuide/Master/Table/SQL-Manual/Select-Clause_apache.md @@ -84,7 +84,7 @@ SELECT * FROM table1; 执行结果如下: -```sql +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| modifytime| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -123,7 +123,7 @@ SELECT count(*) FROM table1; 执行结果如下: -```sql +```shell +-----+ |_col0| +-----+ @@ -143,7 +143,7 @@ SELECT region, count(*) 执行结果如下: -```sql +```shell +------+-----+ |region|_col1| +------+-----+ @@ -166,7 +166,7 @@ IoTDB> SELECT * FROM table1; 执行结果如下: -```sql +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| modifytime| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -203,7 +203,7 @@ IoTDB> SELECT device_id 执行结果如下: -```sql +```shell +------+ |device| +------+ @@ -240,7 +240,7 @@ IoTDB> SELECT table1.* 执行结果如下: -```sql +```shell +-----------------------------+----+----+-----+---+---+----+----+-----+-----------------------------+ | TIMESTAMP| REG| PL|DEVID|MOD|MNT|TEMP| HUM| STAT| MTIME| +-----------------------------+----+----+-----+---+---+----+----+-----+-----------------------------+ @@ -270,9 +270,14 @@ It costs 0.189s ### 3.2 Columns 函数 1. 不结合表达式 + +查询列名以 'm' 开头的列的数据 ```sql --- 查询列名以 'm' 开头的列的数据 -IoTDB:database1> select columns('^m.*') from table1 limit 5 +IoTDB:database1> select columns('^m.*') from table1 limit 5; +``` + +执行结果如下: +```shell +--------+-----------+ |model_id|maintenance| +--------+-----------+ @@ -282,15 +287,23 @@ IoTDB:database1> select columns('^m.*') from table1 limit 5 | C| 90| | C| 90| +--------+-----------+ +``` - --- 查询列名以 'o' 开头的列,未匹配到任何列,抛出异常 -IoTDB:database1> select columns('^o.*') from table1 limit 5 +查询列名以 'o' 开头的列,未匹配到任何列,抛出异常 +```SQL +IoTDB:database1> select columns('^o.*') from table1 limit 5; +``` +执行结果如下: +```shell Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*' +``` - --- 查询列名以 'm' 开头的列的数据,并重命名以 'series_' 开头 -IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 +查询列名以 'm' 开头的列的数据,并重命名以 'series_' 开头 +```SQL +IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5; +``` +执行结果如下: +```shell +---------------+------------------+ |series_model_id|series_maintenance| +---------------+------------------+ @@ -305,9 +318,13 @@ IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 2. 结合表达式 - 单个 COLUMNS 函数 + +查询所有列的最小值 ```sql --- 查询所有列的最小值 -IoTDB:database1> select min(columns(*)) from table1 +IoTDB:database1> select min(columns(*)) from table1; +``` +执行结果如下: +```shell +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ | _col0_time|_col1_region|_col2_plant_id|_col3_device_id|_col4_model_id|_col5_maintenance|_col6_temperature|_col7_humidity|_col8_status| _col9_arrival_time| +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ @@ -319,33 +336,48 @@ IoTDB:database1> select min(columns(*)) from table1 > 使用限制:出现多个 COLUMNS 函数时,多个 COLUMNS 函数的参数要完全相同 +查询 'h' 开头列的最小值和最大值之和 ```sql --- 查询 'h' 开头列的最小值和最大值之和 -IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1 +IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1; +``` +执行结果如下: +```shell +--------------+ |_col0_humidity| +--------------+ | 79.899994| +--------------+ +``` --- 错误查询,两个 COLUMNS 函数不完全相同 -IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1 +错误查询,两个 COLUMNS 函数不完全相同 +```SQL +IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1; +``` +执行结果如下: +```shell Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Multiple different COLUMNS in the same expression are not supported ``` - 多个 COLUMNS 函数,出现在不同表达式 +分别查询 'h' 开头列的最小值和最大值 ```sql --- 分别查询 'h' 开头列的最小值和最大值 -IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1 +IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1; +``` +执行结果如下: +```shell +--------------+--------------+ |_col0_humidity|_col1_humidity| +--------------+--------------+ | 34.8| 45.1| +--------------+--------------+ - --- 分别查询 'h' 开头列的最小值和 'te'开头列的最大值 -IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 +``` +分别查询 'h' 开头列的最小值和 'te'开头列的最大值 +```SQL +IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1; +``` +执行结果如下: +```shell +--------------+-----------------+ |_col0_humidity|_col1_temperature| +--------------+-----------------+ @@ -355,9 +387,12 @@ IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 3. 在 WHERE 子句中使用 +查询数据,所有 'h' 开头列的数据必须要大于 40 ```sql --- 查询数据,所有 'h' 开头列的数据必须要大于 40 -IoTDB:database1> select * from table1 where columns('^h.*') > 40 +IoTDB:database1> select * from table1 where columns('^h.*') > 40; +``` +执行结果如下: +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -365,9 +400,13 @@ IoTDB:database1> select * from table1 where columns('^h.*') > 40 |2024-11-28T09:00:00.000+08:00| 上海| 3001| 100| C| 90| null| 40.9| true| null| |2024-11-28T11:00:00.000+08:00| 上海| 3001| 100| C| 90| 88.0| 45.1| true|2024-11-28T11:00:12.000+08:00| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ - ---等价于 -IoTDB:database1> select * from table1 where humidity > 40 +``` +等价于 +```SQL +IoTDB:database1> select * from table1 where humidity > 40; +``` +执行结果如下: +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ diff --git a/src/zh/UserGuide/Master/Table/SQL-Manual/Select-Clause_timecho.md b/src/zh/UserGuide/Master/Table/SQL-Manual/Select-Clause_timecho.md index 3f2c476b1..d5568b600 100644 --- a/src/zh/UserGuide/Master/Table/SQL-Manual/Select-Clause_timecho.md +++ b/src/zh/UserGuide/Master/Table/SQL-Manual/Select-Clause_timecho.md @@ -84,7 +84,7 @@ SELECT * FROM table1; 执行结果如下: -```sql +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| modifytime| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -123,7 +123,7 @@ SELECT count(*) FROM table1; 执行结果如下: -```sql +```shell +-----+ |_col0| +-----+ @@ -143,7 +143,7 @@ SELECT region, count(*) 执行结果如下: -```sql +```shell +------+-----+ |region|_col1| +------+-----+ @@ -166,7 +166,7 @@ IoTDB> SELECT * FROM table1; 执行结果如下: -```sql +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| modifytime| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -203,7 +203,7 @@ IoTDB> SELECT device_id 执行结果如下: -```sql +```shell +------+ |device| +------+ @@ -240,7 +240,7 @@ IoTDB> SELECT table1.* 执行结果如下: -```sql +```shell +-----------------------------+----+----+-----+---+---+----+----+-----+-----------------------------+ | TIMESTAMP| REG| PL|DEVID|MOD|MNT|TEMP| HUM| STAT| MTIME| +-----------------------------+----+----+-----+---+---+----+----+-----+-----------------------------+ @@ -274,7 +274,11 @@ It costs 0.189s 示例一:直接查询 object 类型数据 ```SQL -IoTDB:database1> select s1 from table1 where device_id = 'tag1' +IoTDB:database1> select s1 from table1 where device_id = 'tag1'; +``` + +执行结果如下: +```shell +------------+ | s1| +------------+ @@ -287,7 +291,11 @@ It costs 0.428s 示例二:通过 read\_object 函数查询 Object 类型数据的真实内容 ```SQL -IoTDB:database1> select read_object(s1) from table1 where device_id = 'tag1' +IoTDB:database1> select read_object(s1) from table1 where device_id = 'tag1'; +``` + +执行结果如下: +```shell +------------+ | _col0| +------------+ @@ -301,9 +309,14 @@ It costs 0.188s ### 3.2 Columns 函数 1. 不结合表达式 + +查询列名以 'm' 开头的列的数据 ```sql --- 查询列名以 'm' 开头的列的数据 -IoTDB:database1> select columns('^m.*') from table1 limit 5 +IoTDB:database1> select columns('^m.*') from table1 limit 5; +``` + +执行结果如下: +```shell +--------+-----------+ |model_id|maintenance| +--------+-----------+ @@ -313,15 +326,23 @@ IoTDB:database1> select columns('^m.*') from table1 limit 5 | C| 90| | C| 90| +--------+-----------+ +``` - --- 查询列名以 'o' 开头的列,未匹配到任何列,抛出异常 -IoTDB:database1> select columns('^o.*') from table1 limit 5 +查询列名以 'o' 开头的列,未匹配到任何列,抛出异常 +```SQL +IoTDB:database1> select columns('^o.*') from table1 limit 5; +``` +执行结果如下: +```shell Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*' +``` - --- 查询列名以 'm' 开头的列的数据,并重命名以 'series_' 开头 -IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 +查询列名以 'm' 开头的列的数据,并重命名以 'series_' 开头 +```SQL +IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5; +``` +执行结果如下: +```shell +---------------+------------------+ |series_model_id|series_maintenance| +---------------+------------------+ @@ -336,9 +357,13 @@ IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 2. 结合表达式 - 单个 COLUMNS 函数 + +查询所有列的最小值 ```sql --- 查询所有列的最小值 -IoTDB:database1> select min(columns(*)) from table1 +IoTDB:database1> select min(columns(*)) from table1; +``` +执行结果如下: +```shell +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ | _col0_time|_col1_region|_col2_plant_id|_col3_device_id|_col4_model_id|_col5_maintenance|_col6_temperature|_col7_humidity|_col8_status| _col9_arrival_time| +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ @@ -350,33 +375,48 @@ IoTDB:database1> select min(columns(*)) from table1 > 使用限制:出现多个 COLUMNS 函数时,多个 COLUMNS 函数的参数要完全相同 +查询 'h' 开头列的最小值和最大值之和 ```sql --- 查询 'h' 开头列的最小值和最大值之和 -IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1 +IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1; +``` +执行结果如下: +```shell +--------------+ |_col0_humidity| +--------------+ | 79.899994| +--------------+ +``` --- 错误查询,两个 COLUMNS 函数不完全相同 -IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1 +错误查询,两个 COLUMNS 函数不完全相同 +```SQL +IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1; +``` +执行结果如下: +```shell Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Multiple different COLUMNS in the same expression are not supported ``` - 多个 COLUMNS 函数,出现在不同表达式 +分别查询 'h' 开头列的最小值和最大值 ```sql --- 分别查询 'h' 开头列的最小值和最大值 -IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1 +IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1; +``` +执行结果如下: +```shell +--------------+--------------+ |_col0_humidity|_col1_humidity| +--------------+--------------+ | 34.8| 45.1| +--------------+--------------+ - --- 分别查询 'h' 开头列的最小值和 'te'开头列的最大值 -IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 +``` +分别查询 'h' 开头列的最小值和 'te'开头列的最大值 +```SQL +IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1; +``` +执行结果如下: +```shell +--------------+-----------------+ |_col0_humidity|_col1_temperature| +--------------+-----------------+ @@ -386,9 +426,12 @@ IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 3. 在 WHERE 子句中使用 +查询数据,所有 'h' 开头列的数据必须要大于 40 ```sql --- 查询数据,所有 'h' 开头列的数据必须要大于 40 -IoTDB:database1> select * from table1 where columns('^h.*') > 40 +IoTDB:database1> select * from table1 where columns('^h.*') > 40; +``` +执行结果如下: +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -396,9 +439,13 @@ IoTDB:database1> select * from table1 where columns('^h.*') > 40 |2024-11-28T09:00:00.000+08:00| 上海| 3001| 100| C| 90| null| 40.9| true| null| |2024-11-28T11:00:00.000+08:00| 上海| 3001| 100| C| 90| 88.0| 45.1| true|2024-11-28T11:00:12.000+08:00| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ - ---等价于 -IoTDB:database1> select * from table1 where humidity > 40 +``` +等价于 +```SQL +IoTDB:database1> select * from table1 where humidity > 40; +``` +执行结果如下: +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md index e5234cfad..6acfe7e9a 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_apache.md @@ -55,10 +55,6 @@ **示例:** ```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -75,7 +71,7 @@ USE **示例:** ```SQL -USE database1 +USE database1; ``` ### 1.3 查看当前数据库 @@ -91,16 +87,10 @@ SHOW CURRENT_DATABASE **示例:** ```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE database1; - -IoTDB> SHOW CURRENT_DATABASE; +USE database1; +SHOW CURRENT_DATABASE; +``` +```shell +---------------+ |CurrentDatabase| +---------------+ @@ -133,15 +123,9 @@ SHOW DATABASES (DETAILS)? **示例:** ```SQL -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -| database1| INF| 1| 1| 604800000| -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details +SHOW DATABASES DETAILS; +``` +```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum|DataRegionGroupNum| +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -188,5 +172,5 @@ DROP DATABASE (IF EXISTS)? **示例:** ```SQL -DROP DATABASE IF EXISTS database1 +DROP DATABASE IF EXISTS database1; ``` diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md index a29b198da..43b014c57 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management_timecho.md @@ -55,10 +55,6 @@ **示例:** ```SQL -CREATE DATABASE database1; -CREATE DATABASE IF NOT EXISTS database1; - -// 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年。 CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -75,7 +71,7 @@ USE **示例:** ```SQL -USE database1 +USE database1; ``` ### 1.3 查看当前数据库 @@ -91,16 +87,10 @@ SHOW CURRENT_DATABASE **示例:** ```SQL -IoTDB> SHOW CURRENT_DATABASE; -+---------------+ -|CurrentDatabase| -+---------------+ -| null| -+---------------+ - -IoTDB> USE database1; - -IoTDB> SHOW CURRENT_DATABASE; +USE database1; +SHOW CURRENT_DATABASE; +``` +```shell +---------------+ |CurrentDatabase| +---------------+ @@ -133,15 +123,9 @@ SHOW DATABASES (DETAILS)? **示例:** ```SQL -IoTDB> show databases -+------------------+-------+-----------------------+---------------------+---------------------+ -| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| -+------------------+-------+-----------------------+---------------------+---------------------+ -| database1| INF| 1| 1| 604800000| -|information_schema| INF| null| null| null| -+------------------+-------+-----------------------+---------------------+---------------------+ - -IoTDB> show databases details +SHOW DATABASES DETAILS; +``` +```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum|DataRegionGroupNum| +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -188,5 +172,5 @@ DROP DATABASE (IF EXISTS)? **示例:** ```SQL -DROP DATABASE IF EXISTS database1 +DROP DATABASE IF EXISTS database1; ``` diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Delete-Data.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Delete-Data.md index 9772b59a8..e056bf0f9 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Delete-Data.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Delete-Data.md @@ -67,34 +67,21 @@ ID_CONDITION: #### 1.2.1 删除全表数据 ```SQL -# 全表删除 -DELETE FROM table1 +DELETE FROM table1; ``` #### 1.2.2 删除一段时间范围 ```SQL -# 单时间段删除 -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - -# 多时间段删除 -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` #### 1.2.3 删除指定设备 ```SQL -# 删除指定设备 -# 标识条件只支持 = 运算符 -DELETE FROM table1 WHERE device_id='101' and model_id = 'B' - -# 删除指定设备的时间段 DELETE FROM table1 WHERE time >= 2024-11-27 16:39:00 and time <= 2024-11-29 16:42:00 - AND device_id='101' and model_id = 'B' - -# 删除指定类型的设备 -DELETE FROM table1 WHERE model_id = 'B' + AND device_id='101' and model_id = 'B'; ``` ## 2. 设备删除 @@ -112,5 +99,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? ### 2.2 示例 ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md index 77b59ba13..706b46477 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_apache.md @@ -45,7 +45,7 @@ IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系 示例1:创建表时设置 TTL ```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600) +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600); ``` 示例2:更改表语句设置TTL: @@ -57,9 +57,9 @@ ALTER TABLE tableB SET PROPERTIES TTL=3600; 示例3:不指定TTL或设为默认值,它将与数据库的TTL相同,默认情况下是'INF'(无穷大): ```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("场站" string id, "温度" int32) -ALTER TABLE tableB set properties TTL=DEFAULT +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT); +CREATE TABLE test3 ("场站" string id, "温度" int32); +ALTER TABLE tableB set properties TTL=DEFAULT; ``` ### 2.2 为数据库设置 TTL @@ -69,25 +69,25 @@ ALTER TABLE tableB set properties TTL=DEFAULT 示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32); ``` 示例5:数据库不设置ttl,将生成一个没有ttl的表: ```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) +CREATE DATABASE db; +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32); ``` 示例6:数据库设置了ttl,但想显式设置没有TTL的表,可以将TTL设置为'INF': ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF'); ``` ## 3. 取消 TTL @@ -95,7 +95,7 @@ CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') 取消 TTL 设置,可以修改表的 TTL 设置为 'INF'。目前,IoTDB 不支持修改数据库的 TTL。 ```SQL -ALTER TABLE tableB set properties TTL='INF' +ALTER TABLE tableB set properties TTL='INF'; ``` ## 4. 查看 TTL 信息 @@ -105,7 +105,7 @@ ALTER TABLE tableB set properties TTL='INF' > 注意,树模型数据库的TTL也将显示。 ```SQL -IoTDB> show databases +IoTDB> show databases; +---------+-------+-----------------------+---------------------+---------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| +---------+-------+-----------------------+---------------------+---------------------+ @@ -113,14 +113,15 @@ IoTDB> show databases | test2| 300| 1| 1| 604800000| +---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details +IoTDB> show databases details; +---------+-------+-----------------------+---------------------+---------------------+-----+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| +---------+-------+-----------------------+---------------------+---------------------+-----+ |test_prop| 300| 1| 3| 100000|TABLE| | test2| 300| 1| 1| 604800000| TREE| +---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables + +IoTDB> show tables; +---------+-------+ |TableName|TTL(ms)| +---------+-------+ @@ -129,7 +130,7 @@ IoTDB> show tables | flower| INF| +---------+-------+ -IoTDB> show tables details +IoTDB> show tables details; +---------+-------+----------+ |TableName|TTL(ms)| Status| +---------+-------+----------+ diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md index 6c145ef83..3e6cb9778 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/TTL-Delete-Data_timecho.md @@ -45,7 +45,7 @@ IoTDB支持对表(table)级别设置数据保留时间(TTL),允许系 示例1:创建表时设置 TTL ```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600) +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=3600); ``` 示例2:更改表语句设置TTL: @@ -57,9 +57,9 @@ ALTER TABLE tableB SET PROPERTIES TTL=3600; 示例3:不指定TTL或设为默认值,它将与数据库的TTL相同,默认情况下是'INF'(无穷大): ```SQL -CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT) -CREATE TABLE test3 ("场站" string id, "温度" int32) -ALTER TABLE tableB set properties TTL=DEFAULT +CREATE TABLE test3 ("场站" string id, "温度" int32) with (TTL=DEFAULT); +CREATE TABLE test3 ("场站" string id, "温度" int32); +ALTER TABLE tableB set properties TTL=DEFAULT; ``` ### 2.2 为数据库设置 TTL @@ -69,25 +69,25 @@ ALTER TABLE tableB set properties TTL=DEFAULT 示例4:数据库设置为 ttl =3600000,将生成一个ttl=3600000的表: ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32); ``` 示例5:数据库不设置ttl,将生成一个没有ttl的表: ```SQL -CREATE DATABASE db -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) +CREATE DATABASE db; +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32); ``` 示例6:数据库设置了ttl,但想显式设置没有TTL的表,可以将TTL设置为'INF': ```SQL -CREATE DATABASE db WITH (ttl=3600000) -use db -CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') +CREATE DATABASE db WITH (ttl=3600000); +use db; +CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF'); ``` ## 3. 取消 TTL @@ -95,7 +95,7 @@ CREATE TABLE test3 ("场站" string id, "温度" int32) with (ttl='INF') 取消 TTL 设置,可以修改表的 TTL 设置为 'INF'。目前,IoTDB 不支持修改数据库的 TTL。 ```SQL -ALTER TABLE tableB set properties TTL='INF' +ALTER TABLE tableB set properties TTL='INF'; ``` ## 4. 查看 TTL 信息 @@ -105,7 +105,7 @@ ALTER TABLE tableB set properties TTL='INF' > 注意,树模型数据库的TTL也将显示。 ```SQL -IoTDB> show databases +IoTDB> show databases; +---------+-------+-----------------------+---------------------+---------------------+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| +---------+-------+-----------------------+---------------------+---------------------+ @@ -113,14 +113,15 @@ IoTDB> show databases | test2| 300| 1| 1| 604800000| +---------+-------+-----------------------+---------------------+---------------------+ -IoTDB> show databases details +IoTDB> show databases details; +---------+-------+-----------------------+---------------------+---------------------+-----+ | Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|Model| +---------+-------+-----------------------+---------------------+---------------------+-----+ |test_prop| 300| 1| 3| 100000|TABLE| | test2| 300| 1| 1| 604800000| TREE| +---------+-------+-----------------------+---------------------+---------------------+-----+ -IoTDB> show tables + +IoTDB> show tables; +---------+-------+ |TableName|TTL(ms)| +---------+-------+ @@ -129,7 +130,7 @@ IoTDB> show tables | flower| INF| +---------+-------+ -IoTDB> show tables details +IoTDB> show tables details; +---------+-------+----------+ |TableName|TTL(ms)| Status| +---------+-------+----------+ diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md index 7d8a9a5b3..d2ad37671 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_apache.md @@ -106,20 +106,6 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); - -CREATE TABLE if not exists tableB (); - -CREATE TABLE tableC ( - station STRING TAG, - temperature int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); - - -- 自定义时间列:命名为time_test, 位于表的第二列 - CREATE TABLE table1 ( - region STRING TAG, - time_user_defined TIMESTAMP TIME, - temperature FLOAT FIELD - ); ``` 注意:若您使用的终端不支持多行粘贴(例如 Windows CMD),请将 SQL 语句调整为单行格式后再执行。 @@ -144,19 +130,9 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? - `PRE_DELETE`:表示表正在删除中或删除失败,此类表将永久不可用。 **示例:** - -```sql -show tables from database1; -``` -```shell -+---------+---------------+ -|TableName| TTL(ms)| -+---------+---------------+ -| table1| 31536000000| -+---------+---------------+ -``` + ```sql -show tables details from database1; +SHOW TABLES DETAILS FROM database1; ``` ```shell +---------------+-----------+------+-------+ @@ -184,27 +160,8 @@ show tables details from database1; **示例:** -```SQL -desc table1; -``` -```shell -+------------+---------+---------+ -| ColumnName| DataType| Category| -+------------+---------+---------+ -| time|TIMESTAMP| TIME| -| region| STRING| TAG| -| plant_id| STRING| TAG| -| device_id| STRING| TAG| -| model_id| STRING|ATTRIBUTE| -| maintenance| STRING|ATTRIBUTE| -| temperature| FLOAT| FIELD| -| humidity| FLOAT| FIELD| -| status| BOOLEAN| FIELD| -|arrival_time|TIMESTAMP| FIELD| -+------------+---------+---------+ -``` ```sql -desc table1 details; +DESC table1 DETAILS; ``` ```shell +------------+---------+---------+------+------------+ @@ -242,7 +199,7 @@ SHOW CREATE TABLE **示例:** ```SQL -show create table table1; +SHOW CREATE TABLE table1; ``` ```shell +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ @@ -250,7 +207,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -281,11 +237,24 @@ COMMENT ON COLUMN tableName.column IS 'column_comment'; **示例:** +表 table1 增加 tag 列 a ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; +``` +表 table1 增加 field 列 b +```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +修改表 table1 的 TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +表 table1 增加注释 +```SQL COMMENT ON TABLE table1 IS 'table1'; +``` +表 table1 的 a 列去掉注释 +```SQL COMMENT ON COLUMN table1.a IS null; ``` @@ -303,5 +272,4 @@ DROP TABLE (IF EXISTS)? ; ```SQL DROP TABLE table1; -DROP TABLE database1.table1; ``` \ No newline at end of file diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md index 65a6502b8..c2dca4beb 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md @@ -105,20 +105,6 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); - -CREATE TABLE if not exists tableB (); - -CREATE TABLE tableC ( - station STRING TAG, - temperature int32 FIELD COMMENT 'temperature' - ) with (TTL=DEFAULT); - - -- 自定义时间列:命名为time_test, 位于表的第二列 - CREATE TABLE table1 ( - region STRING TAG, - time_user_defined TIMESTAMP TIME, - temperature FLOAT FIELD - ); ``` 注意:若您使用的终端不支持多行粘贴(例如 Windows CMD),请将 SQL 语句调整为单行格式后再执行。 @@ -144,16 +130,6 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? **示例:** -```SQL -show tables from database1; -``` -```shell -+---------+---------------+ -|TableName| TTL(ms)| -+---------+---------------+ -| table1| 31536000000| -+---------+---------------+ -``` ```sql show tables details from database1; ``` @@ -183,25 +159,6 @@ show tables details from database1; **示例:** -```SQL -desc table1; -``` -```shell -+------------+---------+---------+ -| ColumnName| DataType| Category| -+------------+---------+---------+ -| time|TIMESTAMP| TIME| -| region| STRING| TAG| -| plant_id| STRING| TAG| -| device_id| STRING| TAG| -| model_id| STRING|ATTRIBUTE| -| maintenance| STRING|ATTRIBUTE| -| temperature| FLOAT| FIELD| -| humidity| FLOAT| FIELD| -| status| BOOLEAN| FIELD| -|arrival_time|TIMESTAMP| FIELD| -+------------+---------+---------+ -``` ```sql desc table1 details; ``` @@ -250,7 +207,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -299,12 +255,28 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column **示例:** +表 table1 增加 tag 列 a ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; +``` +表 table1 增加 field 列 b +```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +修改表 table1 的 TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +表 table1 增加注释 +```SQL COMMENT ON TABLE table1 IS 'table1'; +``` +表 table1 的 a 列去掉注释 +```SQL COMMENT ON COLUMN table1.a IS null; +``` +修改表 table1 的 b 列的数据类型 +```SQL ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE; ``` @@ -322,7 +294,6 @@ DROP TABLE (IF EXISTS)? ```SQL DROP TABLE table1; -DROP TABLE database1.table1; ``` @@ -351,14 +322,14 @@ device 的唯一标识由全部 tag 列组合而成,只要 region(区域)+ 1. 查询 device 数量 ```sql -IoTDB:database1> count devices from table1 +count devices from table1; +``` +```shell +--------------+ |count(devices)| +--------------+ | 6| +--------------+ -Total line number = 1 -It costs 0.019s ``` 2. 计算单表测点数量 diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md index e84f1fef3..235c70758 100644 --- a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_apache.md @@ -34,18 +34,18 @@ INSERT INTO [(COLUMN_NAME[, COLUMN_NAME]*)]? VALUES (COLUMN_VALUE[, **示例一:指定列写入** ```SQL -INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('北京', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('北京', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('北京', '1001', '100', '2025-11-26 13:38:00', 91.0) +INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('北京', '1001', '100', '2025-11-26 13:38:00', 91.0); ``` **示例二:空值写入** +上述部分列写入等价于如下的带空值写入 ```SQL -# 上述部分列写入等价于如下的带空值写入 -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null); ``` **示例三:多行写入** @@ -54,13 +54,13 @@ INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, tem INSERT INTO table1 VALUES ('2025-11-26 13:37:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('2025-11-26 13:38:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25') +('2025-11-26 13:38:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25'); INSERT INTO table1 (region, plant_id, device_id, model_id, maintenance, time, temperature, humidity, status, arrival_time) VALUES ('北京', '1001', '100', 'A', '180', '2025-11-26 13:37:00', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('北京', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25') +('北京', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25'); ``` **示例四:查询写回** @@ -90,7 +90,7 @@ updateAssignment **示例:** ```SQL -update table1 set b = a where substring(a, 1, 1) like '%' +update table1 set b = a where substring(a, 1, 1) like '%'; ``` ## 3. 数据删除 @@ -123,34 +123,37 @@ ID_CONDITION: **示例一: 删除全表数据** +全表删除 ```SQL --- 全表删除 -DELETE FROM table1 +DELETE FROM table1; ``` **示例二:删除一段时间范围内的数据** +单时间段数据删除 ```SQL --- 单时间段数据删除 -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - --- 多时间段数据删除 -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00; +``` +多时间段数据删除 +```SQL +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` **示例三:删除指定设备的数据** +删除指定设备的数据 ```SQL --- 删除指定设备的数据 -DELETE FROM table1 WHERE device_id='101' and model_id = 'B' - --- 删除指定设备及时间段的数据 +DELETE FROM table1 WHERE device_id='101' and model_id = 'B'; +``` +删除指定设备及时间段的数据 +```SQL DELETE FROM table1 WHERE time >= 2024-11-27 16:39:00 and time <= 2024-11-29 16:42:00 - AND device_id='101' and model_id = 'B' - --- 删除指定类型设备的数据 -DELETE FROM table1 WHERE model_id = 'B' + AND device_id='101' and model_id = 'B'; +``` +删除指定类型设备的数据 +```SQL +DELETE FROM table1 WHERE model_id = 'B'; ``` ## 4. 设备删除 @@ -164,5 +167,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? **示例:删除指定设备及其相关的所有数据** ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md index 2b33cf13b..df4b0fcc0 100644 --- a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Data-Addition-Deletion_timecho.md @@ -34,18 +34,18 @@ INSERT INTO [(COLUMN_NAME[, COLUMN_NAME]*)]? VALUES (COLUMN_VALUE[, **示例一:指定列写入** ```SQL -INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('北京', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('北京', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('北京', '1001', '100', '2025-11-26 13:38:00', 91.0) +INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('北京', '1001', '100', '2025-11-26 13:38:00', 91.0); ``` **示例二:空值写入** +上述部分列写入等价于如下的带空值写入 ```SQL -# 上述部分列写入等价于如下的带空值写入 -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1); -INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null) +INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('北京', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null); ``` **示例三:多行写入** @@ -54,13 +54,13 @@ INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, tem INSERT INTO table1 VALUES ('2025-11-26 13:37:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('2025-11-26 13:38:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25') +('2025-11-26 13:38:00', '北京', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25'); INSERT INTO table1 (region, plant_id, device_id, model_id, maintenance, time, temperature, humidity, status, arrival_time) VALUES ('北京', '1001', '100', 'A', '180', '2025-11-26 13:37:00', 90.0, 35.1, true, '2025-11-26 13:37:34'), -('北京', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25') +('北京', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25'); ``` **示例四:查询写回** @@ -90,7 +90,7 @@ updateAssignment **示例:** ```SQL -update table1 set b = a where substring(a, 1, 1) like '%' +update table1 set b = a where substring(a, 1, 1) like '%'; ``` ## 3. 数据删除 @@ -123,34 +123,37 @@ ID_CONDITION: **示例一: 删除全表数据** +全表删除 ```SQL --- 全表删除 -DELETE FROM table1 +DELETE FROM table1; ``` **示例二:删除一段时间范围内的数据** +单时间段数据删除 ```SQL --- 单时间段数据删除 -DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00 - --- 多时间段数据删除 -DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00 +DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00; +``` +多时间段数据删除 +```SQL +DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00; ``` **示例三:删除指定设备的数据** +删除指定设备的数据 +```SQL +DELETE FROM table1 WHERE device_id='101' and model_id = 'B'; +``` +删除指定设备及时间段的数据 ```SQL --- 删除指定设备的数据 -DELETE FROM table1 WHERE device_id='101' and model_id = 'B' - --- 删除指定设备及时间段的数据 DELETE FROM table1 WHERE time >= 2024-11-27 16:39:00 and time <= 2024-11-29 16:42:00 - AND device_id='101' and model_id = 'B' - --- 删除指定类型设备的数据 -DELETE FROM table1 WHERE model_id = 'B' + AND device_id='101' and model_id = 'B'; +``` +删除指定类型设备的数据 +```SQL +DELETE FROM table1 WHERE model_id = 'B'; ``` ## 4. 设备删除 @@ -164,5 +167,5 @@ DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)? **示例:删除指定设备及其相关的所有数据** ```SQL -DELETE DEVICES FROM table1 WHERE device_id = '101' +DELETE DEVICES FROM table1 WHERE device_id = '101'; ``` diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md index 6eb4883c6..9ed7c6aa9 100644 --- a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_apache.md @@ -35,11 +35,14 @@ CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? **示例:** +创建一个名为 database1 的数据库, 数据库的 TTL 时间默认永久。 ```SQL CREATE DATABASE database1; CREATE DATABASE IF NOT EXISTS database1; +``` --- 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年; +创建一个名为 database1 的数据库,并将数据库的 TTL 时间设置为1年。 +```SQL CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -67,6 +70,7 @@ SHOW CURRENT_DATABASE; **示例:** +未执行过 `use`语句指定数据库 ```SQL SHOW CURRENT_DATABASE; ``` @@ -77,6 +81,7 @@ SHOW CURRENT_DATABASE; | null| +---------------+ ``` +执行 `use`语句指定数据库 database1 ```sql USE database1; SHOW CURRENT_DATABASE; @@ -101,8 +106,9 @@ SHOW DATABASES (DETAILS)? **示例:** +查看所有数据库 ```SQL -show databases; +SHOW DATABASES; ``` ```shell +------------------+-------+-----------------------+---------------------+---------------------+ @@ -112,8 +118,10 @@ show databases; |information_schema| INF| null| null| null| +------------------+-------+-----------------------+---------------------+---------------------+ ``` + +查看所有数据库详情 ```sql -show databases details; +SHOW DATABASES DETAILS; ``` ```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -134,6 +142,7 @@ ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignmen **示例:** +修改数据库 database1 的 TTL 时间为1年 ```SQL ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; ``` @@ -148,6 +157,7 @@ DROP DATABASE (IF EXISTS)? ; **示例:** +删除数据库 database1 ```SQL DROP DATABASE IF EXISTS database1; ``` @@ -191,6 +201,7 @@ comment **示例:** +创建表 table1 并将表的 TTL 设置为1年 ```SQL CREATE TABLE table1 ( time TIMESTAMP TIME, @@ -204,21 +215,30 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); +``` +创建空表 tableB +```SQL CREATE TABLE if not exists tableB (); +``` +创建表 tableC +```SQL CREATE TABLE tableC ( station STRING TAG, temperature int32 FIELD COMMENT 'temperature' ) with (TTL=DEFAULT); - --- 自定义时间列:命名为time_test, 位于表的第二列 (V2.0.8 起支持) +``` + +创建表 table1 并自定义时间列:命名为time_test, 位于表的第二列 (V2.0.8 起支持) +```SQL CREATE TABLE table1 ( region STRING TAG, time_user_defined TIMESTAMP TIME, temperature FLOAT FIELD ); ``` + 注意:若您使用的终端不支持多行粘贴(例如 Windows CMD),请将 SQL 语句调整为单行格式后再执行。 ### 2.2 查看表 @@ -231,6 +251,7 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? **示例:** +查看数据库 database1 下的所有表 ```SQL show tables from database1; ``` @@ -241,6 +262,8 @@ show tables from database1; | table1| 31536000000| +---------+---------------+ ``` + +查看数据库 database1 下的所有表及其属性信息 ```sql show tables details from database1; ``` @@ -262,6 +285,7 @@ show tables details from database1; **示例:** +查看表 table1 的列信息 ```SQL desc table1; ``` @@ -281,6 +305,7 @@ desc table1; |arrival_time|TIMESTAMP| FIELD| +------------+---------+---------+ ``` +查看表 table1 的列详细信息 ```sql desc table1 details; ``` @@ -311,6 +336,7 @@ SHOW CREATE TABLE **示例:** +查看表 table1 的创建信息 ```SQL show create table table1; ``` @@ -320,7 +346,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -342,11 +367,24 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column **示例:** +表 table1 增加 tag 列 a ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; +``` +表 table1 增加 field 列 b +```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +修改表 table1 的 TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +表 table1 增加注释 +```SQL COMMENT ON TABLE table1 IS 'table1'; +``` +表 table1 的 a 列去掉注释 +```SQL COMMENT ON COLUMN table1.a IS null; ``` diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md index dccbd6acf..662677066 100644 --- a/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md @@ -35,11 +35,14 @@ CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? **示例:** +创建一个名为 database1 的数据库, 数据库的 TTL 时间默认永久。 ```SQL CREATE DATABASE database1; CREATE DATABASE IF NOT EXISTS database1; +``` --- 创建一个名为 database1 的数据库,并将数据库的TTL时间设置为1年; +创建一个名为 database1 的数据库,并将数据库的 TTL 时间设置为1年。 +```SQL CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); ``` @@ -67,6 +70,7 @@ SHOW CURRENT_DATABASE; **示例:** +未执行过 `use`语句指定数据库 ```SQL SHOW CURRENT_DATABASE; ``` @@ -77,6 +81,7 @@ SHOW CURRENT_DATABASE; | null| +---------------+ ``` +执行 `use`语句指定数据库 database1 ```sql USE database1; SHOW CURRENT_DATABASE; @@ -101,8 +106,9 @@ SHOW DATABASES (DETAILS)? **示例:** +查看所有数据库 ```SQL -show databases; +SHOW DATABASES; ``` ```shell +------------------+-------+-----------------------+---------------------+---------------------+ @@ -112,8 +118,10 @@ show databases; |information_schema| INF| null| null| null| +------------------+-------+-----------------------+---------------------+---------------------+ ``` + +查看所有数据库详情 ```sql -show databases details; +SHOW DATABASES DETAILS; ``` ```shell +------------------+-------+-----------------------+---------------------+---------------------+--------------------+------------------+ @@ -134,6 +142,7 @@ ALTER DATABASE (IF EXISTS)? database=identifier SET PROPERTIES propertyAssignmen **示例:** +修改数据库 database1 的 TTL 时间为1年 ```SQL ALTER DATABASE database1 SET PROPERTIES TTL=31536000000; ``` @@ -148,6 +157,7 @@ DROP DATABASE (IF EXISTS)? ; **示例:** +删除数据库 database1 ```SQL DROP DATABASE IF EXISTS database1; ``` @@ -191,6 +201,7 @@ comment **示例:** +创建表 table1 并将表的 TTL 设置为1年 ```SQL CREATE TABLE table1 ( time TIMESTAMP TIME, @@ -204,21 +215,30 @@ CREATE TABLE table1 ( status Boolean FIELD COMMENT 'status', arrival_time TIMESTAMP FIELD COMMENT 'arrival_time' ) COMMENT 'table1' WITH (TTL=31536000000); +``` +创建空表 tableB +```SQL CREATE TABLE if not exists tableB (); +``` +创建表 tableC +```SQL CREATE TABLE tableC ( station STRING TAG, temperature int32 FIELD COMMENT 'temperature' ) with (TTL=DEFAULT); - --- 自定义时间列:命名为time_test, 位于表的第二列 (V2.0.8.2 起支持) +``` + +创建表 table1 并自定义时间列:命名为time_test, 位于表的第二列 (V2.0.8 起支持) +```SQL CREATE TABLE table1 ( region STRING TAG, time_user_defined TIMESTAMP TIME, temperature FLOAT FIELD ); ``` + 注意:若您使用的终端不支持多行粘贴(例如 Windows CMD),请将 SQL 语句调整为单行格式后再执行。 ### 2.2 查看表 @@ -231,6 +251,7 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? **示例:** +查看数据库 database1 下的所有表 ```SQL show tables from database1; ``` @@ -241,6 +262,8 @@ show tables from database1; | table1| 31536000000| +---------+---------------+ ``` + +查看数据库 database1 下的所有表及其属性信息 ```sql show tables details from database1; ``` @@ -262,6 +285,7 @@ show tables details from database1; **示例:** +查看表 table1 的列信息 ```SQL desc table1; ``` @@ -281,6 +305,7 @@ desc table1; |arrival_time|TIMESTAMP| FIELD| +------------+---------+---------+ ``` +查看表 table1 的列详细信息 ```sql desc table1 details; ``` @@ -311,6 +336,7 @@ SHOW CREATE TABLE **示例:** +查看表 table1 的创建信息 ```SQL show create table table1; ``` @@ -320,7 +346,6 @@ show create table table1; +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |table1|CREATE TABLE "table1" ("region" STRING TAG,"plant_id" STRING TAG,"device_id" STRING TAG,"model_id" STRING ATTRIBUTE,"maintenance" STRING ATTRIBUTE,"temperature" FLOAT FIELD,"humidity" FLOAT FIELD,"status" BOOLEAN FIELD,"arrival_time" TIMESTAMP FIELD) WITH (ttl=31536000000)| +------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 1 ``` @@ -344,12 +369,28 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col **示例:** +表 table1 增加 tag 列 a ```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'; +``` +表 table1 增加 field 列 b +```SQL ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'; -ALTER TABLE table1 set properties TTL=3600; +``` +修改表 table1 的 TTL +```SQL +ALTER TABLE table1 set properties TTL=3600; +``` +表 table1 增加注释 +```SQL COMMENT ON TABLE table1 IS 'table1'; +``` +表 table1 的 a 列去掉注释 +```SQL COMMENT ON COLUMN table1.a IS null; +``` +修改表 table1 的 b 列的数据类型 +```SQL ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE; ``` diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/Select-Clause_apache.md b/src/zh/UserGuide/latest-Table/SQL-Manual/Select-Clause_apache.md index ae6473613..c1aecba1b 100644 --- a/src/zh/UserGuide/latest-Table/SQL-Manual/Select-Clause_apache.md +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/Select-Clause_apache.md @@ -84,7 +84,7 @@ SELECT * FROM table1; 执行结果如下: -```sql +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| modifytime| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -123,7 +123,7 @@ SELECT count(*) FROM table1; 执行结果如下: -```sql +```shell +-----+ |_col0| +-----+ @@ -143,7 +143,7 @@ SELECT region, count(*) 执行结果如下: -```sql +```shell +------+-----+ |region|_col1| +------+-----+ @@ -166,7 +166,7 @@ IoTDB> SELECT * FROM table1; 执行结果如下: -```sql +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| modifytime| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -203,7 +203,7 @@ IoTDB> SELECT device_id 执行结果如下: -```sql +```shell +------+ |device| +------+ @@ -240,7 +240,7 @@ IoTDB> SELECT table1.* 执行结果如下: -```sql +```shell +-----------------------------+----+----+-----+---+---+----+----+-----+-----------------------------+ | TIMESTAMP| REG| PL|DEVID|MOD|MNT|TEMP| HUM| STAT| MTIME| +-----------------------------+----+----+-----+---+---+----+----+-----+-----------------------------+ @@ -270,9 +270,14 @@ It costs 0.189s ### 3.2 Columns 函数 1. 不结合表达式 + +查询列名以 'm' 开头的列的数据 ```sql --- 查询列名以 'm' 开头的列的数据 -IoTDB:database1> select columns('^m.*') from table1 limit 5 +IoTDB:database1> select columns('^m.*') from table1 limit 5; +``` + +执行结果如下: +```shell +--------+-----------+ |model_id|maintenance| +--------+-----------+ @@ -282,15 +287,23 @@ IoTDB:database1> select columns('^m.*') from table1 limit 5 | C| 90| | C| 90| +--------+-----------+ +``` - --- 查询列名以 'o' 开头的列,未匹配到任何列,抛出异常 -IoTDB:database1> select columns('^o.*') from table1 limit 5 +查询列名以 'o' 开头的列,未匹配到任何列,抛出异常 +```SQL +IoTDB:database1> select columns('^o.*') from table1 limit 5; +``` +执行结果如下: +```shell Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*' +``` - --- 查询列名以 'm' 开头的列的数据,并重命名以 'series_' 开头 -IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 +查询列名以 'm' 开头的列的数据,并重命名以 'series_' 开头 +```SQL +IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5; +``` +执行结果如下: +```shell +---------------+------------------+ |series_model_id|series_maintenance| +---------------+------------------+ @@ -305,9 +318,13 @@ IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 2. 结合表达式 - 单个 COLUMNS 函数 + +查询所有列的最小值 ```sql --- 查询所有列的最小值 -IoTDB:database1> select min(columns(*)) from table1 +IoTDB:database1> select min(columns(*)) from table1; +``` +执行结果如下: +```shell +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ | _col0_time|_col1_region|_col2_plant_id|_col3_device_id|_col4_model_id|_col5_maintenance|_col6_temperature|_col7_humidity|_col8_status| _col9_arrival_time| +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ @@ -319,33 +336,48 @@ IoTDB:database1> select min(columns(*)) from table1 > 使用限制:出现多个 COLUMNS 函数时,多个 COLUMNS 函数的参数要完全相同 +查询 'h' 开头列的最小值和最大值之和 ```sql --- 查询 'h' 开头列的最小值和最大值之和 -IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1 +IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1; +``` +执行结果如下: +```shell +--------------+ |_col0_humidity| +--------------+ | 79.899994| +--------------+ +``` --- 错误查询,两个 COLUMNS 函数不完全相同 -IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1 +错误查询,两个 COLUMNS 函数不完全相同 +```SQL +IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1; +``` +执行结果如下: +```shell Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Multiple different COLUMNS in the same expression are not supported ``` - 多个 COLUMNS 函数,出现在不同表达式 +分别查询 'h' 开头列的最小值和最大值 ```sql --- 分别查询 'h' 开头列的最小值和最大值 -IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1 +IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1; +``` +执行结果如下: +```shell +--------------+--------------+ |_col0_humidity|_col1_humidity| +--------------+--------------+ | 34.8| 45.1| +--------------+--------------+ - --- 分别查询 'h' 开头列的最小值和 'te'开头列的最大值 -IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 +``` +分别查询 'h' 开头列的最小值和 'te'开头列的最大值 +```SQL +IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1; +``` +执行结果如下: +```shell +--------------+-----------------+ |_col0_humidity|_col1_temperature| +--------------+-----------------+ @@ -355,9 +387,12 @@ IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 3. 在 WHERE 子句中使用 +查询数据,所有 'h' 开头列的数据必须要大于 40 ```sql --- 查询数据,所有 'h' 开头列的数据必须要大于 40 -IoTDB:database1> select * from table1 where columns('^h.*') > 40 +IoTDB:database1> select * from table1 where columns('^h.*') > 40; +``` +执行结果如下: +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -365,9 +400,13 @@ IoTDB:database1> select * from table1 where columns('^h.*') > 40 |2024-11-28T09:00:00.000+08:00| 上海| 3001| 100| C| 90| null| 40.9| true| null| |2024-11-28T11:00:00.000+08:00| 上海| 3001| 100| C| 90| 88.0| 45.1| true|2024-11-28T11:00:12.000+08:00| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ - ---等价于 -IoTDB:database1> select * from table1 where humidity > 40 +``` +等价于 +```SQL +IoTDB:database1> select * from table1 where humidity > 40; +``` +执行结果如下: +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ diff --git a/src/zh/UserGuide/latest-Table/SQL-Manual/Select-Clause_timecho.md b/src/zh/UserGuide/latest-Table/SQL-Manual/Select-Clause_timecho.md index 3f2c476b1..d5568b600 100644 --- a/src/zh/UserGuide/latest-Table/SQL-Manual/Select-Clause_timecho.md +++ b/src/zh/UserGuide/latest-Table/SQL-Manual/Select-Clause_timecho.md @@ -84,7 +84,7 @@ SELECT * FROM table1; 执行结果如下: -```sql +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| modifytime| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -123,7 +123,7 @@ SELECT count(*) FROM table1; 执行结果如下: -```sql +```shell +-----+ |_col0| +-----+ @@ -143,7 +143,7 @@ SELECT region, count(*) 执行结果如下: -```sql +```shell +------+-----+ |region|_col1| +------+-----+ @@ -166,7 +166,7 @@ IoTDB> SELECT * FROM table1; 执行结果如下: -```sql +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| modifytime| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -203,7 +203,7 @@ IoTDB> SELECT device_id 执行结果如下: -```sql +```shell +------+ |device| +------+ @@ -240,7 +240,7 @@ IoTDB> SELECT table1.* 执行结果如下: -```sql +```shell +-----------------------------+----+----+-----+---+---+----+----+-----+-----------------------------+ | TIMESTAMP| REG| PL|DEVID|MOD|MNT|TEMP| HUM| STAT| MTIME| +-----------------------------+----+----+-----+---+---+----+----+-----+-----------------------------+ @@ -274,7 +274,11 @@ It costs 0.189s 示例一:直接查询 object 类型数据 ```SQL -IoTDB:database1> select s1 from table1 where device_id = 'tag1' +IoTDB:database1> select s1 from table1 where device_id = 'tag1'; +``` + +执行结果如下: +```shell +------------+ | s1| +------------+ @@ -287,7 +291,11 @@ It costs 0.428s 示例二:通过 read\_object 函数查询 Object 类型数据的真实内容 ```SQL -IoTDB:database1> select read_object(s1) from table1 where device_id = 'tag1' +IoTDB:database1> select read_object(s1) from table1 where device_id = 'tag1'; +``` + +执行结果如下: +```shell +------------+ | _col0| +------------+ @@ -301,9 +309,14 @@ It costs 0.188s ### 3.2 Columns 函数 1. 不结合表达式 + +查询列名以 'm' 开头的列的数据 ```sql --- 查询列名以 'm' 开头的列的数据 -IoTDB:database1> select columns('^m.*') from table1 limit 5 +IoTDB:database1> select columns('^m.*') from table1 limit 5; +``` + +执行结果如下: +```shell +--------+-----------+ |model_id|maintenance| +--------+-----------+ @@ -313,15 +326,23 @@ IoTDB:database1> select columns('^m.*') from table1 limit 5 | C| 90| | C| 90| +--------+-----------+ +``` - --- 查询列名以 'o' 开头的列,未匹配到任何列,抛出异常 -IoTDB:database1> select columns('^o.*') from table1 limit 5 +查询列名以 'o' 开头的列,未匹配到任何列,抛出异常 +```SQL +IoTDB:database1> select columns('^o.*') from table1 limit 5; +``` +执行结果如下: +```shell Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: No matching columns found that match regex '^o.*' +``` - --- 查询列名以 'm' 开头的列的数据,并重命名以 'series_' 开头 -IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 +查询列名以 'm' 开头的列的数据,并重命名以 'series_' 开头 +```SQL +IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5; +``` +执行结果如下: +```shell +---------------+------------------+ |series_model_id|series_maintenance| +---------------+------------------+ @@ -336,9 +357,13 @@ IoTDB:database1> select columns('^m(.*)') AS "series_$0" from table1 limit 5 2. 结合表达式 - 单个 COLUMNS 函数 + +查询所有列的最小值 ```sql --- 查询所有列的最小值 -IoTDB:database1> select min(columns(*)) from table1 +IoTDB:database1> select min(columns(*)) from table1; +``` +执行结果如下: +```shell +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ | _col0_time|_col1_region|_col2_plant_id|_col3_device_id|_col4_model_id|_col5_maintenance|_col6_temperature|_col7_humidity|_col8_status| _col9_arrival_time| +-----------------------------+------------+--------------+---------------+--------------+-----------------+-----------------+--------------+------------+-----------------------------+ @@ -350,33 +375,48 @@ IoTDB:database1> select min(columns(*)) from table1 > 使用限制:出现多个 COLUMNS 函数时,多个 COLUMNS 函数的参数要完全相同 +查询 'h' 开头列的最小值和最大值之和 ```sql --- 查询 'h' 开头列的最小值和最大值之和 -IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1 +IoTDB:database1> select min(columns('^h.*')) + max(columns('^h.*')) from table1; +``` +执行结果如下: +```shell +--------------+ |_col0_humidity| +--------------+ | 79.899994| +--------------+ +``` --- 错误查询,两个 COLUMNS 函数不完全相同 -IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1 +错误查询,两个 COLUMNS 函数不完全相同 +```SQL +IoTDB:database1> select min(columns('^h.*')) + max(columns('^t.*')) from table1; +``` +执行结果如下: +```shell Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Multiple different COLUMNS in the same expression are not supported ``` - 多个 COLUMNS 函数,出现在不同表达式 +分别查询 'h' 开头列的最小值和最大值 ```sql --- 分别查询 'h' 开头列的最小值和最大值 -IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1 +IoTDB:database1> select min(columns('^h.*')) , max(columns('^h.*')) from table1; +``` +执行结果如下: +```shell +--------------+--------------+ |_col0_humidity|_col1_humidity| +--------------+--------------+ | 34.8| 45.1| +--------------+--------------+ - --- 分别查询 'h' 开头列的最小值和 'te'开头列的最大值 -IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 +``` +分别查询 'h' 开头列的最小值和 'te'开头列的最大值 +```SQL +IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1; +``` +执行结果如下: +```shell +--------------+-----------------+ |_col0_humidity|_col1_temperature| +--------------+-----------------+ @@ -386,9 +426,12 @@ IoTDB:database1> select min(columns('^h.*')) , max(columns('^te.*')) from table1 3. 在 WHERE 子句中使用 +查询数据,所有 'h' 开头列的数据必须要大于 40 ```sql --- 查询数据,所有 'h' 开头列的数据必须要大于 40 -IoTDB:database1> select * from table1 where columns('^h.*') > 40 +IoTDB:database1> select * from table1 where columns('^h.*') > 40; +``` +执行结果如下: +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ @@ -396,9 +439,13 @@ IoTDB:database1> select * from table1 where columns('^h.*') > 40 |2024-11-28T09:00:00.000+08:00| 上海| 3001| 100| C| 90| null| 40.9| true| null| |2024-11-28T11:00:00.000+08:00| 上海| 3001| 100| C| 90| 88.0| 45.1| true|2024-11-28T11:00:12.000+08:00| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ - ---等价于 -IoTDB:database1> select * from table1 where humidity > 40 +``` +等价于 +```SQL +IoTDB:database1> select * from table1 where humidity > 40; +``` +执行结果如下: +```shell +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+ | time|region|plant_id|device_id|model_id|maintenance|temperature|humidity|status| arrival_time| +-----------------------------+------+--------+---------+--------+-----------+-----------+--------+------+-----------------------------+