การจัดการข้อผิดพลาด

Transactions and Error Handling in 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';
Transactions and Error Handling in PostgreSQL

การย้อนกลับข้อผิดพลาด

BEGIN TRANSACTION

UPDATE cookies SET quantity = 13 WHERE name = 'Biscuits';
ROLLBACK;
SELECT quantity FROM cookies where name = 'Biscuits';
13
Transactions and Error Handling in PostgreSQL

Rollback หลายคำสั่งพร้อมกัน

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

มาฝึกกันเถอะ!

Transactions and Error Handling in PostgreSQL

Preparing Video For Download...