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, except that a column partition key must always be supplied. The missing values do not use storage space.

To insert the result of a query, use INSERT INTO … SELECT.

11.3. Column-partitioned tables#

For Column partitioning, include both $timestamp and the ordinary partition key in every row. The key cannot be NULL. Empty STRING keys are rejected because the current storage representation treats them as NULL. INT64_MIN is reserved for NULL, and selected TIMESTAMP keys must be within the valid domain described in Supported operations and limitations.

QuasarDB routes each row by its key and keeps the supplied columns aligned. Invalid keys are rejected during ingestion preflight, before the batch is sent. Non-key columns can still be omitted.

For the sensor_readings table in the guide:

INSERT INTO sensor_readings ($timestamp, sensor_id, value)
VALUES (2026-01-01T10:03:00, 101, 14.0);

See Supported operations and limitations for ingestion mode restrictions.

11.4. Parameters#

table_name

The name of the target table.

column_name

The name of a target column.

value

The value to add to the column. The value type must be compatible with the column type.

expression

An expression that calculates the value to add. You can use now as the value for $timestamp. For more information, refer to timestamps.

11.5. 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 nanosecond:

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)