Skip to content

INSERT

INSERT appends rows to an existing table. Each statement commits individually.

CREATE TABLE events (id BIGINT, region VARCHAR);
INSERT INTO events (id, region) VALUES (1, 'eu'), (2, 'us');
INSERT INTO table_name [(column [, ...])]
VALUES (expression [, ...]) [, ...];
INSERT INTO table_name [(column [, ...])]
SELECT ...;
INSERT INTO table_name BY NAME
SELECT ...;

An explicit column list maps input values to those columns in order. Columns omitted from that list are filled with NULL.

INSERT INTO events (id) VALUES (3);

This adds a row whose region is NULL.

Use a query to produce the input rows. Its output must match the target columns in number and compatible types.

INSERT INTO events (id, region)
SELECT range, 'eu' FROM range(4, 7);

BY NAME matches query output names to target columns rather than using position. Omitted target columns are filled with NULL.

INSERT INTO events BY NAME
SELECT 'us' AS region, 7 AS id;

DEFAULT VALUES is not supported. BEGIN and ROLLBACK do not group or undo inserts; see transaction behavior.

  • CREATE TABLE - define the target table.
  • COPY - stream Arrow IPC data from a client.
  • SELECT - construct an input query.