BEGIN(7)

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

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 πŸšͺ

⚠️ 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)). 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 πŸ”₯


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