Transactions and Error Handling in PostgreSQL
Jason Myers
Principal Engineer
Mistakenly updated Biscuits
UPDATE cookies SET quantity = 13 WHERE name = 'Biscuits';
Corrected to update Biscotti
UPDATE cookies SET quantity = 1 WHERE name = 'Biscuits';
UPDATE cookies SET quantity = 13 WHERE name = 'Biscotti';
BEGIN TRANSACTION
UPDATE cookies SET quantity = 13 WHERE name = 'Biscuits';
ROLLBACK;
SELECT quantity FROM cookies where name = 'Biscuits';
13
BEGIN TRANSACTION;
UPDATE cookies SET deliciousness = 111 where name = 'Cats Tongue';
UPDATE cookies SET deliciousness = 8 where name = 'Gingerbread';
ROLLBACK;
SELECT name, deliciousness FROM cookies where name in ('Cats Tongue', 'Gingerbread');
'Cats Tongue' 10
'Gingerbread' 9
Transactions and Error Handling in PostgreSQL