Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Databases - Practical PostgreSQL
Previous Page Home Next Page

BEGIN

Name

BEGIN -- Starts a chained-mode transaction block.

Synopsis

BEGIN [ WORK | TRANSACTION ]

Parameters

WORK | TRANSACTION

A pair of optional noise keywords. They can be ignored, or used to make your SQL more readable.

Results

BEGIN

The message returned when a transaction begins.

NOTICE: BEGIN: already a transaction in progress

The notice returned if a transaction is already in progress within your PostgreSQL session. You cannot nest multiple transactions. The transaction you have in progress is not altered when this happens.

Description

PostgreSQL executes transactions in unchained mode by default. Also called autocommit , this mode encapsulates each user statement in an implicit transaction, and automatically finalizes the transaction by either committing the modification, or performing a rollback, depending on whether or not the execution was successful.

Using BEGIN specifies that you want to enter a transaction block using chained mode, in which statements will be queued by the database, and then sent in a single transaction when the database receives a COMMIT command. Alternatively, the queued statements can be discarded by a ROLLBACK, or by an unexpected disconnection.

Chained mode can be useful when you are working with multiple related tables, and also to increase database performance in general. Executing statements in chained mode uses less CPU and disk resources, as there is only one commit needed per block of statements executed.

When a transaction is committed, the database will attempt to run all updates that have been specified within it. If there are were no errors, the updates will be performed; otherwise the transaction block will be aborted.

Examples

The following example begins a transaction block, creates a table, and commits the action:

booktown=# 
BEGIN WORK;

BEGIN
booktown=# 
CREATE TABLE test (id integer, name text);

CREATE
booktown=# 
COMMIT WORK;

COMMIT
Databases - Practical PostgreSQL
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire