Transaction Control

BEGIN TRANSACTION

Starts a new transaction.

BEGIN TRANSACTION;
-- or simply
BEGIN;

COMMIT

Commits the current transaction, making all changes permanent.

COMMIT;

ROLLBACK

Rolls back the current transaction, discarding all changes.

ROLLBACK;

SAVEPOINT

Creates a savepoint within a transaction for partial rollback.

-- Create a savepoint
SAVEPOINT savepoint_name;

-- Rollback to a savepoint
ROLLBACK TO SAVEPOINT savepoint_name;

-- Release a savepoint
RELEASE SAVEPOINT savepoint_name;

Example

BEGIN TRANSACTION;

INSERT INTO accounts (id, balance) VALUES (1, 1000);
SAVEPOINT after_insert;

UPDATE accounts SET balance = 500 WHERE id = 1;
-- Oops, wrong update
ROLLBACK TO SAVEPOINT after_insert;

-- Continue with correct update
UPDATE accounts SET balance = 900 WHERE id = 1;
COMMIT;

See Savepoints for detailed documentation.


Copyright © 2025-2026 Oxibase Contributors. Gabriel Maeztu.