TD2.0.6 JDBC 创建超级表后,不能通过插入语句自动建子表
使用官方Demo测试 INSERT INTO ${table} using ${dbname}.${stable} tags 无法创建第二个子表。 \tests\examples\JDBC\springbootdemo
TD版本 2.0.6.0 JDBC 2.0.8 windows客户端版本 2.0.6.0
1. 运行Demo
Get http://localhost:8080/rainstation/init 成功 true
此时TD数据库显示: 创建了数据库以及超级表。
Welcome to the TDengine shell from Linux, Client Version:2.0.6.0
Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
taos> show databases;
name | created_time | ntables | vgroups | replica | quorum | days | keep1,keep2,keep(D) | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | precision | status |
===================================================================================================================================================================================================================================================================
rainstation | 2020-10-30 09:58:17.353 | 0 | 0 | 1 | 1 | 30 | 36500,36500,36500 | 16 | 4 | 100 | 4096 | 1 | 3000 | 2 | ms | ready |
log | 2020-10-29 20:15:30.809 | 4 | 1 | 1 | 1 | 10 | 30,30,30 | 1 | 3 | 100 | 4096 | 1 | 3000 | 2 | us | ready |
Query OK, 2 row(s) in set (0.000736s)
taos> show rainstation.tables;
Query OK, 0 row(s) in set (0.000505s)
taos> DESCRIBE rainstation.monitoring;
Field | Type | Length | Note |
=================================================================================
ts | TIMESTAMP | 8 | |
name | NCHAR | 10 | |
code | BINARY | 8 | |
rainfall | FLOAT | 4 | |
station_code | BINARY | 8 | TAG |
station_name | NCHAR | 10 | TAG |
Query OK, 6 row(s) in set (0.000514s)
taos>
2. 执行 插入语句 : http://localhost:8080/rainstation/insert 成功 返回 1
此时: 控制台显示:
2020-10-30 10:02:50.132 DEBUG 20532 --- [nio-8080-exec-6] c.t.j.s.dao.RainfallMapper.save : ==> Preparing: INSERT INTO S_53648 using rainstation.monitoring tags(?, ?) (ts, name, code, rainfall) values (?, ?, ?, ?)
2020-10-30 10:02:50.139 DEBUG 20532 --- [nio-8080-exec-6] c.t.j.s.dao.RainfallMapper.save : ==> Parameters: 10001(String), 第一点位2(String), 2020-10-10 16:13:32.333(Timestamp), 第一点位(String), 10002(String), 21.0(Float)
2020-10-30 10:02:50.294 DEBUG 20532 --- [nio-8080-exec-6] c.t.j.s.dao.RainfallMapper.save : <== Updates: 1
此时TD数据库显示: 成创建子表 并对表查询:
taos> show rainstation.tables;
table_name | created_time | columns | stable_name | uid | tid | vgId |
==========================================================================================================================================================
s_53648 | 2020-10-30 10:02:50.795 | 4 | monitoring | 2533274807190467 | 1 | 9 |
Query OK, 1 row(s) in set (0.000620s)
taos> select * from rainstation.s_53648;
ts | name | code | rainfall |
===============================================================================================
2020-10-10 16:13:32.333 | 第一点位 | 10002 | 21.00000 |
Query OK, 1 row(s) in set (0.001079s)
taos> select * from rainstation.monitoring;
ts | name | code | rainfall | station_code | station_name |
===============================================================================================================================================
2020-10-10 16:13:32.333 | 第一点位 | 10002 | 21.00000 | 10001 | 第一点位2 |
Query OK, 1 row(s) in set (0.000926s)
3. 修改 表名 s_53648 改为 s_53649
执行 插入语句 : http://localhost:8080/rainstation/insert 成功 返回 1
此时 控制台显示:
2020-10-30 10:07:14.089 DEBUG 24272 --- [nio-8080-exec-2] c.t.j.s.dao.RainfallMapper.save : ==> Preparing: INSERT INTO S_53649 using rainstation.monitoring tags(?, ?) (ts, name, code, rainfall) values (?, ?, ?, ?)
2020-10-30 10:07:14.109 DEBUG 24272 --- [nio-8080-exec-2] c.t.j.s.dao.RainfallMapper.save : ==> Parameters: 10003(String), 第二点位3(String), 2020-10-10 16:13:38.666(Timestamp), 第二点位(String), 10003(String), 24.0(Float)
2020-10-30 10:07:14.253 DEBUG 24272 --- [nio-8080-exec-2] c.t.j.s.dao.RainfallMapper.save : <== Updates: 1
此时TD数据库显示:
仅有 s_53648 子表,并没有 s_53649 的子表,超级表还能查询到刚刚插入的语句。
taos> show rainstation.tables;
table_name | created_time | columns | stable_name | uid | tid | vgId |
==========================================================================================================================================================
s_53648 | 2020-10-30 10:02:50.795 | 4 | monitoring | 2533274807190467 | 1 | 9 |
Query OK, 1 row(s) in set (0.000535s)
taos> select * from rainstation.s_53649;
DB error: Table does not exist
taos> select * from rainstation.monitoring;
ts | name | code | rainfall | station_code | station_name |
==================================================================================================================================================
2020-10-10 16:13:38.666000 | 第二点位 | 10003 | 24.00000 | 10003 | 第二点位3 |
1970-01-19 21:05:17.612333 | 第一点位 | 10002 | 21.00000 | 10001 | 第一点位2 |
Query OK, 2 row(s) in set (0.002331s)
taos>
4. 在TD执行刚刚的插入语句: 会自动创建新表并且插入数据
taos> INSERT INTO S_53646 using rainstation.monitoring tags('10003', '第二点位3') (ts, name, code, rainfall) values ('2020-10-10 16:13:38.666', '第二点位', '10003', '24.0');
DB error: Database not specified or available
taos> use rainstation ;
Database changed.
taos> INSERT INTO S_53646 using rainstation.monitoring tags('10003', '第二点位3') (ts, name, code, rainfall) values ('2020-10-10 16:13:38.666', '第二点位', '10003', '24.0');
Query OK, 1 row(s) affected (0.003004s)
taos> show rainstation.tables;
table_name | created_time | columns | stable_name | uid | tid | vgId |
==========================================================================================================================================================
s_53646 | 2020-10-30 10:12:40.544 | 4 | monitoring | 2533274823968233 | 2 | 9 |
s_53648 | 2020-10-30 10:02:50.795 | 4 | monitoring | 2533274807190467 | 1 | 9 |
Query OK, 2 row(s) in set (0.000826s)
taos> INSERT INTO S_53646 using rainstation.monitoring tags('10003', '第二点位3') (ts, name, code, rainfall) values ('2020-10-10 16:13:38.666', '第二点位', '10003', '24.0');
DB error: Database not specified or available
taos> use rainstation
-> ;
Database changed.
taos> INSERT INTO S_53646 using rainstation.monitoring tags('10003', '第二点位3') (ts, name, code, rainfall) values ('2020-10-10 16:13:38.666', '第二点位', '10003', '24.0');
Query OK, 1 row(s) affected (0.003004s)
taos> show rainstation.tables;
table_name | created_time | columns | stable_name | uid | tid | vgId |
==========================================================================================================================================================
s_53646 | 2020-10-30 10:12:40.544 | 4 | monitoring | 2533274823968233 | 2 | 9 |
s_53648 | 2020-10-30 10:02:50.795 | 4 | monitoring | 2533274807190467 | 1 | 9 |
Query OK, 2 row(s) in set (0.000826s)
taos>
看明白了了,这个是例子写的不对,springbootdemo的代码里写的有问题,把station_code那个写死了,谢谢提醒,我后面会修改这个例子。
看明白了了,这个是例子写的不对,springbootdemo的代码里写的有问题,把station_code那个写死了,谢谢提醒,我后面会修改这个例子。
你并没有理解呀,不写死也是这样的问题。JDBC 连接的时候不会二次创建子表。
### 请注意:二次! 手动!修改表名 s_53648 改为 任意都不能自动创建子表,我并没有说你的demo写的问题。 ### 请注意: 二次修改表名后 Updates: 1 插入成功了。但是 show rainstation.tables; 并没有查找到二次手动修改的表名。
public int insert(Rainfall rainfall) {
Map<String, Object> map = new HashMap<>();
map.put("dbname", "rainstation");
map.put("table", "S_53648"); // 手动修改 table 值重新运行,依然不能自动创建表
map.put("stable", "monitoring");
map.put("values", rainfall);
return rainfallMapper.save(map);
}
什么叫二次创建子表?表建了一次就在了啊。 你的描述里就是插入了两张表么?一次调springboot的接口往s_53648插入,一次在shell里面往s_53648里插入,show tables就只有这两张表
看明白了了,这个是例子写的不对,springbootdemo的代码里写的有问题,把station_code那个写死了,谢谢提醒,我后面会修改这个例子。
你并没有理解呀,不写死也是这样的问题。JDBC 连接的时候不会二次创建子表。
### 请注意:二次! 手动!修改表名 s_53648 改为 任意都不能自动创建子表,我并没有说你的demo写的问题。 ### 请注意: 二次修改表名后 Updates: 1 插入成功了。但是 show rainstation.tables; 并没有查找到二次手动修改的表名。
public int insert(Rainfall rainfall) { Map<String, Object> map = new HashMap<>(); map.put("dbname", "rainstation"); map.put("table", "S_53648"); // 手动修改 table 值重新运行,依然不能自动创建表 map.put("stable", "monitoring"); map.put("values", rainfall); return rainfallMapper.save(map); }
什么叫二次创建子表?表建了一次就在了啊。 你的描述里就是插入了两张表么?一次调springboot的接口往s_53648插入,一次在shell里面往s_53648里插入,show tables就只有这两张表
看明白了了,这个是例子写的不对,springbootdemo的代码里写的有问题,把station_code那个写死了,谢谢提醒,我后面会修改这个例子。
你并没有理解呀,不写死也是这样的问题。JDBC 连接的时候不会二次创建子表。 ### 请注意:二次! 手动!修改表名 s_53648 改为 任意都不能自动创建子表,我并没有说你的demo写的问题。 ### 请注意: 二次修改表名后 Updates: 1 插入成功了。但是 show rainstation.tables; 并没有查找到二次手动修改的表名。
public int insert(Rainfall rainfall) { Map<String, Object> map = new HashMap<>(); map.put("dbname", "rainstation"); map.put("table", "S_53648"); // 手动修改 table 值重新运行,依然不能自动创建表 map.put("stable", "monitoring"); map.put("values", rainfall); return rainfallMapper.save(map); }
### 请看第三步 : 3. 修改 表名 s_53648 改为 s_53649
原先 : 表名 s_53648
public int insert(Rainfall rainfall) {
Map<String, Object> map = new HashMap<>();
map.put("dbname", "rainstation");
map.put("table", "S_53648"); // 原先 : 表名 s_53648
map.put("stable", "monitoring");
map.put("values", rainfall);
return rainfallMapper.save(map);
}
执行 插入语句 : http://localhost:8080/rainstation/insert 成功 返回 1
### 之后手动修改: 表名为 s_53649! ### 之后手动修改: 表名为 s_53649!
public int insert(Rainfall rainfall) {
Map<String, Object> map = new HashMap<>();
map.put("dbname", "rainstation");
map.put("table", "S_53649"); // 之后手动修改: 表名为 s_53649
map.put("stable", "monitoring");
map.put("values", rainfall);
return rainfallMapper.save(map);
}
执行 插入语句 : http://localhost:8080/rainstation/insert 成功 返回 1
### 然后去 Linux 下 执行 show rainstation.tables; 命令。 并没有 表名为 s_53649 的表!

经过咨询,在s_XXX 前增加指定数据库即可: 例如:insert into rainstation.s_XXX using rainstation.monitoring