'Delete before update

I have two aws task where one could be writing to table(insert/update) another could run delete query at the same time both could be running parallel queries and playing with same rows.

So the question is if I run delete from table where column_name=some condition ? then will postgres apply table level lock or row level lock. Also if a row has to be deleted based on the condition and while delete operation has not been performed on that row yet and the row gets updated(due to upsert query performed on the row), I would want delete operation to be performed before upsert.

How can i prioritize delete over upsert for each row



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source