INSERT
The INSERT statement adds new rows to a table.
WarningINSERT is experimental and only works against local or limited storage backends. It is not suitable for production use.
Syntax
INSERT INTO <table_name> [ ( <column> [, ...] ) ]
{ VALUES ( <value> [, ...] ) [, ...] | <select_statement> };Parameters
<table_name>— the table to insert into.<column>— an explicit column list. Optional; when given, it must name every column in the target table — see Partial Inserts below. Omitting it inserts into the table's columns in schema order.<value>— literal values for one row. Give more than one parenthesized group, comma-separated, to insert multiple rows in one statement.<select_statement>— aSELECTquery whose result rows are inserted in place of aVALUESlist.
Examples
Single Row Insert
INSERT INTO users (id, name, email, active)
VALUES (1, 'John Doe', 'john@example.com', TRUE);Multiple Row Insert
INSERT INTO users (id, name, email, active)
VALUES
(1, 'John Doe', 'john@example.com', TRUE),
(2, 'Jane Smith', 'jane@example.com', TRUE),
(3, 'Bob Johnson', 'bob@example.com', FALSE);Insert Without a Column List
Values are matched to the table's columns in schema order:
INSERT INTO users
VALUES (1, 'John Doe', 'john@example.com', TRUE);Insert from SELECT
INSERT INTO users_backup (id, name, email)
SELECT id, name, email FROM users WHERE archived = FALSE;Partial Inserts
Inserting into a subset of a table's columns is not supported. An explicit column list must name every column in the target table; a shorter list is rejected when the query is planned, rather than leaving the unlisted columns to be filled with something you did not ask for:
INSERT explicit column list must list all target columns
(target has 4, got 3). Partial column inserts are not yet supported.
The list may reorder columns relative to the schema — it just cannot omit any.
Notes
- INSERT is experimental and only works against local or limited storage backends.
- The column list is optional; when present it must be complete (see above).
- Column order in the VALUES clause must match the column list, or the table's schema order when no list is given.
- The number of values per row, and each value's type, are checked at plan time against the target's schema — a mismatch is rejected before any data is written.
INSERT OVERWRITEis not supported.- A materialized view is not a table: this statement is rejected against one. Its contents come from its defining
SELECT— see REFRESH MATERIALIZED VIEW.