Skip to content

Transactions

Post AI wraps multiple SQL statements in a single ACID transaction. All statements commit atomically, or all roll back on error.

Terminal window
curl -X POST https://postdb.dev/api/transaction \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"statements": [
{
"sql": "INSERT INTO transfers (from_account, to_account, amount) VALUES ($1, $2, $3)",
"params": ["acc-001", "acc-002", 500.00]
},
{
"sql": "UPDATE accounts SET balance = balance - $1 WHERE id = $2",
"params": [500.00, "acc-001"]
},
{
"sql": "UPDATE accounts SET balance = balance + $1 WHERE id = $2",
"params": [500.00, "acc-002"]
}
]
}'

If any statement fails, the entire transaction is rolled back and an error is returned. No partial state.