Skip to main content

INSERT

Adds one or more rows to a table. Rows can be specified as literal values, copied from another query, or generated from column defaults.

Syntax

Parameters

Description

INSERT adds new rows to the specified table. There are three forms:
  • VALUES: Insert one or more rows with explicit values.
  • SELECT: Insert the result set of a query.
  • DEFAULT VALUES: Insert a single row where every column uses its default value (or NULL if no default is defined).
When a column list is provided, only those columns receive explicit values. All other columns use their default value or NULL. When no column list is provided, values must be supplied for every column in the table, in the order the columns were defined.

Inserting Rows

Single Row

Multiple Rows

Supply multiple parenthesized groups separated by commas.

All Columns

When the column list is omitted, provide a value for every column in table-definition order.

INSERT INTO … SELECT

Inserts the result of a SELECT statement. The number of columns returned by the SELECT must match the number of target columns.
The SELECT can include any valid clause: WHERE, JOIN, GROUP BY, ORDER BY, LIMIT, UNION, or subqueries.

DEFAULT VALUES

Inserts a single row where every column receives its default value. Columns without an explicit DEFAULT definition receive NULL. INTEGER PRIMARY KEY columns receive an auto-generated rowid.

Column Default Values

When a column list is provided, omitted columns use their default values.

DEFAULT Keyword in VALUES

Turso extension — This feature follows the SQL standard (SQL:2016) but is not supported by SQLite.
The DEFAULT keyword can be used in place of any value expression in a VALUES list. It resolves to the column’s default value as defined in the CREATE TABLE statement, or NULL if no default is defined. This is particularly useful when inserting multiple rows where different rows need defaults for different columns — something that cannot be achieved by simply omitting columns from the column list.
The DEFAULT keyword is only valid inside INSERT VALUES lists. Using it in other contexts (SELECT, WHERE, UPDATE) produces an error.

Conflict Handling

The OR clause specifies what happens when an INSERT violates a uniqueness or NOT NULL constraint.
For more granular conflict handling based on specific constraints, use the ON CONFLICT clause (UPSERT), which allows different actions depending on which constraint was violated.

RETURNING Clause

Returns data from the rows that were actually inserted. This is useful for retrieving generated values such as auto-incremented IDs or evaluated defaults.
RETURNING accepts any expression that can reference the inserted row’s columns.

RETURNING with Multiple Rows

RETURNING *

Return all columns of the inserted rows.

Examples

Insert with Subquery Values

Insert with Conflict Handling and RETURNING

Archival Pattern

See Also