Skip to main content

Transactions

SereneDB supports ACID transactions with PostgreSQL-compatible syntax.

BEGIN

Start a new transaction:

BEGIN;

Or with an explicit isolation level:

BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;

START TRANSACTION is an alias for BEGIN.

COMMIT

Commit the current transaction, making all changes permanent:

BEGIN;
INSERT INTO articles VALUES (10, 'New Article', 'content', 'engineering', '2025-03-01', 0);
UPDATE articles SET views = views + 1 WHERE id = 1;
COMMIT;

END is an alias for COMMIT.

ROLLBACK

Roll back the current transaction, discarding all changes:

BEGIN;
DELETE FROM articles WHERE views < 100;
-- Oops, let's undo that
ROLLBACK;

ABORT is an alias for ROLLBACK.

Autocommit

By default, each statement runs in its own implicit transaction and is automatically committed. Use explicit BEGIN/COMMIT to group multiple statements into a single transaction.

Example

BEGIN;

-- Both operations succeed or both fail
INSERT INTO accounts (id, balance) VALUES (1, 1000);
INSERT INTO accounts (id, balance) VALUES (2, 500);

COMMIT;