Transactions & COPY
SQL Reference: Transactions
Section titled “SQL Reference: Transactions”Transaction control, savepoints, isolation semantics, and autocommit behavior.
Transaction Control
Section titled “Transaction Control”BEGIN;-- ... your SQL statements ...COMMIT; -- persist all changes atomicallyROLLBACK; -- discard all changesAutocommit
Section titled “Autocommit”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.
Savepoints
Section titled “Savepoints”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 stateCOMMIT; -- only Alice is committedSavepoint 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.
Isolation Level
Section titled “Isolation Level”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 Behavior
Section titled “Sequence Behavior”Sequence advances (nextval) are non-transactional — they survive transaction rollbacks, matching PostgreSQL behavior.
Failed Transaction State
Section titled “Failed Transaction State”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.
SQL Reference: COPY
Section titled “SQL Reference: COPY”Bulk data import and export.
-- 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.