- Mastering PostgreSQL 10
- Hans Jürgen Sch?nig
- 271字
- 2021-06-30 19:03:50
Transactional DDLs
PostgreSQL has a very nice feature that is unfortunately not present in many commercial database systems. In PostgreSQL, it is possible to run DDLs (commands that change the data structure) inside a transaction block. In a typical commercial system, a DDL will implicitly commit the current transaction. Not so in PostgreSQL.
Apart from some minor exceptions (DROP DATABASE, CREATE TABLESPACE/DROP TABLESPACE, and so on), all DDLs in PostgreSQL are transactional, which is a huge plus and a real benefit to end users.
Here is an example:
test=# \d
No relations found.
test=# BEGIN; BEGIN
test=# CREATE TABLE t_test (id int); CREATE TABLE
test=# ALTER TABLE t_test ALTER COLUMN id TYPE int8; ALTER TABLE
test=# \d t_test Table "public.t_test"
Column | Type | Modifiers --------+--------+----------- id | bigint | test=# ROLLBACK; ROLLBACK
test=# \d
No relations found.
In this example, a table has been created and modified, and the entire transaction is aborted instantly. As you can see, there is no implicit COMMIT or any other strange behavior. PostgreSQL simply acts as expected.
Transactional DDLs are especially important if you want to deploy software. Just imagine running a Content Management System (CMS). If a new version is released, you'll want to upgrade. Running the old version would still be OK; running the new version is also OK but you really don't want a mixture of old and new. Therefore, deploying an upgrade in a single transaction is definitely highly beneficial as it upgrades an atomic operation.
- Internet接入·網(wǎng)絡(luò)安全
- 平面設(shè)計(jì)初步
- Google Cloud Platform Cookbook
- 輕松學(xué)C#
- 手把手教你玩轉(zhuǎn)RPA:基于UiPath和Blue Prism
- PIC單片機(jī)C語言非常入門與視頻演練
- Visual C# 2008開發(fā)技術(shù)實(shí)例詳解
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)訓(xùn)(職業(yè)模塊)
- 中國戰(zhàn)略性新興產(chǎn)業(yè)研究與發(fā)展·數(shù)控系統(tǒng)
- 人工智能云平臺(tái):原理、設(shè)計(jì)與應(yīng)用
- Moodle 2.0 Course Conversion(Second Edition)
- Learning Couchbase
- 仿龜機(jī)器人的設(shè)計(jì)與制作
- Learn T-SQL Querying
- 單片機(jī)原理、接口及應(yīng)用系統(tǒng)設(shè)計(jì)