Database locking with raw SQL (FOR UPDATE)

Two concurrent transactions that each SELECT a row, change it in memory, then UPDATE can lose an update or claim the same resource twice…