Skip to content
Discord Get Started

Transactions & COPY

Transaction control, savepoints, isolation semantics, and autocommit behavior.

SQL
BEGIN;
-- ... your SQL statements ...
COMMIT; -- persist all changes atomically
ROLLBACK; -- discard all changes

Single statements outside an explicit BEGIN block run in implicit autocommit mode. The system begins a transaction, executes the statement, and commits (or rolls back on error). Retryable TiKV errors trigger automatic retry with backoff.

SQL
BEGIN;
INSERT INTO users (name) VALUES ('Alice');
SAVEPOINT sp1;
INSERT INTO users (name) VALUES ('Bob');
ROLLBACK TO SAVEPOINT sp1; -- Bob's insert is undone
RELEASE SAVEPOINT sp1; -- destroys savepoint, merges state
COMMIT; -- only Alice is committed

Savepoint behavior matches PostgreSQL: duplicate names are allowed (most recent is targeted), RELEASE destroys the named savepoint and all later ones, ROLLBACK TO re-establishes the savepoint for reuse.

Default transaction mode is pessimistic with Snapshot Isolation provided by TiKV. Each transaction sees a consistent snapshot of the database at its start time.

Sequence advances (nextval) are non-transactional — they survive transaction rollbacks, matching PostgreSQL behavior.

When an error occurs in a transaction, it enters a failed state. Only ROLLBACK, COMMIT, and END are accepted. All other statements return an error. This matches PostgreSQL behavior.


Bulk data import and export.

SQL
-- Import from file (via client)
COPY table_name FROM STDIN;
-- Import from Parquet (with parquet extension)
COPY table_name FROM '/data/file.parquet' FORMAT parquet;

Text, CSV, and Parquet formats are supported for COPY FROM.