SET TRANSACTION

A command for setting the type of the current transaction

SET TRANSACTION is a transaction command for setting transaction characteristics.

SET TRANSACTION was added in PostgreSQL 6.5.

Usage

SET TRANSACTION can perform one of three different tasks:

  • setting the current transaction mode
  • setting the session transaction mode
  • setting the session snapshot

Change history

Examples

Basic execution example for SET TRANSACTION:

postgres=# BEGIN;
BEGIN

postgres=*# SET TRANSACTION READ ONLY;
SET

postgres=*# INSERT INTO foo VALUES(1);
ERROR:  cannot execute INSERT in a read-only transaction

SET TRANSACTION is only effective if a transaction is in progress:

postgres=# SET TRANSACTION READ ONLY;
WARNING:  SET TRANSACTION can only be used in transaction blocks
SET

Categories

SQL command, Transaction command, Transactions

See also

default_transaction_isolation, default_transaction_deferrable, default_transaction_read_only