Pretty simple question but I can't find the answer anywhere.
The pg-promise
docs say that we should avoid using transactions because they're blocking operations and that we should be using tasks instead. https://vitaly-t.github.io/pg-promise/Database.html#tx
But what happens when a query inside of a task fails? Will the whole task be rolled back?
In other words, are tasks atomic?
Tasks (method task) are there simply to let you execute multiple queries against the same allocated connection from the pool. They are not atomic.
A transaction (method tx) extends the task with automatic injection of BEGIN
+ COMMIT
/ROLLBACK
. Every transaction is atomic.
Also, each multi-query is atomic, as documented, which is enforced by PostgreSQL.
The
pg-promise
docs say that we should avoid using transactions because they're blocking operations and that we should be using tasks instead.
That advise is given in the context of executing multiple queries where none of the query changes the database, like SELECT
-s. If you are changing data, that advise does not apply.
From the tx documentation:
Note that transactions should be chosen over tasks only where necessary, because unlike regular tasks, transactions are blocking operations
.