Skip to main content
DB

SQL reference

Transactions

Atomic statements and multi-statement transactions with BEGIN, COMMIT and ROLLBACK.

Every SQL statement commits atomically: it is applied completely, or nothing is written. Several statements commit together inside a transaction.

A transaction

BEGIN;

UPSERT INTO balances (
  chain_id, address, token, amount, updated_at, balance_index, balance_version
)
VALUES (1, '0x4b1e7c2a', 'USDC', 1500000000, '2026-10-01 12:00:00.000', 1001, 1)
ATTRIBUTE GROUP holding;

UPSERT INTO balances (
  chain_id, address, token, amount, updated_at, balance_index, balance_version
)
VALUES (1, '0x9c2e4f1a', 'USDC', 2500000000, '2026-10-01 12:00:00.000', 1001, 1)
ATTRIBUTE GROUP holding;

INSERT INTO transfers (
  chain_id, token, sender, recipient, amount, transferred_at, _index
)
VALUES (
  1, 'USDC', '0x4b1e7c2a', '0x9c2e4f1a', 1000000000, '2026-10-01 12:00:00.000',
  1001
);

COMMIT;

Both balances and the transfer become visible together at COMMIT. ROLLBACK discards every statement since BEGIN.

StatementEffect
BEGIN / START TRANSACTIONOpens a transaction on the session.
COMMITCommits every statement of the transaction atomically.
ROLLBACKDiscards every statement of the transaction.

What one statement guarantees

StatementUnit of atomicity
INSERT, UPSERT, REPLACEone row tuple, optionally one attribute group of it
UPDATEthe named columns of the row with one complete primary key, optionally within one group
DELETEthe row with one complete primary key, every group included
DDL (CREATE, ALTER, DROP)the one definition change

After the receipt returns, the next read sees the write. See Consistency.

Rows sent in bulk go through the HTTP write-batch and bulk-load routes; see Protocol for their acknowledgement contract.

Designing writes

  • Put the facts that change together in one row, in one attribute group of a row, or in one transaction.
  • Record each step of a workflow as an event in an APPEND table, and derive the current state with a transformation.
  • Make retries safe. On columns with the default REPLACE reducer, an UPSERT or REPLACE sent twice with the same values leaves the same row. An INSERT of an existing key reports the duplicate instead of writing it twice.
  • Use VALID BY and REVISION BY on keyed tables so late or repeated writes resolve deterministically. See Versioned tables.

On this page