Rolling back with a savepoint
Building upon the last exercise, it turns out that banks with more than $6 million in MMDAs are twice as likely to sustain during a downturn than those with between $5 and 6 million in that same asset class. Here I've made a mistake in the sample code, and we need to rollback to the save point to maintain data integrity.
Diese Übung ist Teil des Kurses
Transactions and Error Handling in PostgreSQL
Anleitung zur Übung
- Inside a transaction set
FIELD48
to'MMDA+'
whereRCON6810
(MMDA amount) is greater than $6 million. - Set
mmdaplus_flag_set
as a savepoint. - Set
FIELD48
to'MMDA+'
whereRCON6810
(MMDA amount) is greater than $5 million (this is a mistake). - Undo back to
mmdaplus_flag_set
, end the transaction, and count the'MMDA+'
records.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
BEGIN;
-- Set the flag to MMDA+ where the value is greater than $6 million
UPDATE ffiec_reci set FIELD48 = 'MMDA+' where RCON6810 > 6000000;
-- Set a Savepoint
___ mmdaplus_flag_set;
-- Mistakenly set the flag to MMDA+ where the value is greater than $5 million
UPDATE ffiec_reci set FIELD48 = 'MMDA+' where ___ > 5000000;
-- Rollback to savepoint
___ TO ___;
COMMIT;
-- Select count of records where the flag is MMDA+
SELECT count(FIELD48) from ffiec_reci where FIELD48 = 'MMDA+';