- Mastering PostgreSQL 9.6
- Hans Jurgen Schonig
- 170字
- 2021-07-09 19:57:11
Handling errors inside a transaction
It is not always the case that transactions are correct from beginning to end. However, in PostgreSQL, only error-free transactions can be committed. Here is what happens:
test=# BEGIN;
BEGIN
test=# SELECT 1;
?column?
----------
1
(1 row)
test=# SELECT 1 / 0;
ERROR: division by zero
test=# SELECT 1;
ERROR: current transaction is aborted, commands ignored until end of transaction block
test=# COMMIT;
ROLLBACK
Note that the division by zero did not work out.
In any proper database, an instruction like this will instantly error-out and make the statement fail.
It is important to point out that PostgreSQL will error-out, unlike MySQL, which does not seem to have a problem with a mathematically wrong result.
After an error has occurred, no more instructions will be accepted even if those instructions are semantically and syntactically correct. It is still possible to issue a COMMIT. However, PostgreSQL will roll back the transaction because it is the only thing at this point that can still be done.
推薦閱讀
- 腦動力:Linux指令速查效率手冊
- SCRATCH與機(jī)器人
- 大型數(shù)據(jù)庫管理系統(tǒng)技術(shù)、應(yīng)用與實(shí)例分析:SQL Server 2005
- Grome Terrain Modeling with Ogre3D,UDK,and Unity3D
- Excel 2007技巧大全
- 啊哈C!思考快你一步
- Linux內(nèi)核精析
- Photoshop CS5圖像處理入門、進(jìn)階與提高
- 重估:人工智能與賦能社會
- 空間機(jī)器人
- Python文本分析
- Mastering MongoDB 4.x
- FANUC工業(yè)機(jī)器人虛擬仿真教程
- 超好玩的Python少兒編程
- ARM嵌入式開發(fā)實(shí)例