Ripristinare a un savepoint

Transazioni e gestione degli errori in PostgreSQL

Jason Myers

Principal Engineer

Senza savepoint

BEGIN TRANSACTION;

UPDATE cost = 2.33 WHERE name = 'Linga';

UPDATE cost = 500 WHERE name = 'Macaron';

ROLLBACK;
Transazioni e gestione degli errori in PostgreSQL

Usare savepoint e rollback mirati

BEGIN TRANSACTION;

UPDATE cost = 2.33 WHERE name = 'Linga';

SAVEPOINT oops;
UPDATE cost = 500 WHERE name = 'Macaron';
ROLLBACK TO oops;
Transazioni e gestione degli errori in PostgreSQL

Rilasciare un savepoint quando non serve più

BEGIN TRANSACTION;

UPDATE cost = 2.33 WHERE name = 'Linga';
UPDATE cost = 2.33 WHERE name = 'Petit-Beurre';
UPDATE cost = 2.33 WHERE name = 'Rosette';

SAVEPOINT oops;

UPDATE cost = 5.00 WHERE name = 'Macaron';
UPDATE cost = 3.50 WHERE name = 'Panellets';
RELEASE SAVEPOINT oops;
Transazioni e gestione degli errori in PostgreSQL

Due cose critiche su rollback e savepoint

  • ROLLBACK senza TO annulla tutta la transazione
  • ROLLBACK TO ___ dove ___ non è un nome di savepoint valido genera un errore
Transazioni e gestione degli errori in PostgreSQL

Facciamo pratica!

Transazioni e gestione degli errori in PostgreSQL

Preparing Video For Download...