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