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).
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.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.
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.
DEFAULT keyword is only valid inside INSERT VALUES lists. Using it in other contexts (SELECT, WHERE, UPDATE) produces an error.
Conflict Handling
TheOR 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 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
- INSERT … ON CONFLICT (UPSERT) for conditional insert-or-update behavior
- REPLACE for shorthand INSERT OR REPLACE
- SELECT for the query syntax used with INSERT INTO … SELECT
- CREATE TABLE for column definitions and default values