如何在 psql 中使用多个查询进行原子选择?

How can I do atomic selection using multiple queries in psql?

假设我有 postgresql 数据库和 2 tables:用户和提交,我正在做:

SELECT * FROM User;
SELECT * FROM Submission;

如您所见,它是两个查询,因此可以对查询

之间的任何table应用一些更改

所以我有两个问题:

  1. 如何在没有任何连接或显式锁定的情况下自动从不同的 table 获取数据?确保未对查询

  2. 之间的任何table应用任何更改
  3. 哪些查询保证原子行为? SELECT with INNER JOIN 是否以原子方式工作?

运行 single transaction 中的两个语句都设置为 repeatable read.

Quote from the manual

The Repeatable Read isolation level only sees data committed before the transaction began; it never sees either uncommitted data or changes committed during transaction execution by concurrent transactions.


是的,单个语句始终是原子的。当它是 运行 时,它永远不会看到对基础数据的更改,即使这些更改是在语句仍然是 运行.

时提交的