最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【已解决】TDengine中taoos中插入数据没报错但实际上没插入成功

数据 crifan 79浏览 0评论
折腾:
【未解决】TDengine中taos客户端中尝试新建数据库并插入数据
期间,去select看看当前数据:
taos> select * from item;
          ts          |                                                                                                                                                                                                                                                      datastr                                                                                                                                                                                                                                                       |
============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
 20-03-01 11:00:00.000|68 14 12 D3 00 00 01 87 14 00 05 00 01 00 00 01 01 01 00 00 00 01                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
 20-03-01 12:00:00.000|68 59 0E D3 00 00 15 A6 14 00 05 00 01 07 00 02 00 00 00 00 00 CE 5D 96 5D B5 5D 45 00 01 00 FE FF 7C 00 83 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 88 13 00 00 02 00 00 00 00 00 FE FF 00 00 00 00 A3 00 00 00 00 00 02 00 00 00 00 00                                                                                                                                                                                                                                    |
Query OK, 2 row(s) in set (0.001156s)
发现很奇怪啊,应该有4个数据的,怎么只有2个?
然后注意到前面有2个:
Query OK, 0 row(s) affected (0.000606s)
说明没插入成功啊
找找原因
再去试试:
taos> insert into item values('2020-03-01 10:00:00', '68 14 0C D3 00 00 01 87 14 00 05 00 01 00 00 01 01 01 00 00 00 01');
Query OK, 0 row(s) affected (0.000673s)
问题依旧。
-》难道是因为前面的:
taos> insert into item values('2020-03-01 10:00:00', '68 14 0C D3 00 00 01 87 14 00 05 00 01 00 00 01 01 01 00 00 00 01');
Query OK, 0 row(s) affected (0.000606s)

taos> insert into item values('2020-03-01 09:00:00', '68 12 34 B8 00 00 0F 81 05 00 05 00 01 0C 00 95 42 03 00 00');
Query OK, 0 row(s) affected (0.000502s)
此处有2个时间戳:
2020-03-01 09:00:00
2020-03-01 10:00:00
比第一条的时间戳:
2020-03-01 11:00:00
更早,所以被忽略了??
那故意换成更新的时间试试:
insert into item values('2020-03-01 12:10:00', '68 14 0C D3 00 00 01 87 14 00 05 00 01 00 00 01 01 01 00 00 00 01');
果然可以了:
taos> insert into item values('2020-03-01 12:10:00', '68 14 0C D3 00 00 01 87 14 00 05 00 01 00 00 01 01 01 00 00 00 01');
Query OK, 1 row(s) affected (0.000397s)
再去插入:
taos> insert into item values('2020-03-01 12:20:00', '68 12 34 B8 00 00 0F 81 05 00 05 00 01 0C 00 95 42 03 00 00');
Query OK, 1 row(s) affected (0.000323s)
【总结】
此处TDengine是时序数据库,所以当你建的表中有timestamp的key的话
其内部就加了额外的逻辑校验:
当后续插入的数据的timestamp,不能早于第一条的数据的时间,否则无法插入。
即此处:
taos> create table item (ts timestamp, dataStr binary(500));
Query OK, 1 row(s) affected (0.010996s)
创建了表。
第一条数据是
taos> insert into item values('2020-03-01 11:00:00', '68 14 12 D3 00 00 01 87 14 00 05 00 01 00 00 01 01 01 00 00 00 01');
Query OK, 1 row(s) affected (0.000496s)
其中时间戳是:2020-03-01 11:00:00
后续插入的数据的timestamp早于这个值:
taos> insert into item values('2020-03-01 10:00:00', '68 14 0C D3 00 00 01 87 14 00 05 00 01 00 00 01 01 01 00 00 00 01');
Query OK, 0 row(s) affected (0.000606s)
虽然OK,但是0 row(s) affected,表示没有插入。
只有时间戳大于第一条数据:
taos> insert into item values('2020-03-01 12:10:00', '68 14 0C D3 00 00 01 87 14 00 05 00 01 00 00 01 01 01 00 00 00 01');
Query OK, 1 row(s) affected (0.000397s)
才是:1 row(s) affected,表示插入成功。

转载请注明:在路上 » 【已解决】TDengine中taoos中插入数据没报错但实际上没插入成功

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
22 queries in 0.082 seconds, using 9.43MB memory