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. Parameters#

table_name

The name of the target table.

select_statement

A SELECT statement that supplies the rows to insert.

12.4. 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