title: Lock for SELECT so another process doesn't get old data
body: <p>I have a table that could have two threads reading data from it. If the data is in a certain state (let's say state 1) then the process will do something (not relevant to this question) and then update the state to 2.</p>
  
  <p>It seems to me that there could be a case where thread 1 and thread 2 both perform a select within microseconds of one another and both see that the row is in state 1, and then both do the same thing and 2 updates occur after locks have been released.</p>
  
  <p>Question is: Is there a way to prevent the second thread from being able to modify this data in Postgres - AKA it is forced to do another <code>SELECT</code> after the lock from the first one is released for its update so it knows to bail in order to prevent dupes?</p>
  
  <p>I looked into row locking, but it says you cannot prevent select statements which sounds like it won't work for my condition here. Is my only option to use advisory locks?</p>