IoTDB 入门教程 基础篇⑥——数据库SQL操作 | 数据库管理和数据读写

embedded/2024/9/23 22:32:51/

文章目录

  • 一、前文
  • 二、数据库管理
  • 三、数据读写
    • 3.1 查询数据
    • 3.2 新增数据
    • 3.3 修改数据
    • 3.4 删除数据
  • 四、参考

一、前文

IoTDB入门教程——导读

本博文主要讲述数据库管理和数据读写

二、数据库管理

2.1 创建数据库

CREATE DATABASE root.ln

sql">IoTDB> CREATE DATABASE root.test
Msg: The statement is executed successfully.

注意:必须是root.开头

这一点也是我一直吐槽的地方,为啥要限制必须root.开头呢?

全部都是root.开头不就等于全部都没有root.开头。意义何在呢。

sql">IoTDB> CREATE DATABASE test
Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 700: Error occurred while parsing SQL to physical plan: line 1:16 mismatched input 'test' expecting ROOT
IoTDB> CREATE DATABASE test.test
Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 700: Error occurred while parsing SQL to physical plan: line 1:16 mismatched input 'test' expecting ROOT

注意:Database的父子节点都不能再设置 database

sql">IoTDB> CREATE DATABASE root.test.aa
Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 501: root.test has already been created as database
IoTDB> CREATE DATABASE root.test1.aa
Msg: The statement is executed successfully.

2.2 查询数据库

SHOW DATABASES;

sql">IoTDB> SHOW DATABASES;
+----------------+----+-----------------------+---------------------+---------------------+
|        Database| TTL|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|
+----------------+----+-----------------------+---------------------+---------------------+
|      root.user1|null|                      1|                    1|            604800000|
|   root.test1.aa|null|                      1|                    1|            604800000|
|       root.test|null|                      1|                    1|            604800000|
|root.water_meter|null|                      1|                    1|            604800000|
+----------------+----+-----------------------+---------------------+---------------------+
Total line number = 4
It costs 0.010s

2.3 删除数据库

DELETE DATABASE root.ln

sql">IoTDB> DELETE DATABASE root.user1
Msg: The statement is executed successfully.
IoTDB> SHOW DATABASES;
+----------------+----+-----------------------+---------------------+---------------------+
|        Database| TTL|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|
+----------------+----+-----------------------+---------------------+---------------------+
|   root.test1.aa|null|                      1|                    1|            604800000|
|       root.test|null|                      1|                    1|            604800000|
|root.water_meter|null|                      1|                    1|            604800000|
+----------------+----+-----------------------+---------------------+---------------------+
Total line number = 3
It costs 0.006s
sql">IoTDB> DELETE DATABASE root.test1.aa
Msg: The statement is executed successfully.
IoTDB> SHOW DATABASES;
+----------------+----+-----------------------+---------------------+---------------------+
|        Database| TTL|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|
+----------------+----+-----------------------+---------------------+---------------------+
|       root.test|null|                      1|                    1|            604800000|
|root.water_meter|null|                      1|                    1|            604800000|
+----------------+----+-----------------------+---------------------+---------------------+
Total line number = 2
It costs 0.005s

三、数据读写

3.1 查询数据

select status from root.test.test

sql">IoTDB> select status from root.test.test
+-----------------------------+---------------------+
|                         Time|root.test.test.status|
+-----------------------------+---------------------+
|2024-05-03T19:18:07.573+08:00|                  1.0|
|2024-05-03T19:18:19.825+08:00|                  2.0|
|2024-05-03T19:18:21.893+08:00|                  3.0|
+-----------------------------+---------------------+
Total line number = 3
It costs 0.127s

3.2 新增数据

  • 新增单条数据

INSERT INTO root.test.test(status) values(1)

sql">IoTDB> INSERT INTO root.test.test(status) values(1)
Msg: The statement is executed successfully.
IoTDB> INSERT INTO root.test.test(status) values(2)
Msg: The statement is executed successfully.
IoTDB> INSERT INTO root.test.test(status) values(3)
Msg: The statement is executed successfully.
IoTDB> select status from root.test.test
+-----------------------------+---------------------+
|                         Time|root.test.test.status|
+-----------------------------+---------------------+
|2024-05-03T19:18:07.573+08:00|                  1.0|
|2024-05-03T19:18:19.825+08:00|                  2.0|
|2024-05-03T19:18:21.893+08:00|                  3.0|
+-----------------------------+---------------------+
Total line number = 3
It costs 0.127s
  • 新增多条数据

注意:新增多条数据,需要传入时间戳参数

INSERT INTO root.test.test(timestamp,status) values(1,4),(2,5),(3,6)

