]> begriffs open source - ai-pg/blob - full-docs/txt/sql-begin.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-begin.txt
1
2 BEGIN
3
4    BEGIN — start a transaction block
5
6 Synopsis
7
8 BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ]
9
10 where transaction_mode is one of:
11
12     ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNC
13 OMMITTED }
14     READ WRITE | READ ONLY
15     [ NOT ] DEFERRABLE
16
17 Description
18
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).
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, read/write mode, or deferrable mode is
35    specified, the new transaction has those characteristics, as if SET
36    TRANSACTION was executed.
37
38 Parameters
39
40    WORK
41           TRANSACTION
42           Optional key words. They have no effect.
43
44    Refer to SET TRANSACTION for information on the meaning of the other
45    parameters to this statement.
46
47 Notes
48
49    START TRANSACTION has the same functionality as BEGIN.
50
51    Use COMMIT or ROLLBACK to terminate a transaction block.
52
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
56    SAVEPOINT).
57
58    For reasons of backwards compatibility, the commas between successive
59    transaction_modes can be omitted.
60
61 Examples
62
63    To begin a transaction block:
64 BEGIN;
65
66 Compatibility
67
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.
71
72    The DEFERRABLE transaction_mode is a PostgreSQL language extension.
73
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.
77
78 See Also
79
80    COMMIT, ROLLBACK, START TRANSACTION, SAVEPOINT