1BEGIN(7)                 PostgreSQL 14.3 Documentation                BEGIN(7)
2
3
4

NAME

6       BEGIN - start a transaction block
7

SYNOPSIS

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

DESCRIPTION

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 or ROLLBACK 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 was executed.
36

PARAMETERS

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

NOTES

46       START TRANSACTION has the same functionality as BEGIN.
47
48       Use COMMIT or ROLLBACK 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

EXAMPLES

59       To begin a transaction block:
60
61           BEGIN;
62

COMPATIBILITY

64       BEGIN is a PostgreSQL language extension. It is equivalent to the
65       SQL-standard command START TRANSACTION, whose reference page contains
66       additional compatibility information.
67
68       The DEFERRABLE transaction_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

SEE ALSO

75       COMMIT(7), ROLLBACK(7), START TRANSACTION (START_TRANSACTION(7)),
76       SAVEPOINT(7)
77
78
79
80PostgreSQL 14.3                      2022                             BEGIN(7)
Impressum