sql">IoTDB> INSERT INTO root.test.test(timestamp,status) values(1,4),(2,5),(3,6)
Msg: The statement is executed successfully.
IoTDB> select status from root.test.test
+-----------------------------+---------------------+
|                         Time|root.test.test.status|
+-----------------------------+---------------------+
|1970-01-01T08:00:00.001+08:00|                  4.0|
|1970-01-01T08:00:00.002+08:00|                  5.0|
|1970-01-01T08:00:00.003+08:00|                  6.0|
|2024-05-03T19:18:07.573+08:00|                  1.0|
|2024-05-03T19:18:19.825+08:00|                  2.0|
|2024-05-03T19:18:21.893+08:00|                  3.0|
+-----------------------------+---------------------+
Total line number = 6
It costs 0.012s

3.3 修改数据

传入同样的时间戳,即可覆盖该时间戳的上一条数据

sql">IoTDB> INSERT INTO root.test.test(timestamp,status) values(1,444)
Msg: The statement is executed successfully.
IoTDB> SELECT status FROM root.test.test
+-----------------------------+---------------------+
|                         Time|root.test.test.status|
+-----------------------------+---------------------+
|1970-01-01T08:00:00.001+08:00|                444.0|
|1970-01-01T08:00:00.002+08:00|                  5.0|
|1970-01-01T08:00:00.003+08:00|                  6.0|
|2024-05-03T19:18:07.573+08:00|                  1.0|
|2024-05-03T19:18:19.825+08:00|                  2.0|
|2024-05-03T19:18:21.893+08:00|                  3.0|
+-----------------------------+---------------------+
Total line number = 6
It costs 0.010s

3.4 删除数据

DELETE FROM root.test.test.status where time < 4

sql">IoTDB> DELETE FROM root.test.test.status where time < 4
Msg: The statement is executed successfully.
IoTDB> SELECT status FROM root.test.test
+-----------------------------+---------------------+
|                         Time|root.test.test.status|
+-----------------------------+---------------------+
|2024-05-03T19:18:07.573+08:00|                  1.0|
|2024-05-03T19:18:19.825+08:00|                  2.0|
|2024-05-03T19:18:21.893+08:00|                  3.0|
+-----------------------------+---------------------+
Total line number = 3
It costs 0.014s

四、参考

SQL手册 | IoTDB Website

数据增删 | IoTDB Website

数据查询 | IoTDB Website

觉得好,就一键三连呗(点赞+收藏+关注)


http://www.ppmy.cn/embedded/37647.html

相关文章

Rust:用 Warp 库实现 Restful API 的简单示例

直接上代码&#xff1a; 1、源文件 Cargo.toml [package] name "xcalc" version "0.1.0" edition "2021"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html[dependencies] warp "…

Linux守护进程

进程组和会话在 UNIX 系统中是非常重要的概念&#xff0c;特别是在进行作业控制和终端会话管理时。下面是关于进程组和会话的详细解释&#xff1a; 进程组&#xff08;Process Group&#xff09; 定义与作用&#xff1a; 进程组是一个或多个进程的集合&#xff0c;这些进程通常…

042.最近的请求次数

刷算法题&#xff1a; 第一遍&#xff1a;1.看5分钟&#xff0c;没思路看题解 2.通过题解改进自己的解法&#xff0c;并且要写每行的注释以及自己的思路。 3.思考自己做到了题解的哪一步&#xff0c;下次怎么才能做对(总结方法) 4.整理到自己的自媒体平台。 5.再刷重复的类…

前后端分离项目中的一些疑惑

1、前后端分离项目&#xff0c;浏览器发起请求后&#xff0c;请求的是前端服务器还是后端服务器&#xff1f; 在前后端分离的项目中&#xff0c;当浏览器发起请求时&#xff0c;它首先会请求的是前端服务器。 前后端分离的工作流程大致如下&#xff1a; 用户在浏览器中输入网…

windows10打印机共享完美解决方案

提到文件共享大家并不陌生,相关的还有打印机共享,这个多见于单位、复印部,在一个区域网里多台电脑共用一台打印机,打印资料非常方便,就包括在家里,我们现在一般都会有多台电脑或设备,通过家庭网络联接,如果共享一台打印机的话也是件便捷的事。 但是随着操作系统的更新…

三维球体空间中光线反射模拟与三维点云提取matlab仿真

目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.本算法原理 5.完整程序 1.程序功能描述 三维球体空间中光线反射模拟与三维点云提取matlab仿真。设置一个三维的椭球模型&#xff0c;作为墙壁&#xff0c;然后根据光线的反射原理&#xff0c;设计三维空…

【第6节课笔记】LagentAgentLego

Lagent 最中间部分的是LLM&#xff0c;即为大语言模型模块&#xff0c;他可以思考planning和调用什么action&#xff0c;再将其转发给动作执行器action executer执行。 支持的工具如下&#xff1a; Arxiv 搜索 Bing 地图 Google 学术搜索 Google 搜索 交互式 IPython 解释器 IP…

电商核心内容揭秘50:个性化广告与投放策略

相关系列文章 电商技术揭秘相关系列文章合集&#xff08;1&#xff09; 电商技术揭秘相关系列文章合集&#xff08;2&#xff09; 电商技术揭秘相关系列文章合集&#xff08;3&#xff09; 电商技术揭秘四十一&#xff1a;电商平台的营销系统浅析 电商技术揭秘四十二&#…