I cant rollback inside a transaction
See original GitHub issueconst client = await pool.connect()
try {
await client.query('begin')
(...)
if (condition) {
await client.query('rollback') //does not work
}
(...) //queries here are still being committed
await client.query('commit')
}
catch (e) {
await client.query('rollback')
}
finally {
client.release()
}
How do I force rollback inside a transaction if a condition matches?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
ROLLBACK TRANSACTION (Transact-SQL) - SQL Server
Rolls back an explicit or implicit transaction to the beginning of the transaction, or to a savepoint inside the transaction. You can use ......
Read more >Cannot rollback in if block transaction sql - Stack Overflow
When I executed this stored procedure, I cannot rollback in IF block even the IF statement was right. If the IF statement was...
Read more >How to rollback using explicit SQL Server transactions
This demonstration shows that an explicit transaction rollbacks a transaction, but it cannot revert the identity value. It is the reason we see ......
Read more >Can't rollback transaction - Forums - SQLServerCentral
The rollback itself will definitely take much longer than the initial transaction. It will require additional log space as well. If the ...
Read more >Transactions - Snowflake Documentation
Statements inside an explicit transaction are not affected by AUTOCOMMIT. For example, statements inside an explicit BEGIN TRANSACTION ... ROLLBACK are rolled ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
ROLLBACK
ends your transaction. Statements continue to work after a transaction like they do before a transaction.COMMIT
does nothing outside of a transaction (https://www.postgresql.org/docs/current/sql-commit.html#id-1.9.3.53.7), but even if it were an error, the queries before it would take effect.@gustavopiucco, you need to
return
to halt execution, or add anelse
to theif
statement