插入命令
Data can be inserted into a hypertable using the standard INSERT SQL command (PostgreSQL docs).
可以使用标准INSERT SQL
命令向hypertable中插入数据。
INSERT INTO conditions(time, location, temperature, humidity)
VALUES (NOW(), 'office', 70.0, 50.0);
You can also insert multiple rows into a hypertable using a single INSERT call, even thousands at a time. This is typically much more efficient than inserting data row-by-row, and is recommended when possible.
可以使用单一的INSERT call命令向hypertable中一次插入多行,甚至上千行数据。该方法比逐行插入数据更高效,必要时推荐使用该方法。
INSERT INTO conditions
VALUES
(NOW(), 'office', 70.0, 50.0),
(NOW(), 'basement', 66.5, 60.0),
(NOW(), 'garage', 77.0, 65.2);
TIP:The rows that belong to a single batch INSERT command do not need to belong to the same chunk (by time interval or partitioning key). Upon receiving an INSERT command for multiple rows, the TimescaleDB engine will determine which rows (sub-batches) belong to which chunks, and will write them accordingly to each chunk in a single transaction.
上述INSERT命令批量插入的数据行可以属于不同区块(时间键和空间键分割的区域均可)。TimescaleDB接收到INSERT多行插入命令时,其引擎会根据区块区分数据行,根据各数据行的区块将数据行写入单独事务中。
You can also specify that INSERT returns some or all of the inserted data via the RETURNING statement:
你还可以指定INSERT命令通过RETURNING语句返回部分或所有插入的数据。
INSERT INTO conditions
VALUES (NOW(), 'office', 70.1, 50.1) RETURNING *;
time | location | temperature | humidity
-------------------------------+----------+-------------+----------
2017-07-28 11:42:42.846621+00 | office | 70.1 | 50.1
(1 row)