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

【已解决】TDengine中taos客户端中尝试新建数据库并插入数据

数据 crifan 373浏览 0评论
折腾:
【未解决】试用TDeigine数据库的功能和效果
期间,参考官网:
Getting Started | TDengine
再去试试taos的客户端命令行中,试试新建数据库和插入数据:
taos> create table item (ts timestamp, dataStr vchar)
不过要去搞清楚,如何创建可变长度的字符串
文档 | TDengine
文档 | 涛思数据
https://www.taosdata.com/cn/documentation/data-model-and-architecture/#数据模型
文档 | 涛思数据
https://www.taosdata.com/cn/documentation/taos-sql/#支持的数据类型
用BINARY或NCHAR
不过NCHAR要指定长度,占用也大
然后此处暂时,BINARY的504长度够用,所以就暂时用这个
taos> create table item (ts timestamp, dataStr binary);

DB error: invalid SQL: invalid binary/nchar column length
binary也需要指定长度的
此处一般来说,长度长的数据有200多个字节,所以此处暂时设置为500,足够用了
taos> create table item (ts timestamp, dataStr binary(500));
Query OK, 1 row(s) affected (0.010996s)
去插入数据,但是出错:
taos> insert into t values('20200301 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');


DB error: invalid table
原来是搞错table了。。
taos> insert into item values('20200301 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');


DB error: invalid SQL: syntax error near "20200301 11:00:00" (invalid timestamp)
timestamp无效。
看到是年月日中间短横线才行:
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)
可以了。
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 12:00:00', '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 0
2 00 00 00 00 00');
Query OK, 1 row(s) affected (0.000413s)


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)
然后看看现在的数据,结果:
【已解决】TDengine中taoos中插入数据没报错但实际上没插入成功
再去看数据,就是我们希望的4条了:
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                                                                                                                                                                                                                                    |
 20-03-01 12:10:00.000|68 14 0C D3 00 00 01 87 14 00 05 00 01 00 00 01 01 01 00 00 00 01                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
 20-03-01 12:20:00.000|68 12 34 B8 00 00 0F 81 05 00 05 00 01 0C 00 95 42 03 00 00                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
Query OK, 4 row(s) in set (0.001079s)
【总结】
此处去新建数据库:
create database ie104;
切换到该数据库:
use ie104;
创建表结构:
create table item (ts timestamp, dataStr binary(500));
插入数据:
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');

insert into item values('2020-03-01 12:00:00', '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 0
2 00 00 00 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');

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');
查看当前数据:
select * from item;
即可。

转载请注明:在路上 » 【已解决】TDengine中taos客户端中尝试新建数据库并插入数据

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
86 queries in 0.112 seconds, using 20.69MB memory