11. INSERT#
11.1. Synopsis#
INSERT INTO <table_name> (
<column_name> [, ... ]
)
VALUES (
{ <value> | <expression> } [, ... ]
) [, ...]
11.2. Description#
INSERT INTO adds one or more rows to an existing table.
For a time-series table, include $timestamp in the column list.
The position of $timestamp in the list is not significant.
Do not include $timestamp when the table does not have a timestamp column.
QuasarDB matches each value to the column at the same position. Each row must have one value for each specified column.
You can insert data into a subset of the table columns.
QuasarDB stores NULL for the columns that you omit.
The missing values do not use storage space.
To insert the result of a query, use INSERT INTO … SELECT.
11.3. Parameters#
table_nameThe name of the target table.
column_nameThe name of a target column.
valueThe value to add to the column. The value type must be compatible with the column type.
expressionAn expression that calculates the value to add. You can use
nowas the value for$timestamp. For more information, refer to timestamps.
11.4. Examples#
Insert a 64-bit integer:
INSERT INTO example ($timestamp, my_int) VALUES (now(), 1234)
Insert a floating point / double:
INSERT INTO example ($timestamp, my_double) VALUES (now(), 12.34)
Insert a blob string:
INSERT INTO example ($timestamp, my_blob) VALUES (now(), 'etaoin shrdlu')
Insert a timestamp:
INSERT INTO example ($timestamp, my_ts) VALUES (now(), 2018-08-01T03:00:00)
Insert a timestamp referring to a day:
INSERT INTO example ($timestamp, my_ts) VALUES (now(), 2018-01-01)
Insert a timestamp referring to a specific nanoesecond:
INSERT INTO example ($timestamp, my_ts) VALUES (now(), 2018-08-01T00:00:00.000000001Z)
Insert a row with multiple columns:
INSERT INTO example ($timestamp, my_int, my_double, my_blob, my_ts) VALUES (now(), 1234, 12.34, 'etaoin shrdlu', 2018-08-01)
Insert three rows with one 64-bit integer each:
INSERT INTO example ($timestamp, my_int) VALUES (now(), 1234), (now(), 2345), (now(), 3456)
Insert into a table that does not have a timestamp column:
INSERT INTO example (sensor_id, value) VALUES (42, 12.34)