pg-promise 任务是原子的吗?

Are pg-promise tasks atomic?

很简单的问题,但我找不到答案。

pg-promise 文档说我们应该避免使用事务,因为它们会阻塞操作,而我们应该改用任务。 https://vitaly-t.github.io/pg-promise/Database.html#tx

但是当任务内部的查询失败时会发生什么?会回滚整个任务吗?

换句话说,任务是原子的吗?

任务(方法task)只是让您对池中的同一个分配连接执行多个查询。它们不是原子的。

事务(方法 tx)通过自动注入 BEGIN + COMMIT/ROLLBACK 扩展任务。每笔交易都是原子的。

此外,每个 multi-query 都是原子的,如文档所述,这是由 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.

该建议是在执行多个查询的上下文中给出的,其中查询的 none 更改了数据库,例如 SELECT-s。如果您要更改数据,则该建议不适用。

来自 tx 文档:

Note that transactions should be chosen over tasks only where necessary, because unlike regular tasks, transactions are blocking operations.