1BEGIN(7) PostgreSQL 13.3 Documentation BEGIN(7)
2
3
4
6 BEGIN - start a transaction block
7
9 BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ]
10
11 where transaction_mode is one of:
12
13 ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
14 READ WRITE | READ ONLY
15 [ NOT ] DEFERRABLE
16
18 BEGIN initiates a transaction block, that is, all statements after a
19 BEGIN command will be executed in a single transaction until an
20 explicit COMMIT(7) or ROLLBACK(7) is given. By default (without BEGIN),
21 PostgreSQL executes transactions in “autocommit” mode, that is, each
22 statement is executed in its own transaction and a commit is implicitly
23 performed at the end of the statement (if execution was successful,
24 otherwise a rollback is done).
25
26 Statements are executed more quickly in a transaction block, because
27 transaction start/commit requires significant CPU and disk activity.
28 Execution of multiple statements inside a transaction is also useful to
29 ensure consistency when making several related changes: other sessions
30 will be unable to see the intermediate states wherein not all the
31 related updates have been done.
32
33 If the isolation level, read/write mode, or deferrable mode is
34 specified, the new transaction has those characteristics, as if SET
35 TRANSACTION (SET_TRANSACTION(7)) was executed.
36
38 WORK
39 TRANSACTION
40 Optional key words. They have no effect.
41
42 Refer to SET TRANSACTION (SET_TRANSACTION(7)) for information on the
43 meaning of the other parameters to this statement.
44
46 START TRANSACTION (START_TRANSACTION(7)) has the same functionality as
47 BEGIN.
48
49 Use COMMIT(7) or ROLLBACK(7) to terminate a transaction block.
50
51 Issuing BEGIN when already inside a transaction block will provoke a
52 warning message. The state of the transaction is not affected. To nest
53 transactions within a transaction block, use savepoints (see
54 SAVEPOINT(7)).
55
56 For reasons of backwards compatibility, the commas between successive
57 transaction_modes can be omitted.
58
60 To begin a transaction block:
61
62 BEGIN;
63
65 BEGIN is a PostgreSQL language extension. It is equivalent to the
66 SQL-standard command START TRANSACTION (START_TRANSACTION(7)), whose
67 reference page contains additional compatibility information.
68
69 The DEFERRABLE transaction_mode is a PostgreSQL language extension.
70
71 Incidentally, the BEGIN key word is used for a different purpose in
72 embedded SQL. You are advised to be careful about the transaction
73 semantics when porting database applications.
74
76 COMMIT(7), ROLLBACK(7), START TRANSACTION (START_TRANSACTION(7)),
77 SAVEPOINT(7)
78
79
80
81PostgreSQL 13.3 2021 BEGIN(7)