處理錯誤

PostgreSQL 的交易與錯誤處理

Jason Myers

Principal Engineer

難免出錯

誤把 Biscuits 更新為

UPDATE cookies SET quantity = 13 WHERE name = 'Biscuits';

改正為更新 Biscotti

UPDATE cookies SET quantity = 1 WHERE name = 'Biscuits';

UPDATE cookies SET quantity = 13 WHERE name = 'Biscotti';
PostgreSQL 的交易與錯誤處理

回復錯誤變更

BEGIN TRANSACTION

UPDATE cookies SET quantity = 13 WHERE name = 'Biscuits';
ROLLBACK;
SELECT quantity FROM cookies where name = 'Biscuits';
13
PostgreSQL 的交易與錯誤處理

回復多個敘述

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
PostgreSQL 的交易與錯誤處理

一起來練習吧!

PostgreSQL 的交易與錯誤處理

Preparing Video For Download...