The specific case where this is intended to be fixed is when you need to read and update a value in a column. Sometimes you can get away with updating a column first (which blocks it), and then after that it reads, for example:
UPDATE child_codes SET counter_field = counter_field + 1; SELECT counter_field FROM child_codes;
This will return the new counter_field value, but it may be acceptable in your application. It would be unacceptable if you tried to reset the field (and therefore you need the original value), or if you had a complex calculation that could not be expressed in the update statement. In this case, to avoid the two compounds participating in the race for updating the same column, you need to lock the row.
If your RDBMS does not support FOR UPDATE, you can simulate it by performing a useless update, for example.
UPDATE child_codes SET counter_field = counter_field; SELECT counter_field FROM child_codes; UPDATE child_codes SET counter_field = 0;
source share