12. INSERT INTO … SELECT#

12.1. Synopsis#

INSERT INTO <table_name> <select_statement>

12.2. Description#

INSERT INTO ... SELECT inserts the result of a query into an existing table. Use this statement to copy or transform data without transferring the data through a client application.

The target table must exist. The selected columns must be compatible with the columns in the target table.

For a time-series table, the SELECT result must include $timestamp. For a table that does not have a timestamp column, do not select $timestamp.

To insert specified values, use INSERT INTO … VALUES.

12.3. Column-partitioned tables#

INSERT SELECT supports existing column-partitioned destinations, including queries over default timestamp layouts or a different column layout. Include $timestamp and the destination partition-key column in the SELECT result. Each destination key must be valid and non-NULL; empty STRING keys are invalid. Rows are routed by the destination policy, which need not match the source.

For example, copy the guide’s readings into an existing HASH layout:

INSERT INTO sensor_hash
  SELECT $timestamp, sensor_id, value FROM sensor_readings;

This does not enable partitioned CREATE TABLE AS SELECT. Create the destination with CREATE TABLE first. See Supported operations and limitations for the current support matrix.

12.4. Parameters#

table_name

The name of the target table.

select_statement

A SELECT statement that supplies the rows to insert.

12.5. Examples#

Copy rows to another table:

INSERT INTO archive
  SELECT $timestamp, value
  FROM measurements

Copy rows that are older than a specified date:

INSERT INTO archive
  SELECT $timestamp, value
  FROM measurements
  WHERE $timestamp < 2026-01-01

Transform values before you insert them:

INSERT INTO temperatures_fahrenheit
  SELECT $timestamp, (temperature * 9 / 5) + 32 AS temperature
  FROM temperatures_celsius