Skip to content

.tip

· one of the small things

RETURNING can give you the old row too

Since Postgres 18, RETURNING can name both the old and the new values in one statement, so you don't need a trigger or a second query to see what changed.

UPDATE accounts SET balance = balance - 50 WHERE id = 7
RETURNING old.balance AS before, new.balance AS after;

It's handy for audit rows, and for that "what did I just overwrite?" moment in the middle of a migration.

postgresql