START TRANSACTION v6.27.4
Starts a transaction block.
Synopsis
START TRANSACTION [<transaction_mode>] [READ WRITE | READ ONLY]
where transaction_mode is:
ISOLATION LEVEL {SERIALIZABLE | READ COMMITTED | READ UNCOMMITTED}Description
START TRANSACTION begins a new transaction block. If the isolation level or read/write mode is specified, the new transaction has those characteristics, as if SET TRANSACTION was run. This is the same as the BEGIN command.
Parameters
READ UNCOMMITTED
READ COMMITTED
REPEATABLE READ
SERIALIZABLE
The SQL standard defines four transaction isolation levels:
READ UNCOMMITTED,READ COMMITTED,REPEATABLE READ, andSERIALIZABLE.READ UNCOMMITTEDallows transactions to see changes made by uncomitted concurrent transactions. This is not possible in WarehousePG, soREAD UNCOMMITTEDis treated the same asREAD COMMITTED.READ COMMITTED, the default isolation level in WarehousePG, guarantees that a statement can only see rows committed before it began. The same statement run twice in a transaction can produce different results if another concurrent transaction commits after the statement is run the first time.The
REPEATABLE READisolation level guarantees that a transaction can only see rows committed before it began.REPEATABLE READis the strictest transaction isolation level WarehousePG supports. Applications that use theREPEATABLE READisolation level must be prepared to retry transactions due to serialization failures.The
SERIALIZABLEtransaction isolation level guarantees that running multiple concurrent transactions produces the same effects as running the same transactions one at a time. If you specifySERIALIZABLE, WarehousePG falls back toREPEATABLE READ.READ WRITE
READ ONLY
Determines whether the transaction is read/write or read-only. Read/write is the default. When a transaction is read-only, the following SQL commands are disallowed:
INSERT,UPDATE,DELETE, andCOPY FROMif the table they would write to is not a temporary table; allCREATE,ALTER, andDROPcommands;GRANT,REVOKE,TRUNCATE; andEXPLAIN ANALYZEandEXECUTEif the command they would run is among those listed.
Examples
To begin a transaction block:
START TRANSACTION;
Compatibility
In the standard, it is not necessary to issue START TRANSACTION to start a transaction block: any SQL command implicitly begins a block. WarehousePG behavior can be seen as implicitly issuing a COMMIT after each command that does not follow START TRANSACTION (or BEGIN), and it is therefore often called 'autocommit'. Other relational database systems may offer an autocommit feature as a convenience.
The SQL standard requires commas between successive transaction_modes, but for historical reasons WarehousePG allows the commas to be omitted.
See also the compatibility section of SET TRANSACTION.
See Also
Parent topic: SQL Commands