Execute Multiple Statements in a Transaction
pg_transactionExecute multiple SQL statements atomically, rolling back all changes if any statement fails. Ideal for ensuring consistency in multi-step operations.
Instructions
Execute multiple SQL statements atomically in a single transaction.
All statements succeed or all are rolled back. Ideal for multi-step operations that must be atomic (e.g., insert + update, schema migrations).
Args:
statements: Array of SQL statements to execute in order (required)
confirm_destructive: Required if any statement is DROP/TRUNCATE/DELETE-without-WHERE
Returns: JSON: { results: [{command, rows_affected}], total_duration_ms, rolled_back: false } On error: { error, rolled_back: true, failed_at_index: number }
Examples: statements: ["INSERT INTO orders ...", "UPDATE inventory SET qty = qty - 1 WHERE ..."]
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| statements | Yes | SQL statements to execute in order within a transaction | |
| confirm_destructive | No | Set true if any statement is destructive (DROP/TRUNCATE/DELETE without WHERE) | |
| timeout_ms | No | Per-statement timeout in milliseconds |