BEGIN(7)
hey bestie π welcome to BEGIN(7), straight from the PostgreSQL 14.24 Documentation β and it's giving βstart a transaction blockβ energy, no cap. Letβs get into it β¨
π NAME π
BEGIN β start a transaction block π
π« SYNOPSIS π«
BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ]
where transaction_mode is one of:
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
READ WRITE | READ ONLY
[ NOT ] DEFERRABLE
π¦ DESCRIPTION π¦
Okay so BEGIN initiates a transaction block β meaning every statement after a BEGIN command gets executed in a single transaction until you give an explicit COMMIT or ROLLBACK. Periodt. π
By default, like without BEGIN, PostgreSQL executes transactions in βautocommitβ mode. That means 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. π
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. Iconic consistency behavior, honestly π
If the isolation level, read/write mode, or deferrable mode is specified, the new transaction has those characteristics, as if SET TRANSACTION was executed. Slay β¨
πΈ PARAMETERS πΈ
WORKβ optional key word. It has no effect π«ΆTRANSACTIONβ optional key word. It has no effect π«Ά
Refer to SET TRANSACTION (SET_TRANSACTION(7)) for information on the meaning of the other parameters to this statement. iykyk π
π§ NOTES π§
START TRANSACTION has the same functionality as BEGIN. Twin behavior fr fr π―ββοΈ
Use COMMIT or ROLLBACK to terminate a transaction block. Those are the exits, bestie πͺ
β οΈ IssuingBEGINwhen 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 (seeSAVEPOINT(7)). Not me warning you with love π
For reasons of backwards compatibility, the commas between successive transaction_modes can be omitted. Cute little legacy vibe π
π EXAMPLES π
To begin a transaction block:
BEGIN;
π COMPATIBILITY π
BEGIN is a PostgreSQL language extension. It is equivalent to the SQL-standard command START TRANSACTION, whose reference page contains additional compatibility information. Very βsame energy, different nameβ of it π«
The DEFERRABLE transaction_mode is a PostgreSQL language extension. PostgreSQL stays adding its own little sparkle β¨
Incidentally, the BEGIN 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. Like, be careful bestie β this is not the same BEGIN in every context π
π₯ SEE ALSO π₯
COMMIT(7)ROLLBACK(7)START TRANSACTION(START_TRANSACTION(7))SAVEPOINT(7)
mwah π this cutie was brought to you by PostgreSQL 14.24, dated 2026, and itβs the BEGIN(7) page. bye bestie π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms