Data Manipulation (DML)
Standard SQL data manipulation commands for reading and writing data.
DML permission and routing behavior depends on table type. For USER, SHARED, STREAM, and
SYSTEM access rules, see /docs/server/architecture/table-types.
INSERT
Insert one or more rows into a table:
Batch Insert
Examples
Upsert with ON CONFLICT
KalamDB supports PostgreSQL-style upsert for literal INSERT ... VALUES statements on
USER, SHARED, and STREAM tables:
If the primary key already exists, KalamDB updates the row with the DO UPDATE SET assignments.
If the primary key is new, KalamDB inserts the row from VALUES.
Examples
DO UPDATE SET assignments support:
EXCLUDED.<column>to read the value from the attempted insert- literal constants such as
'published',42, orNULL
Upsert inside explicit transactions
Upsert works inside BEGIN / COMMIT blocks and sees rows staged earlier in the same
transaction, including on SHARED tables:
Outside an explicit transaction, KalamDB wraps each upsert in its own internal transaction and commits it automatically.
Upsert rules and limits
- Requires a single-column primary key. The conflict target must be that primary key column.
- Literal
VALUESinserts only.INSERT ... SELECTupserts are not supported on this path. ON CONFLICT DO NOTHING,ON CONFLICT ON CONSTRAINT, andON CONFLICT DO UPDATE WHEREare not supported.- Tuple assignments in
DO UPDATE SETare not supported. system.*tables are rejected.
RETURNING on upsert
Add RETURNING to an upsert to get back the inserted or updated row instead of only an
affected-row count. This follows PostgreSQL’s INSERT ... RETURNING shape: the clause lists
the output columns, and aliases are supported.
Examples
Response shape
- Without
RETURNING, the SQL API reports an insert result withrows_affected. - With
RETURNING, the SQL API returns a query result withschema,rows, androw_count, the same success shape asSELECT.
RETURNING is currently supported on the upsert path above. Plain INSERT ... RETURNING
without ON CONFLICT, and UPDATE / DELETE ... RETURNING, are not supported yet.
UPDATE
Example
DELETE
Example
Explicit Transactions
KalamDB stays in autocommit mode by default. Use explicit transaction blocks when you need PostgreSQL-style atomic multi-statement writes.
Syntax
Commit example
Rollback example
Within the open transaction, reads see the staged writes from that same transaction. After ROLLBACK, those staged changes are discarded.
Rules and limits
- Explicit transactions currently support
USERandSHAREDtables. STREAMtables andsystem.*tables are rejected inside explicit transactions.- DDL statements are not supported inside explicit transactions.
- Nested
BEGINand savepoints are not supported in this phase. - A single
/v1/api/sqlrequest can contain multiple sequentialBEGIN ... COMMITorBEGIN ... ROLLBACKblocks. - If a
/v1/api/sqlrequest ends with an open transaction, KalamDB rolls it back automatically.
To inspect live transaction state, query system.transactions. For pg-extension-specific session
state, use system.sessions. See
/docs/server/sql-reference/system-views.
For deeper read-query patterns (joins, CTEs, and DataFusion-compatible advanced SELECT usage), see /docs/server/sql-reference/query-data.