INSERT
The INSERT statement adds one or more new rows into a table, validating all schema constraints (PRIMARY KEY, UNIQUE, NOT NULL, and FOREIGN KEY) and updating all table indexes atomically.
Syntax
INSERT INTO table_name [(column1, column2, ...)]
VALUES (value1, value2, ...) [, (value1, value2, ...), ...];Parameters
| Parameter | Description |
|---|---|
table_name | Target table to receive the new rows. |
(column1, column2, ...) | Optional explicit list of target columns. Recommended for schema resilience; omitted columns receive their declared DEFAULT or NULL. |
VALUES (...) [, ...] | One or more parenthesized tuples of literal values or bound parameters (@param). Each tuple must match the column count. |
Single-Row Insert
Provide an explicit column list (recommended) or omit it for a positional full-row insert whose values match the table's declared column order.
-- Column-targeted insert (recommended)
INSERT INTO players (Id, Name, Score, Region)
VALUES (1, 'Ada', 980, 'EU');
-- Positional full-row insert (must match column order in CREATE TABLE)
INSERT INTO players
VALUES (2, 'Grace', 1120, 'NA');Explicit Column Lists & Defaults
When you specify an explicit column list, any omitted column automatically receives its declared DEFAULT literal, or NULL if no default is defined and the column is nullable. Omitting a NOT NULL column without a default fails validation.
-- Region receives its DEFAULT value or NULL
INSERT INTO players (Id, Name, Score)
VALUES (3, 'Linus', 875);
-- Inserting explicit NULL values
INSERT INTO players (Id, Name, Score, Region)
VALUES (4, 'Margaret', 1050, NULL);Multi-Row VALUES
Insert multiple rows in a single statement by separating value tuples with commas. Multi-row inserts reduce parse overhead and execute under a single write lock in auto-commit mode.
INSERT INTO matches (Id, PlayerId, Points, PlayedOn)
VALUES
(101, 1, 85, '2026-03-14'),
(102, 2, 92, '2026-03-15'),
(103, 1, 110, '2026-03-16');Inserting VECTOR Columns
DataVo Extension
VECTOR(n) columns accept single-quoted bracketed float-array literals (such as '[0.1, 0.2, 0.3]') or bound parameters (@embedding). The element count must exactly match the column's declared dimension n.
-- Quoted vector literal (shown with a 3-element shorthand; provide 384 floats for VECTOR(384))
INSERT INTO documents (Id, Title, Category, Embedding)
VALUES (1, 'Quickstart Guide', 'guide', '[0.12, 0.85, 0.44]');
-- Bound parameter in parameterized SQL (recommended for high-dimensional VECTOR(384) embeddings)
INSERT INTO documents (Id, Title, Category, Embedding)
VALUES (@id, @title, @category, @embedding);Literal & Expression Rules in VALUES
- Quoted vectors only: Unquoted array syntax like
[0.1, 0.2, 0.3]is not accepted by the SQL parser and raises a syntax error. Always quote vector literals ('[0.1, 0.2, 0.3]') or pass afloat[]parameter. - No expressions in
VALUES: Arithmetic or function expressions insideVALUES(for exampleVALUES (1, 'Ada', 100 + 50, 'EU')orUPPER('eu')) are not parsed. Supply plain literals ('text',42,3.14,TRUE,NULL) or bound@parameters.
Constraints, Indexes & Transactions
- Constraint enforcement: Every row is checked against
PRIMARY KEY,UNIQUE,NOT NULL, andFOREIGN KEYconstraints before storage is modified. If any row in a multi-row batch fails validation, the statement aborts with an error. - Index maintenance: All B-Tree,
HNSW,FLAT, andCOLUMNARindexes on the table are updated automatically. - Transactions: Inside an explicit
BEGIN...COMMITblock, inserted rows are buffered inTransactionContext, visible immediately to subsequent queries in the same transaction, and cleanly discarded onROLLBACKorROLLBACK TO SAVEPOINT.
Unsupported INSERT Clauses in v0.4
The following SQL extensions are not supported in DataVo v0.4:
INSERT ... ON CONFLICT DO UPDATE / DO NOTHING(upsert)INSERT OR REPLACE/REPLACE INTOINSERT INTO ... SELECT ...RETURNINGclauses
To upsert rows in application code, check existence or handle the key conflict inside a transaction, then run UPDATE or INSERT.
See Also
- UPDATE: Modifying existing rows with
SETexpressions - DELETE: Removing rows and compacting storage with
VACUUM - CREATE TABLE: Defining column types,
DEFAULTvalues, and constraints - Transactions: Grouping writes with
BEGIN,SAVEPOINT,COMMIT, andROLLBACK