BEGIN(7)

πŸ“¦ version 15.19, in opensuse-leap 16.0

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 πŸ”₯


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