1BEGIN(7) PostgreSQL 9.2.24 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, TRANSACTION
39 Optional key words. They have no effect.
40
41 Refer to SET TRANSACTION (SET_TRANSACTION(7)) for information on the
42 meaning of the other parameters to this statement.
43
45 START TRANSACTION (START_TRANSACTION(7)) has the same functionality as
46 BEGIN.
47
48 Use COMMIT(7) or ROLLBACK(7) to terminate a transaction block.
49
50 Issuing BEGIN when already inside a transaction block will provoke a
51 warning message. The state of the transaction is not affected. To nest
52 transactions within a transaction block, use savepoints (see
53 SAVEPOINT(7)).
54
55 For reasons of backwards compatibility, the commas between successive
56 transaction_modes can be omitted.
57
59 To begin a transaction block:
60
61 BEGIN;
62
64 BEGIN is a PostgreSQL language extension. It is equivalent to the
65 SQL-standard command START TRANSACTION (START_TRANSACTION(7)), whose
66 reference page contains additional compatibility information.
67
68 The DEFERRABLEtransaction_mode is a PostgreSQL language extension.
69
70 Incidentally, the BEGIN key word is used for a different purpose in
71 embedded SQL. You are advised to be careful about the transaction
72 semantics when porting database applications.
73
75 COMMIT(7), ROLLBACK(7), START TRANSACTION (START_TRANSACTION(7)),
76 SAVEPOINT(7)
77
78
79
80PostgreSQL 9.2.24 2017-11-06 BEGIN(7)