INSERT
INSERT appends rows to an existing table. Each statement commits individually.
Example
Section titled “Example”CREATE TABLE events (id BIGINT, region VARCHAR);INSERT INTO events (id, region) VALUES (1, 'eu'), (2, 'us');Syntax
Section titled “Syntax”INSERT INTO table_name [(column [, ...])]VALUES (expression [, ...]) [, ...];
INSERT INTO table_name [(column [, ...])]SELECT ...;
INSERT INTO table_name BY NAMESELECT ...;Target columns
Section titled “Target columns”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.
Insert from a query
Section titled “Insert from a query”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 NAMESELECT 'us' AS region, 7 AS id;Limitations
Section titled “Limitations”DEFAULT VALUES is not supported. BEGIN and ROLLBACK do not group or undo
inserts; see transaction behavior.
Related
Section titled “Related”- CREATE TABLE - define the target table.
- COPY - stream Arrow IPC data from a client.
- SELECT - construct an input query.
