<!--
doc/src/sgml/ref/begin.sgml
PostgreSQL documentation
-->
<refentry id="sql-begin">
<indexterm zone="sql-begin">
<primary>BEGIN</primary>
</indexterm>
<refmeta>
<refentrytitle>BEGIN</refentrytitle>
<manvolnum>7</manvolnum>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>BEGIN</refname>
<refpurpose>start a transaction block</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
BEGIN [ WORK | TRANSACTION ] [ <replaceable class="parameter">transaction_mode</replaceable> [, ...] ]
<phrase>where <replaceable class="parameter">transaction_mode</replaceable> is one of:</phrase>
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
READ WRITE | READ ONLY
[ NOT ] DEFERRABLE
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
<command>BEGIN</command> initiates a transaction block, that is,
all statements after a <command>BEGIN</command> command will be
executed in a single transaction until an explicit <link
linkend="sql-commit"><command>COMMIT</command></link> or <link
linkend="sql-rollback"><command>ROLLBACK</command></link> is given.
By default (without <command>BEGIN</command>),
<productname>PostgreSQL</productname> executes
transactions in <quote>autocommit</quote> 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).
</para>
<para>
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.
</para>
<para>
If the isolation level, read/write mode, or deferrable mode is specified, the new
transaction has those characteristics, as if
<link linkend="sql-set-transaction"><command>SET TRANSACTION</command></link>
was executed.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><literal>WORK</literal></term>
<term><literal>TRANSACTION</literal></term>
<listitem>