A transaction groups changes into a single commit. BEGIN starts it, COMMIT keeps the work and ROLLBACK discards it. Other sessions should never observe half a transfer. Read your own writes inside the transaction to check the state you are about to publish.
A savepoint marks a recoverable point inside a transaction. ROLLBACK TO removes work after that point while preserving earlier work. After a statement error, a PostgreSQL transaction stays aborted until you roll back the transaction or a suitable savepoint. Merely correcting the next statement isn't enough.
Sequences are an exception to the usual rollback intuition: a consumed identity value can leave a gap after rollback. Do not treat consecutive IDs as a promise. These exercises execute real single-connection transactions. Later lessons use a separately labeled model to inspect interactions between two sessions.
ROLLBACK discards the trial write rather than publishing it.