INSERT

IoTDB provides users with a variety of ways to insert real-time data, such as directly inputting INSERT SQL statement in Client/Shell tools, or using Java JDBC to perform single or batch execution of INSERT SQL statement.

NOTE: This section mainly introduces the use of INSERT SQL statement for real-time data import in the scenario.

Writing a repeat timestamp covers the original timestamp data, which can be regarded as updated data.

Use of INSERT Statements

The INSERT SQL statement statement is used to insert data into one or more specified timeseries created. For each point of data inserted, it consists of a timestamp and a sensor acquisition value (see Data Type).

In the scenario of this section, take two timeseries root.ln.wf02.wt02.status and root.ln.wf02.wt02.hardware as an example, and their data types are BOOLEAN and TEXT, respectively.

The sample code for single column data insertion is as follows:

  1. IoTDB > insert into root.ln.wf02.wt02(timestamp,status) values(1,true)
  2. IoTDB > insert into root.ln.wf02.wt02(timestamp,hardware) values(1, 'v1')

The above example code inserts the long integer timestamp and the value “true” into the timeseries root.ln.wf02.wt02.status and inserts the long integer timestamp and the value “v1” into the timeseries root.ln.wf02.wt02.hardware. When the execution is successful, cost time is shown to indicate that the data insertion has been completed.

Note: In IoTDB, TEXT type data can be represented by single and double quotation marks. The insertion statement above uses double quotation marks for TEXT type data. The following example will use single quotation marks for TEXT type data.

The INSERT statement can also support the insertion of multi-column data at the same time point. The sample code of inserting the values of the two timeseries at the same time point ‘2’ is as follows:

  1. IoTDB > insert into root.ln.wf02.wt02(timestamp, status, hardware) VALUES (2, false, 'v2')

In addition, The INSERT statement support insert multi-rows at once. The sample code of inserting two rows as follows:

  1. IoTDB > insert into root.ln.wf02.wt02(timestamp, status, hardware) VALUES (3, false, 'v3'),(4, true, 'v4')

After inserting the data, we can simply query the inserted data using the SELECT statement:

  1. IoTDB > select * from root.ln.wf02.wt02 where time < 5

The result is shown below. The query result shows that the insertion statements of single column and multi column data are performed correctly.

  1. +-----------------------------+--------------------------+------------------------+
  2. | Time|root.ln.wf02.wt02.hardware|root.ln.wf02.wt02.status|
  3. +-----------------------------+--------------------------+------------------------+
  4. |1970-01-01T08:00:00.001+08:00| v1| true|
  5. |1970-01-01T08:00:00.002+08:00| v2| false|
  6. |1970-01-01T08:00:00.003+08:00| v3| false|
  7. |1970-01-01T08:00:00.004+08:00| v4| true|
  8. +-----------------------------+--------------------------+------------------------+
  9. Total line number = 4
  10. It costs 0.004s

In addition, we can omit the timestamp column, and the system will use the current system timestamp as the timestamp of the data point. The sample code is as follows:

  1. IoTDB > insert into root.ln.wf02.wt02(status, hardware) values (false, 'v2')

Note: Timestamps must be specified when inserting multiple rows of data in a SQL.

Insert Data Into Aligned Timeseries

To insert data into a group of aligned time series, we only need to add the ALIGNED keyword in SQL, and others are similar.

The sample code is as follows:

  1. IoTDB > create aligned timeseries root.sg1.d1(s1 INT32, s2 DOUBLE)
  2. IoTDB > insert into root.sg1.d1(time, s1, s2) aligned values(1, 1, 1)
  3. IoTDB > insert into root.sg1.d1(time, s1, s2) aligned values(2, 2, 2), (3, 3, 3)
  4. IoTDB > select * from root.sg1.d1

The result is shown below. The query result shows that the insertion statements are performed correctly.

  1. +-----------------------------+--------------+--------------+
  2. | Time|root.sg1.d1.s1|root.sg1.d1.s2|
  3. +-----------------------------+--------------+--------------+
  4. |1970-01-01T08:00:00.001+08:00| 1| 1.0|
  5. |1970-01-01T08:00:00.002+08:00| 2| 2.0|
  6. |1970-01-01T08:00:00.003+08:00| 3| 3.0|
  7. +-----------------------------+--------------+--------------+
  8. Total line number = 3
  9. It costs 0.004s