]> begriffs open source - ai-pg/blob - full-docs/man7/BEGIN.7
Include links to all subsection html pages, with shorter paths too
[ai-pg] / full-docs / man7 / BEGIN.7
1 '\" t
2 .\"     Title: BEGIN
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
10 .TH "BEGIN" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 BEGIN \- start a transaction block
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 BEGIN [ WORK | TRANSACTION ] [ \fItransaction_mode\fR [, \&.\&.\&.] ]
36
37 where \fItransaction_mode\fR is one of:
38
39     ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
40     READ WRITE | READ ONLY
41     [ NOT ] DEFERRABLE
42 .fi
43 .SH "DESCRIPTION"
44 .PP
45 \fBBEGIN\fR
46 initiates a transaction block, that is, all statements after a
47 \fBBEGIN\fR
48 command will be executed in a single transaction until an explicit
49 \fBCOMMIT\fR
50 or
51 \fBROLLBACK\fR
52 is given\&. By default (without
53 \fBBEGIN\fR),
54 PostgreSQL
55 executes transactions in
56 \(lqautocommit\(rq
57 mode, that is, each statement is executed in its own transaction and a commit is implicitly performed at the end of the statement (if execution was successful, otherwise a rollback is done)\&.
58 .PP
59 Statements are executed more quickly in a transaction block, because transaction start/commit requires significant CPU and disk activity\&. Execution of multiple statements inside a transaction is also useful to ensure consistency when making several related changes: other sessions will be unable to see the intermediate states wherein not all the related updates have been done\&.
60 .PP
61 If the isolation level, read/write mode, or deferrable mode is specified, the new transaction has those characteristics, as if
62 \fBSET TRANSACTION\fR
63 was executed\&.
64 .SH "PARAMETERS"
65 .PP
66 WORK
67 .br
68 TRANSACTION
69 .RS 4
70 Optional key words\&. They have no effect\&.
71 .RE
72 .PP
73 Refer to
74 SET TRANSACTION (\fBSET_TRANSACTION\fR(7))
75 for information on the meaning of the other parameters to this statement\&.
76 .SH "NOTES"
77 .PP
78 \fBSTART TRANSACTION\fR
79 has the same functionality as
80 \fBBEGIN\fR\&.
81 .PP
82 Use
83 \fBCOMMIT\fR
84 or
85 \fBROLLBACK\fR
86 to terminate a transaction block\&.
87 .PP
88 Issuing
89 \fBBEGIN\fR
90 when already inside a transaction block will provoke a warning message\&. The state of the transaction is not affected\&. To nest transactions within a transaction block, use savepoints (see
91 \fBSAVEPOINT\fR(7))\&.
92 .PP
93 For reasons of backwards compatibility, the commas between successive
94 \fItransaction_modes\fR
95 can be omitted\&.
96 .SH "EXAMPLES"
97 .PP
98 To begin a transaction block:
99 .sp
100 .if n \{\
101 .RS 4
102 .\}
103 .nf
104 BEGIN;
105 .fi
106 .if n \{\
107 .RE
108 .\}
109 .SH "COMPATIBILITY"
110 .PP
111 \fBBEGIN\fR
112 is a
113 PostgreSQL
114 language extension\&. It is equivalent to the SQL\-standard command
115 \fBSTART TRANSACTION\fR, whose reference page contains additional compatibility information\&.
116 .PP
117 The
118 DEFERRABLE
119 \fItransaction_mode\fR
120 is a
121 PostgreSQL
122 language extension\&.
123 .PP
124 Incidentally, the
125 BEGIN
126 key word is used for a different purpose in embedded SQL\&. You are advised to be careful about the transaction semantics when porting database applications\&.
127 .SH "SEE ALSO"
128 \fBCOMMIT\fR(7), \fBROLLBACK\fR(7), START TRANSACTION (\fBSTART_TRANSACTION\fR(7)), \fBSAVEPOINT\fR(7)