FOR _gid, _loser, _winner IN UPDATE words_games SET finished = CURRENT_TIMESTAMP WHERE finished IS NULL AND played1 IS NOT NULL AND played2 IS NOT NULL AND (played1 < CURRENT_TIMESTAMP - INTERVAL '24 hours' OR played2 < CURRENT_TIMESTAMP - INTERVAL '24 hours') RETURNING gid, CASE WHEN played1 < played2 THEN player1 ELSE player2 END, CASE WHEN played1 < played2 THEN player2 ELSE player1 END FOR UPDATE SKIP LOCKED LOOP ... END LOOP;