Examples: Abort
The following example begins a transaction, executes some SQL statements, and aborts the transaction before committing the database changes:
begin transaction;
insert into emp (name, sal, bdate)
values ('Jones,Bill', 100000, 1814);
insert into emp (name, sal, bdate)
values ('Jones,Bill', 100000, 1714);
abort; \g
/* undoes both inserts; table is unchanged */
The following example begins a transaction, establishes savepoints, and does a partial abort of the MST:
begin transaction;
insert into emp (name, sal, bdate)
values ('Jones,Bill', 100000, 1945);
savepoint setone;
insert into emp (name, sal, bdate)
values ('Smith,Stan', 50000, 1911);
savepoint 2; \g
/* undoes second insert; deactivates savepoint 2 */
abort to setone; \g
insert into emp (name, sal, bdate)
values ('Smith,Stan', 50000, 1948);
abort to setone; \g
end transaction; \g
/* only the first insert is committed */
Last modified date: 01/30/2023