BEGIN(7)
okay so bestie π
this is BEGIN(7) from the PostgreSQL 15.19 documentation, and it's literally all about starting a transaction block. let's get into it β¨
π NAME π
BEGIN β start a transaction block, periodt.
π¦ SYNOPSIS π¦
the shape is exactly this, no cap:
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 πΈ
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. by default, like without BEGIN, PostgreSQL executes transactions in βautocommitβ mode: 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. lowkey important π
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. it's giving atomic glow-up β¨
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, bestie.TRANSACTIONβ optional key word. also no effect.
refer to SET TRANSACTION (SET_TRANSACTION(7)) for information on the meaning of the other parameters to this statement π«Ά
β¨ NOTES β¨
START TRANSACTION has the same functionality as BEGIN.
use COMMIT or ROLLBACK to terminate a transaction block.
issuing BEGIN when 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 β see SAVEPOINT(7).
for reasons of backwards compatibility, the commas between successive transaction_modes can be omitted. cute shortcut, iykyk π
π 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.
the DEFERRABLE transaction_mode is a PostgreSQL language extension.
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 π
π₯ SEE ALSO π₯
COMMIT(7)ROLLBACK(7)START TRANSACTION(START_TRANSACTION(7))SAVEPOINT(7)
mwah π β this was sourced from PostgreSQL 15.19, dated 2026, and the page is BEGIN(7); that's the footer vibe, bestie π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-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