How to Use the CLUSTER Command in PostgreSQL 7.4
When you run CLUSTER in PostgreSQL 7.4, PostgreSQL rearranges a table's rows on disk to match an existing index. If your queries…
When you run a joined update in PostgreSQL, two different things can happen. You can join the table you are updating to another table, and PostgreSQL has to decide which source row supplies the new values. Or PostgreSQL can reach a row that another transaction has already changed, and it has to decide whether that row still meets your update's conditions.
PostgreSQL handles each case differently. When you write a joined update, you need to make sure each target row matches at most one source row. When another transaction is already changing a target row under the default READ COMMITTED isolation level, PostgreSQL waits for that transaction to finish and then checks the row again. Knowing both rules helps you avoid ambiguous updates and surprises when transactions run at the same time.
With UPDATE ... FROM, PostgreSQL joins the target table (the table you are changing) to the tables you list after FROM. It uses each matching pair of rows to supply new values or filter which target rows to change. For example:
UPDATE customers AS c
SET status = s.status
FROM staging_status AS s
WHERE s.customer_id = c.customer_id
RETURNING c.customer_id, c.status;
Your join should match at most one staging_status row to each customer. If several source rows match the same target row, PostgreSQL picks one of them and does not guarantee which one. The PostgreSQL UPDATE documentation warns against relying on duplicate matches.
Before you run the update, check whether the join produces duplicates:
SELECT c.customer_id, count(*)
FROM customers AS c
JOIN staging_status AS s
ON s.customer_id = c.customer_id
GROUP BY c.customer_id
HAVING count(*) > 1;
If your data model allows only one staging row per customer, you can add a unique constraint on staging_status.customer_id to enforce that rule. If duplicates are valid, pick one source row with an explicit rule before you update the target table. Adding RETURNING shows you which target rows PostgreSQL updated and what values it wrote, though it does not make an ambiguous source match deterministic.
PostgreSQL uses multiversion concurrency control (MVCC) to keep multiple versions of rows. When you update a row, PostgreSQL writes a new version of a row instead of overwriting the old one in place. Each transaction reads a snapshot of the data from a specific point in time, so your update can run into a row that another transaction has already changed.
Under the default READ COMMITTED isolation level, PostgreSQL takes a fresh snapshot for each statement. If your update reaches a target row that another transaction is currently changing, PostgreSQL waits for that transaction to finish. If the other transaction commits, PostgreSQL moves to the newer row version and checks whether it still meets your update's search condition. If the other transaction rolls back, PostgreSQL proceeds with your update on the original row. If the other transaction deletes the row, PostgreSQL skips it. The transaction isolation documentation covers these rules in detail.
In a joined update, PostgreSQL has to recheck the row whenever the join or filter depends on target-row values that changed. The executor uses a mechanism called EvalPlanQual (EPQ) to test the affected row's current version. As the executor documentation explains, PostgreSQL reruns the relevant query conditions against that updated row. A row that matched your conditions before the other transaction's change can fail this recheck and be skipped.
PostgreSQL uses this recheck only for concurrent changes; it does not fix duplicate source matches in UPDATE ... FROM. For more detail on how the default isolation level handles concurrent updates, see how PostgreSQL READ COMMITTED handles concurrent updates.
At READ COMMITTED, PostgreSQL takes a new snapshot for each statement and rechecks a target row after another transaction updates it. For complex commands, that mix can produce an inconsistent snapshot. PostgreSQL can act on the newer version of the target row without seeing that same transaction's changes to other rows your command reads. That becomes a problem when a business rule requires related rows to stay consistent as a group.
At REPEATABLE READ, PostgreSQL keeps the same snapshot for the entire transaction. If your transaction tries to update a row that changed after its snapshot began, PostgreSQL raises a serialization error instead of rechecking the row. At SERIALIZABLE, PostgreSQL also catches broader conflicts that would make concurrent transactions behave differently from any serial order. If you use either level, your application needs to catch serialization errors and retry the transaction. See how to set PostgreSQL transaction isolation levels.
If you choose a stronger isolation level, you still have to prevent duplicate join matches. Make your source row selection unambiguous no matter which isolation level you use.
The PostgreSQL 18.7 release notes describe a fix for mishandled run-time partition pruning during EPQ rechecks. Before that fix, PostgreSQL could silently skip rows that it should have updated and could also trigger use-after-free memory accesses. The PostgreSQL project released version 18.7 on November 12, 2026, according to the official release announcement.
That fix applies specifically to the interaction between EPQ rechecks and run-time partition pruning. It does not change how UPDATE ... FROM works in general, and it does not mean joined updates commonly skip rows. If your target table is partitioned, check the release notes for the PostgreSQL branch and minor version you run.
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com