1BEGIN()                          SQL Commands                          BEGIN()
2
3
4

NAME

6       BEGIN - start a transaction block
7
8

SYNOPSIS

10       BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ]
11
12       where transaction_mode is one of:
13
14           ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
15           READ WRITE | READ ONLY
16
17

DESCRIPTION

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  [commit(7)]  or  ROLLBACK [rollback(l)] is given.  By
22       default (without BEGIN), PostgreSQL executes transactions in ``autocom‐
23       mit''  mode, that is, each statement is executed in its own transaction
24       and a commit is implicitly performed at the end of  the  statement  (if
25       execution was successful, otherwise a rollback is done).
26
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.
33
34       If the isolation level or read/write mode is specified, the new  trans‐
35       action  has  those characteristics, as if SET TRANSACTION [set_transac‐
36       tion(7)] was executed.
37

PARAMETERS

39       WORK
40
41       TRANSACTION
42              Optional key words. They have no effect.
43
44       Refer to SET TRANSACTION [set_transaction(7)] for  information  on  the
45       meaning of the other parameters to this statement.
46

NOTES

48       START  TRANSACTION [start_transaction(7)] has the same functionality as
49       BEGIN.
50
51       Use COMMIT [commit(7)] or ROLLBACK [rollback(7)] to terminate a  trans‐
52       action block.
53
54       Issuing  BEGIN  when  already inside a transaction block will provoke a
55       warning message. The state of the transaction is not affected.  To nest
56       transactions  within a transaction block, use savepoints (see SAVEPOINT
57       [savepoint(7)]).
58
59       For reasons of backwards compatibility, the commas  between  successive
60       transaction_modes may be omitted.
61

EXAMPLES

63       To begin a transaction block:
64
65       BEGIN;
66
67

COMPATIBILITY

69       BEGIN  is a PostgreSQL language extension. It is equivalent to the SQL-
70       standard command START TRANSACTION [start_transaction(7)], whose refer‐
71       ence page contains additional compatibility information.
72
73       Incidentally,  the  BEGIN  key  word is used for a different purpose in
74       embedded SQL. You are advised  to  be  careful  about  the  transaction
75       semantics when porting database applications.
76

SEE ALSO

78       COMMIT   [commit(7)],   ROLLBACK   [rollback(l)],   START   TRANSACTION
79       [start_transaction(l)], SAVEPOINT [savepoint(l)]
80
81
82
83SQL - Language Statements         2008-06-08                           BEGIN()
Impressum